Package org.pentaho.di.core.util
Class StringUtil
java.lang.Object
org.pentaho.di.core.util.StringUtil
A collection of utilities to manipulate strings.
- Author:
- wdeclerc
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringenvironmentSubstitute(String aString, Map<String, String> systemProperties) Substitutes variables inaStringwith the environment values in the system propertiesstatic final StringenvironmentSubstitute(String aString, Map<String, String> systemProperties, boolean escapeHexDelimiter) Substitutes variables inaStringwith the environment values in the system propertiesstatic final StringgenerateRandomString(int length, String prefix, String postfix, boolean uppercase) static StringgetFormattedDateTime(Date date) Giving back a date/time string in the format following the rule from the most to the least significantstatic StringgetFormattedDateTime(Date date, boolean milliseconds) Giving back a date/time string in the format following the rule from the most to the least significantstatic StringGiving back the actual time as a date/time string in the format following the rule from the most to the least significantstatic StringgetFormattedDateTimeNow(boolean milliseconds) Giving back the actual time as a date/time string in the format following the rule from the most to the least significantstatic StringgetIndent(int indentLevel) static voidgetUsedVariables(String aString, String open, String close, List<String> list, boolean includeSystemVariables) Search the string and report back on the variables usedstatic voidgetUsedVariables(String aString, List<String> list, boolean includeSystemVariables) static final StringgetVariableName(String variable) remove specification from variablestatic booleanhasVariable(String variable) static Stringstatic booleanstatic booleanstatic final booleanCheck if the string supplied is empty.static final booleanisEmpty(StringBuilder string) Check if the StringBuilder supplied is empty.static booleanstatic booleanstatic booleanisSystemVariable(String aString) static booleanisVariable(String variable) static StringsafeToLowerCase(Object obj) Calls theString.toLowerCase()method on theStringreturned by a call toobj.toString(), guarding againstNullPointerExceptions.static Datestatic doublestatic StringSubstitutes variables inaString.static Stringsubstitute(String aString, Map<String, String> variablesValues, String open, String close, int recursion) Substitutes variables inaString.static StringsubstituteField(String aString, RowMetaInterface rowMeta, Object[] rowData) Substitutes field values inaString.static StringsubstituteHex(String aString) Substitutes hex values inaStringand convert them to operating system char equivalents in the return string.static StringsubstituteUnix(String aString, Map<String, String> variables) Substitutes variables inaString.static StringsubstituteWindows(String aString, Map<String, String> variables) Substitutes variables inaString.static URIConvert a raw path such as c:\tmp\park.parquet and /tmp/file, or, URL such as pvfs://tkSnowflakeStaging/@ORC_FILES or hc://clusterName/path/to/file to a URIstatic StringRemoves all instances of the specified character from the end of the givenString.static StringRemoves all instances of the specified character from the start of the givenString.
-
Field Details
-
UNIX_OPEN
- See Also:
-
UNIX_CLOSE
- See Also:
-
WINDOWS_OPEN
- See Also:
-
WINDOWS_CLOSE
- See Also:
-
HEX_OPEN
- See Also:
-
HEX_CLOSE
- See Also:
-
FIELD_OPEN
- See Also:
-
FIELD_CLOSE
- See Also:
-
CRLF
- See Also:
-
INDENTCHARS
- See Also:
-
EMPTY_STRING
- See Also:
-
SYSTEM_PROPERTIES
-
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
substitute
public static String substitute(String aString, Map<String, String> variablesValues, String open, String close) Substitutes variables inaString. Variable names are delimited by open and close strings. The values are retrieved from the given map.- Parameters:
aString- the string on which to apply the substitution.variablesValues- a map containing the variable values. The keys are the variable names, the values are the variable values.open- the open delimiter for variables.close- the close delimiter for variables.- Returns:
- the string with the substitution applied.
-
substitute
public static String substitute(String aString, Map<String, String> variablesValues, String open, String close, int recursion) Substitutes variables inaString. Variable names are delimited by open and close strings. The values are retrieved from the given map.- Parameters:
aString- the string on which to apply the substitution.variablesValues- a map containg the variable values. The keys are the variable names, the values are the variable values.open- the open delimiter for variables.close- the close delimiter for variables.recursion- the number of recursion (internal counter to avoid endless loops)- Returns:
- the string with the substitution applied.
-
substituteHex
Substitutes hex values inaStringand convert them to operating system char equivalents in the return string. Format is $[01] or $[6F,FF,00,1F] Example: "This is a hex encoded six digits number 123456 in this string: $[31,32,33,34,35,36]"- Parameters:
aString- the string on which to apply the substitution.- Returns:
- the string with the substitution applied.
-
environmentSubstitute
public static final String environmentSubstitute(String aString, Map<String, String> systemProperties) Substitutes variables inaStringwith the environment values in the system properties- Parameters:
aString- the string on which to apply the substitution.systemProperties- the system properties to use- Returns:
- the string with the substitution applied.
-
environmentSubstitute
public static final String environmentSubstitute(String aString, Map<String, String> systemProperties, boolean escapeHexDelimiter) Substitutes variables inaStringwith the environment values in the system properties- Parameters:
aString- the string on which to apply the substitution.systemProperties- the system properties to use- Returns:
- the string with the substitution applied.
-
substituteUnix
Substitutes variables inaString. Variables are of the form "${}", following the Unix scripting convention. The values are retrieved from the given map. - Parameters:
aString- the string on which to apply the substitution.variables- a map containg the variable values. The keys are the variable names, the values are the variable values.- Returns:
- the string with the substitution applied.
-
substituteWindows
Substitutes variables inaString. Variables are of the form "%%%%", following the Windows convention. The values are retrieved from the given map. - Parameters:
aString- the string on which to apply the substitution.variables- a map containg the variable values. The keys are the variable names, the values are the variable values.- Returns:
- the string with the substitution applied.
-
substituteField
public static String substituteField(String aString, RowMetaInterface rowMeta, Object[] rowData) throws KettleValueException Substitutes field values inaString. Field values are of the form "?{}". The values are retrieved from the specified row. Please note that the getString() method is used to convert to a String, for all values in the row. - Parameters:
aString- the string on which to apply the substitution.rowMeta- The row metadata to use.rowData- The row data to use- Returns:
- the string with the substitution applied.
- Throws:
KettleValueException- In case there is a String conversion error
-
getUsedVariables
public static void getUsedVariables(String aString, String open, String close, List<String> list, boolean includeSystemVariables) Search the string and report back on the variables used- Parameters:
aString- The string to searchopen- the open or "start of variable" characters ${ or %%close- the close or "end of variable" characters } or %%list- the list of variables to add toincludeSystemVariables- also check for system variables.
-
isSystemVariable
-
getUsedVariables
-
generateRandomString
-
initCap
-
str2num
public static double str2num(String pattern, String decimal, String grouping, String currency, String value) throws KettleValueException - Throws:
KettleValueException
-
isEmpty
Check if the string supplied is empty. A String is empty when it is null or when the length is 0- Parameters:
string- The string to check- Returns:
- true if the string supplied is empty
-
isEmpty
Check if the StringBuilder supplied is empty. A StringBuilder is empty when it is null or when the length is 0- Parameters:
string- The StringBuilder to check- Returns:
- true if the StringBuilder supplied is empty
-
str2dat
- Throws:
KettleValueException
-
getIndent
-
getFormattedDateTime
Giving back a date/time string in the format following the rule from the most to the least significant- Parameters:
date- the date to convert- Returns:
- a string in the form yyyddMM_hhmmss
-
getFormattedDateTime
Giving back a date/time string in the format following the rule from the most to the least significant- Parameters:
date- the date to convertmilliseconds- true when milliseconds should be added- Returns:
- a string in the form yyyddMM_hhmmssSSS (milliseconds will be optional)
-
getFormattedDateTimeNow
Giving back the actual time as a date/time string in the format following the rule from the most to the least significant- Returns:
- a string in the form yyyddMM_hhmmss
-
getFormattedDateTimeNow
Giving back the actual time as a date/time string in the format following the rule from the most to the least significant- Parameters:
milliseconds- true when milliseconds should be added- Returns:
- a string in the form yyyddMM_hhmmssSSS (milliseconds will be optional)
-
IsInteger
-
IsNumber
-
IsDate
-
IsDate
-
getVariableName
remove specification from variable- Parameters:
variable- the variable to look for, with the $ or % variable specification.- Returns:
- the variable name
-
isVariable
- Parameters:
variable- the variable to look for, with the $ or % variable specification.- Returns:
- true if the input is a variable, false otherwise
-
hasVariable
- Parameters:
variable- A String which may have a variable within it, with the $ or % variable specification.- Returns:
- true if the input has a variable, false otherwise
-
safeToLowerCase
Calls theString.toLowerCase()method on theStringreturned by a call toobj.toString(), guarding againstNullPointerExceptions. -
trimStart
Removes all instances of the specified character from the start of the givenString. -
trimEnd
Removes all instances of the specified character from the end of the givenString. -
toUri
Convert a raw path such as c:\tmp\park.parquet and /tmp/file, or, URL such as pvfs://tkSnowflakeStaging/@ORC_FILES or hc://clusterName/path/to/file to a URI- Parameters:
filePathOrUrl-- Returns:
-