org.pentaho.di.core.util.StringUtil Java Examples

The following examples show how to use org.pentaho.di.core.util.StringUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecuteTestsDialog.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( StringUtil.isEmpty( wStepname.getText() ) ) {
    return;
  }

  stepname = wStepname.getText(); // return value

  input.setChanged();

  input.setTestNameInputField( wTestNameInputField.getText() );
  input.setTypeToExecute( DataSetConst.getTestTypeForDescription( wTypeToExecute.getText() ) );
  input.setTransformationNameField( wTransformationNameField.getText() );
  input.setUnitTestNameField( wUnitTestNameField.getText() );
  input.setDataSetNameField( wDataSetNameField.getText() );
  input.setStepNameField( wStepNameField.getText() );
  input.setErrorField( wErrorField.getText() );
  input.setCommentField( wCommentField.getText() );

  dispose();
}
 
Example #2
Source File: LogMessage.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * @return The formatted message.
 */
@Override
public String getMessage() {
  String formatted = message;
  if ( arguments != null ) {
    // get all "tokens" enclosed by curly brackets within the message
    final List<String> tokens = new ArrayList<>();
    StringUtil.getUsedVariables( formatted, "{", "}", tokens, true );
    // perform MessageFormat.format( ... ) on each token, if we get an exception, we'll know that we have a
    // segment that isn't parsable by MessageFormat, likely a pdi variable name (${foo}) - in this case, we need to
    // escape the curly brackets in the message, so that MessageFormat does not complain
    for ( final String token : tokens ) {
      try {
        MessageFormat.format( "{" + token + "}", arguments );
      } catch ( final IllegalArgumentException iar ) {
        formatted = formatted.replaceAll( "\\{" + token + "\\}",  "\\'{'" + token + "\\'}'" );
      }
    }
    // now that we have escaped curly brackets in all invalid tokens, we can attempt to format the entire message
    formatted = MessageFormat.format( formatted, arguments );
  }
  return formatted;
}
 
Example #3
Source File: JobEntryExportRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String buildUniqueFilename( String filename ) {
  String retval = "";
  if ( Utils.isEmpty( filename ) ) {
    return null;
  }

  int lenstring = filename.length();
  int lastindexOfDot = filename.lastIndexOf( '.' );
  if ( lastindexOfDot == -1 ) {
    lastindexOfDot = lenstring;
  }
  retval = filename.substring( 0, lastindexOfDot );
  retval += StringUtil.getFormattedDateTimeNow();
  retval += filename.substring( lastindexOfDot, lenstring );

  return retval;
}
 
Example #4
Source File: DatabaseMeta_AppendExtraParamsTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void onlyValidExtraOptions_AreAppendedToUrl() {
  Map<String, String> extraOptions = generateExtraOptions( CONN_TYPE_MSSQL, 1 );
  extraOptions.put( STRING_DEFAULT, STRING_DEFAULT );
  extraOptions.put( CONN_TYPE_MSSQL + "." + "key1", StringUtil.EMPTY_STRING );
  extraOptions.put( CONN_TYPE_MSSQL + "." + "key2", DatabaseMeta.EMPTY_OPTIONS_STRING );

  String expectedExtraOptionsUrl =
    STRING_EXTRA_OPTION + 0 + mssqlServerDatabaseMeta.getExtraOptionValueSeparator() + STRING_OPTION_VALUE + 0;
  String expectedUrl =
    CONN_URL_NO_EXTRA_OPTIONS + mssqlServerDatabaseMeta.getExtraOptionSeparator() + expectedExtraOptionsUrl;


  String connUrlWithExtraOptions = meta.appendExtraOptions( CONN_URL_NO_EXTRA_OPTIONS, extraOptions );
  assertEquals( expectedUrl, connUrlWithExtraOptions );
}
 
Example #5
Source File: RunConfigurationSaveExtensionPoint.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object o ) throws KettleException {
  JobMeta jobMeta = (JobMeta) ( (Object[]) o )[ 0 ];
  final EmbeddedMetaStore embeddedMetaStore = jobMeta.getEmbeddedMetaStore();

  RunConfigurationManager embeddedRunConfigurationManager =
    EmbeddedRunConfigurationManager.build( embeddedMetaStore );
  embeddedRunConfigurationManager.deleteAll();

  List<String> runConfigurationNames = new ArrayList<>();
  boolean embedAll = false;
  for ( JobEntryCopy jobEntryCopy : jobMeta.getJobCopies() ) {
    if ( jobEntryCopy.getEntry() instanceof JobEntryRunConfigurableInterface ) {
      String usedConfiguration = ( (JobEntryRunConfigurableInterface) jobEntryCopy.getEntry() ).getRunConfiguration();
      embedAll = embedAll || StringUtil.isVariable( usedConfiguration );
      if ( !Utils.isEmpty( usedConfiguration ) && !runConfigurationNames.contains( usedConfiguration ) ) {
        runConfigurationNames.add( usedConfiguration );
      }
    }
  }

  if ( embedAll ) {
    embedAllRunConfigurations( embeddedRunConfigurationManager );
  } else {
    embedRunConfigurations( embeddedRunConfigurationManager, runConfigurationNames );
  }
}
 
