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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final String
environmentSubstitute
(String aString, Map<String, String> systemProperties) Substitutes variables inaString
with the environment values in the system propertiesstatic final String
environmentSubstitute
(String aString, Map<String, String> systemProperties, boolean escapeHexDelimiter) Substitutes variables inaString
with the environment values in the system propertiesstatic final String
generateRandomString
(int length, String prefix, String postfix, boolean uppercase) static String
getFormattedDateTime
(Date date) Giving back a date/time string in the format following the rule from the most to the least significantstatic String
getFormattedDateTime
(Date date, boolean milliseconds) Giving back a date/time string in the format following the rule from the most to the least significantstatic String
Giving back the actual time as a date/time string in the format following the rule from the most to the least significantstatic String
getFormattedDateTimeNow
(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 String
getIndent
(int indentLevel) static void
getUsedVariables
(String aString, String open, String close, List<String> list, boolean includeSystemVariables) Search the string and report back on the variables usedstatic void
getUsedVariables
(String aString, List<String> list, boolean includeSystemVariables) static final String
getVariableName
(String variable) remove specification from variablestatic boolean
hasVariable
(String variable) static String
static boolean
static boolean
static final boolean
Check if the string supplied is empty.static final boolean
isEmpty
(StringBuilder string) Check if the StringBuilder supplied is empty.static boolean
static boolean
static boolean
isSystemVariable
(String aString) static boolean
isVariable
(String variable) static String
safeToLowerCase
(Object obj) Calls theString.toLowerCase()
method on theString
returned by a call toobj.toString()
, guarding againstNullPointerException
s.static Date
static double
static String
Substitutes variables inaString
.static String
substitute
(String aString, Map<String, String> variablesValues, String open, String close, int recursion) Substitutes variables inaString
.static String
substituteField
(String aString, RowMetaInterface rowMeta, Object[] rowData) Substitutes field values inaString
.static String
substituteHex
(String aString) Substitutes hex values inaString
and convert them to operating system char equivalents in the return string.static String
substituteUnix
(String aString, Map<String, String> variables) Substitutes variables inaString
.static String
substituteWindows
(String aString, Map<String, String> variables) Substitutes variables inaString
.static URI
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 URIstatic String
Removes all instances of the specified character from the end of the givenString
.static String
Removes 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 inaString
and 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 inaString
with 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 inaString
with 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 theString
returned by a call toobj.toString()
, guarding againstNullPointerException
s. -
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:
-