Java Code Examples for org.pentaho.di.core.util.StringUtil#getUsedVariables()

The following examples show how to use org.pentaho.di.core.util.StringUtil#getUsedVariables() . 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: 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 2
Source File: CassandraOutputDialog.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
private void checkPasswordVisible() {
  String password = m_passText.getText();
  ArrayList<String> list = new ArrayList<String>();
  StringUtil.getUsedVariables(password, list, true);
  if (list.size() == 0) {
    m_passText.setEchoChar('*');
  } else {
    m_passText.setEchoChar('\0'); // show everything
  }
}
 
Example 3
Source File: CassandraInputDialog.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
private void checkPasswordVisible() {
  String password = m_passText.getText();
  ArrayList<String> list = new ArrayList<String>();
  StringUtil.getUsedVariables(password, list, true);
  if (list.size() == 0) {
    m_passText.setEchoChar('*');
  } else {
    m_passText.setEchoChar('\0'); // show everything
  }
}
 
Example 4
Source File: JobMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the used variables.
 *
 * @return the used variables
 */
public List<String> getUsedVariables() {
  // Get the list of Strings.
  List<StringSearchResult> stringList = getStringList( true, true, false );

  List<String> varList = new ArrayList<String>();

  // Look around in the strings, see what we find...
  for ( StringSearchResult result : stringList ) {
    StringUtil.getUsedVariables( result.getString(), varList, false );
  }

  return varList;
}
 
Example 5
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 6
Source File: RepositoryImporter.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private static boolean containsVariables( String entryPath ) {
  List<String> variablesList = new ArrayList<String>();
  StringUtil.getUsedVariables( entryPath, variablesList, true );
  return !variablesList.isEmpty();
}
 
Example 7
Source File: RepositoryImporterExtension.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private static boolean containsVariables( String entryPath ) {
  List<String> variablesList = new ArrayList<String>();
  StringUtil.getUsedVariables( entryPath, variablesList, true );
  return !variablesList.isEmpty();
}