Class CmsStringUtil
- Since:
- 6.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCompares two Strings according to the count of containing slashes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringRegular expression that matches the HTML body end tag.static final StringRegular expression that matches the HTML body start tag.static final StringConstant for"false".static final Stringa convenient shorthand to the line separator constant.static final StringContext macro.static final PatternPattern to determine a locale for suffixes like '_de' or '_en_US'.static final PatternPattern to determine the document number for suffixes like '_0001'.static final PatternPattern matching one or more slashes.static final StringThe place holder end sign in the pattern.static final StringThe place holder start sign in the pattern.static final char[]Contains all chars that end a sentence in thetrimToSize(String, int, int, String)method.static final Stringa convenient shorthand for tabulations.static final StringConstant for"true". -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAdds leading and trailing slashes to a path, if the path does not already start or end with a slash.static StringarrayAsString(String[] arg, String separator) Returns a string representation for the given array using the given separator.static StringchangeFileNameSuffixTo(String filename, String suffix) Changes the given filenames suffix from the current suffix to the provided suffix.static voidcheckName(String name, String constraints, String key, I_CmsMessageBundle bundle) Checks if a given name is composed only of the charactersa...z,A...Z,0...9and the providedconstraints.static StringcollectionAsString(Collection<?> collection, String separator) Returns a string representation for the given collection using the given separator.static booleancomparePaths(String path1, String path2) Compares two paths, ignoring leading and trailing slashes.static intCounts the occurrence of a given char in a given String.enumNameToStringArray(T[] values) Returns a String array representation for the given enum.static StringescapeHtml(String source) Replaces line breaks to<br/>and HTML control characters like< > & "with their HTML entity representation.static StringescapeJavaScript(String source) Escapes a String so it may be used in JavaScript String definitions.static StringescapePattern(String source) Escapes a String so it may be used as a Perl5 regular expression.extendAttribute(String text, String attribute, String defValue) This method takes a part of a html tag definition, an attribute to extend within the given text and a default value for this attribute; and returns awith 2 values: aMapwith keyString"text"with the new text without the given attribute, and anotherwith keyString"value"with the new extended value for the given attribute, this value is surrounded by the same type of quotation marks as in the given text.static StringextractHtmlBody(String content) Extracts the content of a<body>tag in a HTML page.static StringextractXmlEncoding(String content) Extracts the xml encoding setting from an xml file that is contained in a String by parsing the xml head.static StringformatResourceName(String name, int maxLength) Shortens a resource name or path so that it is not longer than the provided maximum length.static StringformatRuntime(long runtime) Formats a runtime in the format hh:mm:ss, to be used e.g.static ColorgetColorValue(String value, Color defaultValue, String key) Returns the color value () for the given String value.Colorstatic StringgetCommonPrefixPath(String first, String second) Returns the common parent path of two paths.static StringReturns the Ethernet-Address of the locale host.static intgetIntValue(String value, int defaultValue, String key) Returns the Integer (int) value for the given String value.static intgetIntValueRounded(String value, int defaultValue, String key) Returns the closest Integer (int) value for the given String value.static LocalegetLocaleForName(String name) Returns a Locale calculated from the suffix of the given String, ornullif no locale suffix is found.static LocalegetLocaleForText(String text) Returns the locale for the given text based on the language detection library.static StringgetLocaleSuffixForName(String name) Returns the locale suffix from the given String, ornullif no locae suffix is found.static longgetLongValue(String value, long defaultValue, String key) Returns the Long (long) value for the given String value.getPathComponents(String path) Splits a path into its non-empty path components.static StringgetRelativeSubPath(String base, String path) Converts the given path to a path relative to a base folder, but only if it actually is a sub-path of the latter, otherwisenullis returned.static StringindentLines(String text, int numSpaces) Inserts the given number of spaces at the start of each line in the given text.static booleanReturnstrueif the provided String is eithernullor the empty String"".static booleanisEmptyOrWhitespaceOnly(String value) Returnstrueif the provided String is eithernullor contains only white spaces.static booleanReturnstrueif the provided Objects are either bothnullor equal according toObject.equals(Object).static booleanisNotEmpty(String value) Returnstrueif the provided String is neithernullnor the empty String"".static booleanisNotEmptyOrWhitespaceOnly(String value) Returnstrueif the provided String is neithernullnor contains only white spaces.static booleanisPrefixPath(String firstPath, String secondPath) Checks if the first path is a prefix of the second path.static booleanisProperPrefixPath(String firstPath, String secondPath) Checks if the first path is a prefix of the second path, but not equivalent to it.static booleanisValidJavaClassName(String className) Checks if the given class name is a valid Java class name.static StringConcatenates multiple paths and separates them with '/'.static StringConcatenates multiple paths and separates them with '/'.static intlastIndexOf(String source, char[] chars) Returns the last index of any of the given chars in the given source.static intlastWhitespaceIn(String source) Returns the last index a whitespace char the given source.static StringlistAsString(List<?> list, String separator) Returns a string representation for the given list using the given separator.static StringEncodes a map with string keys and values as a JSON string with the same keys/values.static <K,V> String mapAsString(Map<K, V> map, String sepItem, String sepKeyval) Returns a string representation for the given map using the given separators.static StringApplies white space padding to the left of the given String.static StringApplies white space padding to the right of the given String.static final longparseDuration(String durationStr, long defaultValue) Parses a duration and returns the corresponding number of milliseconds.static org.antlr.stringtemplate.StringTemplateGroupreadStringTemplateGroup(InputStream stream) Reads a stringtemplate group from a stream.removePrefixPath(String prefix, String path) static com.google.common.base.Optional<String> replacePrefix(String text, String origPrefix, String newPrefix, boolean ignoreCase) Replaces a constant prefix with another string constant in a given text.static String[]splitAsArray(String source, char delimiter) Splits a String into substrings along the provided char delimiter and returns the result as an Array of Substrings.static String[]splitAsArray(String source, String delimiter) Splits a String into substrings along the provided String delimiter and returns the result as an Array of Substrings.splitAsList(String source, char delimiter) Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings.splitAsList(String source, char delimiter, boolean trim) Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings.splitAsList(String source, String delimiter) Splits a String into substrings along the provided String delimiter and returns the result as List of Substrings.splitAsList(String source, String delimiter, boolean trim) Splits a String into substrings along the provided String delimiter and returns the result as List of Substrings.splitAsMap(String source, String paramDelim, String keyValDelim) Splits a String into substrings along the providedparamDelimdelimiter, then each substring is treat as a key-value pair delimited bykeyValDelim.splitOptions(String optionsStr) Specialized version of splitAsMap used for splitting option lists for widgets.static Stringsubstitute(String source, String searchString, String replaceString) SubstitutessearchStringin the given source String withreplaceString.static Stringsubstitute(String source, Map<String, String> substitions) Replaces a set ofsearchStringandreplaceStringpairs, given by thesubstitutionsMap parameter.static Stringsubstitute(Pattern pattern, String text, I_CmsRegexSubstitution sub) Substitutes a pattern in a string using aI_CmsRegexSubstitution.static StringsubstituteContextPath(String htmlContent, String context) Substitutes the OpenCms context path (e.g.static StringsubstitutePerl(String content, String searchString, String replaceItem, String occurences) Substitutes searchString in content with replaceItem.static StringReturns the java String literal for the given String.static StringtransformValues(String oldFormat, String newFormat, String value) This method transformes a string which matched a format with one or more place holders into another format.static StringtranslatePathComponents(CmsResourceTranslator translator, String path) Translates all consecutive sequences of non-slash characters in a path using the given resource translator.static StringtrimToSize(String source, int length) Returns a substring of the source, which is at most length characters long.static StringtrimToSize(String source, int length, int area, String suffix) Returns a substring of the source, which is at most length characters long, cut in the lastareachars in the source at a sentence ending char or whitespace.static StringtrimToSize(String source, int length, String suffix) Returns a substring of the source, which is at most length characters long.static booleanvalidateRegex(String value, String regex, boolean allowEmpty) Validates a value against a regular expression.
-
Field Details
-
BODY_END_REGEX
Regular expression that matches the HTML body end tag.- See Also:
-
BODY_START_REGEX
Regular expression that matches the HTML body start tag.- See Also:
-
FALSE
Constant for"false". -
LINE_SEPARATOR
a convenient shorthand to the line separator constant. -
MACRO_OPENCMS_CONTEXT
Context macro.- See Also:
-
PATTERN_LOCALE_SUFFIX
Pattern to determine a locale for suffixes like '_de' or '_en_US'. -
PATTERN_NUMBER_SUFFIX
Pattern to determine the document number for suffixes like '_0001'. -
PATTERN_SLASHES
Pattern matching one or more slashes. -
PLACEHOLDER_END
The place holder end sign in the pattern.- See Also:
-
PLACEHOLDER_START
The place holder start sign in the pattern.- See Also:
-
SENTENCE_ENDING_CHARS
Contains all chars that end a sentence in thetrimToSize(String, int, int, String)method. -
TABULATOR
a convenient shorthand for tabulations.- See Also:
-
TRUE
Constant for"true".
-
-
Method Details
-
addLeadingAndTrailingSlash
Adds leading and trailing slashes to a path, if the path does not already start or end with a slash.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
path- the path to which add the slashes- Returns:
- the path with added leading and trailing slashes
-
arrayAsString
Returns a string representation for the given array using the given separator.- Parameters:
arg- the array to transform to a Stringseparator- the item separator- Returns:
- the String of the given array
-
changeFileNameSuffixTo
Changes the given filenames suffix from the current suffix to the provided suffix. Directly exposed for JSP EL, not throughCmsJspElFunctions.- Parameters:
filename- the filename to be changedsuffix- the new suffix of the file- Returns:
- the filename with the replaced suffix
-
checkName
public static void checkName(String name, String constraints, String key, I_CmsMessageBundle bundle) throws CmsIllegalArgumentException Checks if a given name is composed only of the charactersa...z,A...Z,0...9and the providedconstraints.If the check fails, an Exception is generated. The provided bundle and key is used to generate the Exception. 4 parameters are passed to the Exception:
- The
name - The first illegal character found
- The position where the illegal character was found
- The
constraints
- Parameters:
name- the name to checkconstraints- the additional character constraintskey- the key to use for generating the Exception (if required)bundle- the bundle to use for generating the Exception (if required)- Throws:
CmsIllegalArgumentException- if the check fails (generated from the given key and bundle)
- The
-
collectionAsString
Returns a string representation for the given collection using the given separator.- Parameters:
collection- the collection to printseparator- the item separator- Returns:
- the string representation for the given collection
-
comparePaths
Compares two paths, ignoring leading and trailing slashes.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
path1- the first pathpath2- the second path- Returns:
- true if the paths are equal (ignoring leading and trailing slashes)
-
countChar
Counts the occurrence of a given char in a given String.- Parameters:
s- the stringc- the char to count- Returns:
- returns the count of occurrences of a given char in a given String
-
enumNameToStringArray
Returns a String array representation for the given enum.- Type Parameters:
T- the type of the enum- Parameters:
values- the enum values- Returns:
- the representing String array
-
escapeHtml
Replaces line breaks to<br/>and HTML control characters like< > & "with their HTML entity representation.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
source- the String to escape- Returns:
- the escaped String
-
escapeJavaScript
Escapes a String so it may be used in JavaScript String definitions.This method escapes line breaks (
\r\n,\n) quotation marks (".') and slash as well as backspace characters (\,/).Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
source- the String to escape- Returns:
- the escaped String
-
escapePattern
Escapes a String so it may be used as a Perl5 regular expression.This method replaces the following characters in a String:
{}[]()\$^.*+/Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
source- the string to escape- Returns:
- the escaped string
-
extendAttribute
This method takes a part of a html tag definition, an attribute to extend within the given text and a default value for this attribute; and returns awith 2 values: aMapwith keyString"text"with the new text without the given attribute, and anotherwith keyString"value"with the new extended value for the given attribute, this value is surrounded by the same type of quotation marks as in the given text.- Parameters:
text- the text to search inattribute- the attribute to remove and extend from the textdefValue- a default value for the attribute, should not have any quotation mark- Returns:
- a map with the new text and the new value for the given attribute
-
extractHtmlBody
Extracts the content of a<body>tag in a HTML page.This method should be pretty robust and work even if the input HTML does not contains a valid body tag.
Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
content- the content to extract the body from- Returns:
- the extracted body tag content
-
extractXmlEncoding
Extracts the xml encoding setting from an xml file that is contained in a String by parsing the xml head.This is useful if you have a byte array that contains a xml String, but you do not know the xml encoding setting. Since the encoding setting in the xml head is usually encoded with standard US-ASCII, you usually just create a String of the byte array without encoding setting, and use this method to find the 'true' encoding. Then create a String of the byte array again, this time using the found encoding.
This method will return
nullin case no xml head or encoding information is contained in the input.- Parameters:
content- the xml content to extract the encoding from- Returns:
- the extracted encoding, or null if no xml encoding setting was found in the input
-
formatResourceName
Shortens a resource name or path so that it is not longer than the provided maximum length.In order to reduce the length of the resource name, only complete folder names are removed and replaced with ... successively, starting with the second folder. The first folder is removed only in case the result still does not fit if all subfolders have been removed.
Example:
formatResourceName("/myfolder/subfolder/index.html", 21)returns/myfolder/.../index.html.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
name- the resource name to formatmaxLength- the maximum length of the resource name (without leading/...)- Returns:
- the formatted resource name
-
formatRuntime
Formats a runtime in the format hh:mm:ss, to be used e.g. in reports.If the runtime is greater then 24 hours, the format dd:hh:mm:ss is used.
- Parameters:
runtime- the time to format- Returns:
- the formatted runtime
-
getColorValue
Returns the color value () for the given String value.ColorAll parse errors are caught and the given default value is returned in this case.
- Parameters:
value- the value to parse as colordefaultValue- the default value in case of parsing errorskey- a key to be included in the debug output in case of parse errors- Returns:
- the int value for the given parameter value String
-
getCommonPrefixPath
Returns the common parent path of two paths.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
first- the first pathsecond- the second path- Returns:
- the common prefix path
-
getEthernetAddress
Returns the Ethernet-Address of the locale host.A dummy ethernet address is returned, if the ip is representing the loopback address or in case of exceptions.
- Returns:
- the Ethernet-Address
-
getIntValue
Returns the Integer (int) value for the given String value.All parse errors are caught and the given default value is returned in this case.
- Parameters:
value- the value to parse as intdefaultValue- the default value in case of parsing errorskey- a key to be included in the debug output in case of parse errors- Returns:
- the int value for the given parameter value String
-
getIntValueRounded
Returns the closest Integer (int) value for the given String value.All parse errors are caught and the given default value is returned in this case.
- Parameters:
value- the value to parse as int, can also represent a float valuedefaultValue- the default value in case of parsing errorskey- a key to be included in the debug output in case of parse errors- Returns:
- the closest int value for the given parameter value String
-
getLocaleForName
Returns a Locale calculated from the suffix of the given String, ornullif no locale suffix is found.The locale returned will include the optional country code if this was part of the suffix.
Calls
CmsResource.getName(String)first, so the given name can also be a resource root path.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
name- the name to get the locale for- Returns:
- the locale, or
null - See Also:
-
getLocaleForText
Returns the locale for the given text based on the language detection library.The result will be
nullif the detection fails or the detected locale is not configured in the 'opencms-system.xml' as available locale.- Parameters:
text- the text to retrieve the locale for- Returns:
- the detected locale for the given text
-
getLocaleSuffixForName
Returns the locale suffix from the given String, ornullif no locae suffix is found.Uses the the
PATTERN_LOCALE_SUFFIXto find a language_country occurrence in the given name and returns the first group of the match.Examples:
rabbit_en_EN.html -> Locale[en_EN]rabbit_en_EN -> Locale[en_EN]rabbit_en.html -> Locale[en]rabbit_en -> Locale[en]rabbit_en. -> Locale[en]rabbit_enr -> nullrabbit_en.tar.gz -> null
CmsJspElFunctions.- Parameters:
name- the resource name to get the locale suffix for- Returns:
- the locale suffix if found,
nullotherwise
-
getLongValue
Returns the Long (long) value for the given String value.All parse errors are caught and the given default value is returned in this case.
- Parameters:
value- the value to parse as longdefaultValue- the default value in case of parsing errorskey- a key to be included in the debug output in case of parse errors- Returns:
- the long value for the given parameter value String
-
getPathComponents
Splits a path into its non-empty path components.If the path is the root path, an empty list will be returned.
Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
path- the path to split- Returns:
- the list of non-empty path components
-
getRelativeSubPath
Converts the given path to a path relative to a base folder, but only if it actually is a sub-path of the latter, otherwisenullis returned.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
base- the base pathpath- the path which should be converted to a relative path- Returns:
- 'path' converted to a path relative to 'base', or null if 'path' is not a sub-folder of 'base'
-
indentLines
Inserts the given number of spaces at the start of each line in the given text.This is useful when writing toString() methods for complex nested objects.
- Parameters:
text- the text to indentnumSpaces- the number of spaces to insert before each line- Returns:
- the indented text
-
isEmpty
Returnstrueif the provided String is eithernullor the empty String"".- Parameters:
value- the value to check- Returns:
- true, if the provided value is null or the empty String, false otherwise
-
isEmptyOrWhitespaceOnly
Returnstrueif the provided String is eithernullor contains only white spaces.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
value- the value to check- Returns:
- true, if the provided value is null or contains only white spaces, false otherwise
-
isEqual
Returnstrueif the provided Objects are either bothnullor equal according toObject.equals(Object).- Parameters:
value1- the first object to comparevalue2- the second object to compare- Returns:
trueif the provided Objects are either bothnullor equal according toObject.equals(Object)
-
isNotEmpty
Returnstrueif the provided String is neithernullnor the empty String"".- Parameters:
value- the value to check- Returns:
- true, if the provided value is not null and not the empty String, false otherwise
-
isNotEmptyOrWhitespaceOnly
Returnstrueif the provided String is neithernullnor contains only white spaces.- Parameters:
value- the value to check- Returns:
true, if the provided value isnullor contains only white spaces,falseotherwise
-
isPrefixPath
Checks if the first path is a prefix of the second path.This method is different compared to
String.startsWith(java.lang.String, int), because it considers/foo/barto be a prefix path of/foo/bar/baz, but not of/foo/bar42. Directly exposed for JSP EL, not throughCmsJspElFunctions.- Parameters:
firstPath- the first pathsecondPath- the second path- Returns:
- true if the first path is a prefix path of the second path
-
isProperPrefixPath
Checks if the first path is a prefix of the second path, but not equivalent to it.- Parameters:
firstPath- the first pathsecondPath- the second path- Returns:
- true if the first path is a prefix path of the second path, but not equivalent
-
isValidJavaClassName
Checks if the given class name is a valid Java class name.Directly exposed for JSP EL, not through
CmsJspElFunctions.- Parameters:
className- the name to check- Returns:
- true if the given class name is a valid Java class name
-
joinPaths
Concatenates multiple paths and separates them with '/'.Consecutive slashes will be reduced to a single slash in the resulting string. For example, joinPaths("/foo/", "/bar", "baz") will return "/foo/bar/baz".
- Parameters:
paths- the list of paths- Returns:
- the joined path
-
joinPaths
Concatenates multiple paths and separates them with '/'.Consecutive slashes will be reduced to a single slash in the resulting string. For example joinPaths("/foo/", "/bar", "baz") will return "/foo/bar/baz".
If one of the argument paths already contains a double "//" this will also be reduced to '/'. For example joinPaths("/foo//bar/", "/baz") will return "/foo/bar/baz".
- Parameters:
paths- the array of paths- Returns:
- the joined path
-
lastIndexOf
Returns the last index of any of the given chars in the given source.If no char is found, -1 is returned.
- Parameters:
source- the source to checkchars- the chars to find- Returns:
- the last index of any of the given chars in the given source, or -1
-
lastWhitespaceIn
Returns the last index a whitespace char the given source.If no whitespace char is found, -1 is returned.
- Parameters:
source- the source to check- Returns:
- the last index a whitespace char the given source, or -1
-
listAsString
Returns a string representation for the given list using the given separator.- Parameters:
list- the list to writeseparator- the item separator string- Returns:
- the string representation for the given map
-
mapAsJson
Encodes a map with string keys and values as a JSON string with the same keys/values.- Parameters:
map- the input map- Returns:
- the JSON data containing the map entries
-
mapAsString
Returns a string representation for the given map using the given separators.- Type Parameters:
K- type of map keysV- type of map values- Parameters:
map- the map to writesepItem- the item separator stringsepKeyval- the key-value pair separator string- Returns:
- the string representation for the given map
-
padLeft
Applies white space padding to the left of the given String.- Parameters:
input- the input to pad leftsize- the size of the padding- Returns:
- the input padded to the left
-
padRight
Applies white space padding to the right of the given String.- Parameters:
input- the input to pad rightsize- the size of the padding- Returns:
- the input padded to the right
-
parseDuration
Parses a duration and returns the corresponding number of milliseconds. Durations consist of a space-separated list of components of the form {number}{time unit}, for example 1d 5m. The available units are d (days), h (hours), m (months), s (seconds), ms (milliseconds).- Parameters:
durationStr- the duration stringdefaultValue- the default value to return in case the pattern does not match- Returns:
- the corresponding number of milliseconds
-
readStringTemplateGroup
public static org.antlr.stringtemplate.StringTemplateGroup readStringTemplateGroup(InputStream stream) Reads a stringtemplate group from a stream. This will always return a group (empty if necessary), even if reading it from the stream fails.- Parameters:
stream- the stream to read from- Returns:
- the string template group
-
removePrefixPath
-
replacePrefix
public static com.google.common.base.Optional<String> replacePrefix(String text, String origPrefix, String newPrefix, boolean ignoreCase) Replaces a constant prefix with another string constant in a given text.If the input string does not start with the given prefix, Optional.absent() is returned.
- Parameters:
text- the text for which to replace the prefixorigPrefix- the original prefixnewPrefix- the replacement prefixignoreCase- if true, upper-/lower case differences will be ignored- Returns:
- an Optional containing either the string with the replaced prefix, or an absent value if the prefix could not be replaced
-
splitAsArray
Splits a String into substrings along the provided char delimiter and returns the result as an Array of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split at- Returns:
- the Array of splitted Substrings
-
splitAsArray
Splits a String into substrings along the provided String delimiter and returns the result as an Array of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split at- Returns:
- the Array of splitted Substrings
-
splitAsList
Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split at- Returns:
- the List of splitted Substrings
-
splitAsList
Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split attrim- flag to indicate if leading and trailing white spaces should be omitted- Returns:
- the List of splitted Substrings
-
splitAsList
Splits a String into substrings along the provided String delimiter and returns the result as List of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split at- Returns:
- the Array of splitted Substrings
-
splitAsList
Splits a String into substrings along the provided String delimiter and returns the result as List of Substrings.- Parameters:
source- the String to splitdelimiter- the delimiter to split attrim- flag to indicate if leading and trailing white spaces should be omitted- Returns:
- the Array of splitted Substrings
-
splitAsMap
Splits a String into substrings along the providedparamDelimdelimiter, then each substring is treat as a key-value pair delimited bykeyValDelim.- Parameters:
source- the string to splitparamDelim- the string to delimit each key-value pairkeyValDelim- the string to delimit key and value- Returns:
- a map of splitted key-value pairs
-
splitOptions
Specialized version of splitAsMap used for splitting option lists for widgets.This used the separator characters (':' for key/value, '|' for entries), but also allows escaping of these characters with backslashes ('\'), to enable use of colons/pipes in keys and values. Backslashes themselves can also be escaped.
- Parameters:
optionsStr- the string representing the option list- Returns:
- the options map
-
substitute
Substitutes a pattern in a string using aI_CmsRegexSubstitution.- Parameters:
pattern- the pattern to substitutetext- the text in which the pattern should be substitutedsub- the substitution handler- Returns:
- the transformed string
-
substitute
Replaces a set ofsearchStringandreplaceStringpairs, given by thesubstitutionsMap parameter.- Parameters:
source- the string to scansubstitions- the map of substitutions- Returns:
- the substituted String
- See Also:
-
substitute
SubstitutessearchStringin the given source String withreplaceString.This is a high-performance implementation which should be used as a replacement for
in case no regular expression evaluation is required.String.replaceAll(java.lang.String, java.lang.String)- Parameters:
source- the content which is scannedsearchString- the String which is searched in contentreplaceString- the String which replacessearchString- Returns:
- the substituted String
-
substituteContextPath
Substitutes the OpenCms context path (e.g. /opencms/opencms/) in a HTML page with a special variable so that the content also runs if the context path of the server changes.- Parameters:
htmlContent- the HTML to replace the context path incontext- the context path of the server- Returns:
- the HTML with the replaced context path
-
substitutePerl
public static String substitutePerl(String content, String searchString, String replaceItem, String occurences) Substitutes searchString in content with replaceItem.- Parameters:
content- the content which is scannedsearchString- the String which is searched in contentreplaceItem- the new String which replaces searchStringoccurences- must be a "g" if all occurrences of searchString shall be replaced- Returns:
- String the substituted String
-
toUnicodeLiteral
Returns the java String literal for the given String.This is the form of the String that had to be written into source code using the unicode escape sequence for special characters.
Example: "invalid input: 'Ä'" would be transformed to "\\u00C4".
- Parameters:
s- a string that may contain non-ascii characters- Returns:
- the java unicode escaped string Literal of the given input string
-
transformValues
This method transformes a string which matched a format with one or more place holders into another format. The other format also includes the same number of place holders. Place holders start withPLACEHOLDER_STARTand end withPLACEHOLDER_END.- Parameters:
oldFormat- the original formatnewFormat- the new formatvalue- the value which matched the original format and which shall be transformed into the new format- Returns:
- the new value with the filled place holder with the information in the parameter value
-
translatePathComponents
Translates all consecutive sequences of non-slash characters in a path using the given resource translator.- Parameters:
translator- the resource translatorpath- the path to translate- Returns:
- the translated path
-
trimToSize
Returns a substring of the source, which is at most length characters long.This is the same as calling
trimToSize(String, int, String)with the parameters(source, length, " ...").- Parameters:
source- the string to trimlength- the maximum length of the string to be returned- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
Returns a substring of the source, which is at most length characters long, cut in the lastareachars in the source at a sentence ending char or whitespace.If a char is cut, the given
suffixis appended to the result.- Parameters:
source- the string to trimlength- the maximum length of the string to be returnedarea- the area at the end of the string in which to find a sentence ender or whitespacesuffix- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
Returns a substring of the source, which is at most length characters long.If a char is cut, the given
suffixis appended to the result.This is almost the same as calling
trimToSize(String, int, int, String)with the parameters(source, length, length*, suffix). Iflengthif larger then 100, thenlength* = length / 2, otherwiselength* = length.- Parameters:
source- the string to trimlength- the maximum length of the string to be returnedsuffix- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-
validateRegex
Validates a value against a regular expression.- Parameters:
value- the value to testregex- the regular expressionallowEmpty- if an empty value is allowed- Returns:
trueif the value satisfies the validation
-