Example #6
Source File: VFSFileSelection.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private Optional<String> promptForFile() {
  String curFile = abstractMeta.environmentSubstitute( wFileName.getText() );
  FileObject root;

  try {
    root = KettleVFS.getFileObject( curFile != null ? curFile : Const.getUserHomeDirectory() );
    VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog( root.getParent(), root );
    if ( StringUtil.isEmpty( initialScheme ) ) {
      initialScheme = "file";
    }
    FileObject file = vfsFileChooser.open( getShell(), null, initialScheme, true, curFile, fileFilters, fileFilterNames, false,
      fileDialogMode, showLocation, true );
    if ( file == null ) {
      return Optional.empty();
    }

    String filePath = getRelativePath( file.getName().toString() );
    return Optional.ofNullable( filePath );
  } catch ( IOException | KettleException e ) {
    new ErrorDialog( getShell(),
      BaseMessages.getString( PKG, "VFSFileSelection.ErrorLoadingFile.DialogTitle" ),
      BaseMessages.getString( PKG, "VFSFileSelection.ErrorLoadingFile.DialogMessage" ), e );
  }
  return Optional.empty();
}
 
Example #7
Source File: MQTTClientBuilderTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyClientId() throws MqttException {
  builder
    .withClientId( "asdf" )
    .buildAndConnect();
  assertEquals( "asdf", clientIdCapture.getValue() );

  builder
    .withClientId( null )
    .buildAndConnect();
  assertFalse( StringUtil.isEmpty( clientIdCapture.getValue() ) );
  assertNotEquals( "asdf", clientIdCapture.getValue() );

  builder
    .withClientId( "" )
    .buildAndConnect();
  assertFalse( StringUtil.isEmpty( clientIdCapture.getValue() ) );
  assertNotEquals( "asdf", clientIdCapture.getValue() );
}
 
Example #8
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
public static String validateDataSet( DataSet dataSet, String previousName, List<String> setNames ) {

    String message = null;

    String newName = dataSet.getName();
    if ( StringUtil.isEmpty( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.NoNameSpecified.Message" );
    } else if ( !StringUtil.isEmpty( previousName ) && !previousName.equals( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.RenamingOfADataSetsNotSupported.Message" );
    } else if ( dataSet.getGroup() == null ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.NoGroupSpecified.Message" );
    } else {
      if ( StringUtil.isEmpty( previousName ) && Const.indexOfString( newName, setNames ) >= 0 ) {
        message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.ADataSetWithNameExists.Message", newName );
      }
    }

    return message;
  }
 
Example #9
Source File: HTTPPOST.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
String getRequestBodyParamsAsStr( NameValuePair[] pairs, String charset ) throws KettleException {
  StringBuffer buf = new StringBuffer();
  try {
    for ( int i = 0; i < pairs.length; ++i ) {
      NameValuePair pair = pairs[ i ];
      if ( pair.getName() != null ) {
        if ( i > 0 ) {
          buf.append( "&" );
        }

        buf.append( URLEncoder.encode( pair.getName(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        buf.append( "=" );
        if ( pair.getValue() != null ) {
          buf.append( URLEncoder.encode( pair.getValue(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        }
      }
    }
    return buf.toString();
  } catch ( UnsupportedEncodingException e ) {
    throw new KettleException( e.getMessage(), e.getCause() );
  }
}
 
Example #10
Source File: SpoonFlagUnitTestExtensionPoint.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
@Override
public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException {
  if ( !( object instanceof TransMeta ) ) {
    return;
  }

  TransMeta transMeta = (TransMeta) object;

  TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( transMeta );
  if ( unitTest == null ) {
    return;
  }

  String unitTestName = unitTest.getName();

  if ( !StringUtil.isEmpty( unitTestName ) ) {
    // We're running in Spoon and there's a unit test selected : test it
    //
    transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "Y" );
    transMeta.setVariable( DataSetConst.VAR_UNIT_TEST_NAME, unitTestName );
  }
}
 
Example #11
Source File: StepOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void checkInteger( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                                 String identifier, String value ) {
  try {
    if ( !StringUtil.isEmpty( space.environmentSubstitute( value ) ) ) {
      Integer.parseInt( space.environmentSubstitute( value ) );
    }
  } catch ( NumberFormatException e ) {
    remarks.add( new CheckResult(
      CheckResultInterface.TYPE_RESULT_ERROR,
      BaseMessages.getString( PKG, "StepOption.CheckResult.NotAInteger", identifier ),
      stepMeta ) );
  }
}
 
Example #12
Source File: Variables.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String environmentSubstitute( String aString ) {
  if ( aString == null || aString.length() == 0 ) {
    return aString;
  }

  return StringUtil.environmentSubstitute( aString, properties );
}
 
Example #13
Source File: DatabaseMeta_AppendExtraParamsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void extraOptionsAreNotAppended_WhenTheyAreEmpty() {
  Map<String, String> extraOptions = generateExtraOptions( CONN_TYPE_MSSQL, 0 );
  final String validKey = CONN_TYPE_MSSQL + "." + "key";
  extraOptions.put( validKey, StringUtil.EMPTY_STRING );
  extraOptions.put( validKey, DatabaseMeta.EMPTY_OPTIONS_STRING );

  String connUrlWithExtraOptions = meta.appendExtraOptions( CONN_URL_NO_EXTRA_OPTIONS, extraOptions );
  assertEquals( CONN_URL_NO_EXTRA_OPTIONS, connUrlWithExtraOptions );
}
 
Example #14
Source File: Variables.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String environmentSubstitute( String aString, boolean escapeHexDelimiter ) {
  if ( aString == null || aString.length() == 0 ) {
    return aString;
  }

  return StringUtil.environmentSubstitute( aString, properties, escapeHexDelimiter );
}
 
Example #15
Source File: S3CsvInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * For legacy transformations containing AWS S3 access credentials, {@link Const#KETTLE_USE_AWS_DEFAULT_CREDENTIALS} can force Spoon to use
 * the Amazon Default Credentials Provider Chain instead of using the credentials embedded in the transformation metadata.
 *
 * @return true if {@link Const#KETTLE_USE_AWS_DEFAULT_CREDENTIALS} is true or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are not specified
 */
public boolean getUseAwsDefaultCredentials() {
  if ( ValueMetaBase.convertStringToBoolean( Const.NVL( EnvUtil.getSystemProperty( Const.KETTLE_USE_AWS_DEFAULT_CREDENTIALS ), "N" ) ) ) {
    return true;
  } else if ( StringUtil.isEmpty( awsAccessKey ) && StringUtil.isEmpty( awsSecretKey ) ) {
    return true;
  }
  return false;
}
 
Example #16
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
  super.loadXML( stepnode, databases, metaStore );
  targetFieldName = XMLHandler.getTagValue( stepnode, ConcatFieldsNodeNameSpace, "targetFieldName" );
  targetFieldLength =
    Const.toInt( XMLHandler.getTagValue( stepnode, ConcatFieldsNodeNameSpace, "targetFieldLength" ), 0 );
  removeSelectedFields =
    "Y"
      .equalsIgnoreCase( XMLHandler
        .getTagValue( stepnode, ConcatFieldsNodeNameSpace, "removeSelectedFields" ) );

  // PDI-18028: Avoid fileName handling!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );
}
 
Example #17
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String getXML() {
  // PDI-18028: Avoid fileName handling!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );

  String retval = super.getXML();
  retval = retval + "    <" + ConcatFieldsNodeNameSpace + ">" + Const.CR;
  retval = retval + XMLHandler.addTagValue( "targetFieldName", targetFieldName );
  retval = retval + XMLHandler.addTagValue( "targetFieldLength", targetFieldLength );
  retval = retval + XMLHandler.addTagValue( "removeSelectedFields", removeSelectedFields );
  retval = retval + "    </" + ConcatFieldsNodeNameSpace + ">" + Const.CR;
  return retval;
}
 
Example #18
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases )
  throws KettleException {
  super.readRep( rep, metaStore, id_step, databases );
  targetFieldName = rep.getStepAttributeString( id_step, ConcatFieldsNodeNameSpace + "targetFieldName" );
  targetFieldLength =
    (int) rep.getStepAttributeInteger( id_step, ConcatFieldsNodeNameSpace + "targetFieldLength" );
  removeSelectedFields =
    rep.getStepAttributeBoolean( id_step, ConcatFieldsNodeNameSpace + "removeSelectedFields" );

  // PDI-18028: Avoid fileName handling!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );
}
 
Example #19
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step )
  throws KettleException {
  // PDI-18028: Avoid fileName handling!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );

  super.saveRep( rep, metaStore, id_transformation, id_step );
  rep.saveStepAttribute(
    id_transformation, id_step, ConcatFieldsNodeNameSpace + "targetFieldName", targetFieldName );
  rep.saveStepAttribute(
    id_transformation, id_step, ConcatFieldsNodeNameSpace + "targetFieldLength", targetFieldLength );
  rep.saveStepAttribute(
    id_transformation, id_step, ConcatFieldsNodeNameSpace + "removeSelectedFields", removeSelectedFields );
}
 
Example #20
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param retVal
 * @param value
 */
@Override
protected void saveSource( StringBuilder retVal, String value ) {
  // PDI-18028: Avoid fileName handling!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );

  super.saveSource( retVal, value );
}
 
Example #21
Source File: ConcatFieldsMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void setDefault() {
  super.setDefault();
  // overwrite header
  super.setHeaderEnabled( false );
  // PDI-18028: ConcatFields doesn't need or use the 'fileName' field!
  super.setFileName( StringUtil.EMPTY_STRING );
  super.setFileNameInField( false );
  // set default for new properties specific to the concat fields
  targetFieldName = StringUtil.EMPTY_STRING;
  targetFieldLength = 0;
  removeSelectedFields = false;
}
 
Example #22
Source File: SpecialMethodProcessor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void schemaSelection( PartitionSettings settings, Shell shell, SpoonDelegates delegates )
  throws KettleException {
  String schema =
    super.askForSchema( settings.getSchemaNamesArray(), shell, settings.getDefaultSelectedSchemaIndex() );
  super.processForKnownSchema( schema, settings );
  if ( !StringUtil.isEmpty( schema ) ) {
    askForField( settings, delegates );
  }
}
 
Example #23
Source File: MetricsDuration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  if ( Utils.isEmpty( subject ) ) {
    return description
      + " @ " + StringUtil.getFormattedDateTime( date, true ) + " : "
      + ( duration == null ? "-" : duration.toString() ) + ( count == null ? "" : " (x" + count + ")" );
  } else {
    return description
      + " / " + subject + " @ " + StringUtil.getFormattedDateTime( date, true ) + " : "
      + ( duration == null ? "-" : duration.toString() ) + ( count == null ? "" : " (x" + count + ")" );
  }
}
 
Example #24
Source File: MetricsSnapshot.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( logChannelId );
  String subject = null;
  if ( loggingObject != null ) {
    subject = loggingObject.getObjectName() + "(" + loggingObject.getObjectType() + ")";
  } else {
    subject = "-";
  }

  return subject
    + " - " + getKey() + " @ " + StringUtil.getFormattedDateTime( date, true ) + " : " + type.toString();

}
 
Example #25
Source File: StepOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void checkLong( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                              String identifier, String value ) {
  try {
    if ( !StringUtil.isEmpty( space.environmentSubstitute( value ) ) ) {
      Long.parseLong( space.environmentSubstitute( value ) );
    }
  } catch ( NumberFormatException e ) {
    remarks.add( new CheckResult(
      CheckResultInterface.TYPE_RESULT_ERROR,
      BaseMessages.getString( PKG, "StepOption.CheckResult.NotAInteger", identifier ),
      stepMeta ) );
  }
}
 
Example #26
Source File: StepOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void checkBoolean( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                                 String identifier, String value ) {
  if ( !StringUtil.isEmpty( space.environmentSubstitute( value ) ) && null == BooleanUtils
    .toBooleanObject( space.environmentSubstitute( value ) ) ) {
    remarks.add( new CheckResult(
      CheckResultInterface.TYPE_RESULT_ERROR,
      BaseMessages.getString( PKG, "StepOption.CheckResult.NotABoolean", identifier ),
      stepMeta ) );
  }
}
 
Example #27
Source File: SpeedTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static void populateMetaAndData( int i, Object[] rowString10, RowMetaInterface metaString10,
                                         Object[] rowMixed10, RowMetaInterface metaMixed10 ) {
  String strNamePrefix = "String";
  rowString10[i] = StringUtil.generateRandomString( 20, "", "", false );
  ValueMetaInterface meta = new ValueMetaString( strNamePrefix + ( i + 1 ), 20, 0 );
  metaString10.addValueMeta( meta );

  rowMixed10[i * 5 + 0] = StringUtil.generateRandomString( 20, "", "", false );
  ValueMetaInterface meta0 = new ValueMetaString( strNamePrefix + ( i * 5 + 1 ), 20, 0 );
  metaMixed10.addValueMeta( meta0 );

  rowMixed10[i * 5 + 1] = new Date();
  ValueMetaInterface meta1 = new ValueMetaDate( strNamePrefix + ( i * 5 + 1 ) );
  metaMixed10.addValueMeta( meta1 );

  rowMixed10[i * 5 + 2] = Double.valueOf( Math.random() * 1000000 );
  ValueMetaInterface meta2 = new ValueMetaNumber( strNamePrefix + ( i * 5 + 1 ), 12, 4 );
  metaMixed10.addValueMeta( meta2 );

  rowMixed10[i * 5 + 3] = Long.valueOf( (long) ( Math.random() * 1000000 ) );
  ValueMetaInterface meta3 = new ValueMetaInteger( strNamePrefix + ( i * 5 + 1 ), 8, 0 );
  metaMixed10.addValueMeta( meta3 );

  rowMixed10[i * 5 + 4] = Boolean.valueOf( Math.random() > 0.5 );
  ValueMetaInterface meta4 = new ValueMetaBoolean( strNamePrefix + ( i * 5 + 1 ) );
  metaMixed10.addValueMeta( meta4 );
}
 
Example #28
Source File: TextFileInputMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void whenExportingResourcesWeGetFileObjectsOnlyFromFilesWithNotNullAndNotEmptyFileNames() throws Exception {
  inputMeta.inputFiles = new BaseFileInputFiles();
  inputMeta.inputFiles.fileName = new String[] { FILE_NAME_NULL, FILE_NAME_EMPTY, FILE_NAME_VALID_PATH };
  inputMeta.inputFiles.fileMask =
    new String[] { StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING, StringUtil.EMPTY_STRING };

  inputMeta.exportResources( variableSpace, null, mock( ResourceNamingInterface.class ), null, null );

  verify( inputMeta ).getFileObject( FILE_NAME_VALID_PATH, variableSpace );
  verify( inputMeta, never() ).getFileObject( FILE_NAME_NULL, variableSpace );
  verify( inputMeta, never() ).getFileObject( FILE_NAME_EMPTY, variableSpace );
}
 
Example #29
Source File: DatabaseDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static final void checkPasswordVisible( Text wPassword ) {
  String password = wPassword.getText();
  java.util.List<String> list = new ArrayList<String>();
  StringUtil.getUsedVariables( password, list, true );
  // ONLY show the variable in clear text if there is ONE variable used
  // Also, it has to be the only string in the field.
  //

  if ( list.size() != 1 ) {
    wPassword.setEchoChar( '*' );
  } else {
    String variableName = null;
    if ( ( password.startsWith( StringUtil.UNIX_OPEN ) && password.endsWith( StringUtil.UNIX_CLOSE ) ) ) {
      // ${VAR}
      // 012345
      //
      variableName =
        password.substring( StringUtil.UNIX_OPEN.length(), password.length() - StringUtil.UNIX_CLOSE.length() );
    }
    if ( ( password.startsWith( StringUtil.WINDOWS_OPEN ) && password.endsWith( StringUtil.WINDOWS_CLOSE ) ) ) {
      // %VAR%
      // 01234
      //
      variableName =
        password.substring( StringUtil.WINDOWS_OPEN.length(), password.length()
          - StringUtil.WINDOWS_CLOSE.length() );
    }

    // If there is a variable name in there AND if it's defined in the system properties...
    // Otherwise, we'll leave it alone.
    //
    if ( variableName != null && System.getProperty( variableName ) != null ) {
      wPassword.setEchoChar( '\0' ); // Show it all...
    } else {
      wPassword.setEchoChar( '*' );
    }
  }
}
 
Example #30
Source File: SpecialMethodProcessor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void askForField( PartitionSettings settings, SpoonDelegates delegates ) throws KettleException {
  StepDialogInterface partitionDialog =
    delegates.steps.getPartitionerDialog( settings.getStepMeta(), settings.getStepMeta().getStepPartitioningMeta(),
      settings.getTransMeta() );
  String  fieldName = partitionDialog.open();
  if ( StringUtil.isEmpty( fieldName ) ) {
    settings.rollback( settings.getBefore() );
  }
}