public final class CmsStringUtil extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CmsStringUtil.CmsSlashComparator
Compares two Strings according to the count of containing slashes.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BODY_END_REGEX
Regular expression that matches the HTML body end tag.
|
static java.lang.String |
BODY_START_REGEX
Regular expression that matches the HTML body start tag.
|
static java.lang.String |
FALSE
Constant for
"false" . |
static java.lang.String |
LINE_SEPARATOR
a convenient shorthand to the line separator constant.
|
static java.lang.String |
MACRO_OPENCMS_CONTEXT
Context macro.
|
static java.util.regex.Pattern |
PATTERN_LOCALE_SUFFIX
Pattern to determine a locale for suffixes like '_de' or '_en_US'.
|
static java.util.regex.Pattern |
PATTERN_NUMBER_SUFFIX
Pattern to determine the document number for suffixes like '_0001'.
|
static java.util.regex.Pattern |
PATTERN_SLASHES
Pattern matching one or more slashes.
|
static java.lang.String |
PLACEHOLDER_END
The place holder end sign in the pattern.
|
static java.lang.String |
PLACEHOLDER_START
The place holder start sign in the pattern.
|
static char[] |
SENTENCE_ENDING_CHARS
Contains all chars that end a sentence in the
trimToSize(String, int, int, String) method. |
static java.lang.String |
TABULATOR
a convenient shorthand for tabulations.
|
static java.lang.String |
TRUE
Constant for
"true" . |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addLeadingAndTrailingSlash(java.lang.String path)
Adds leading and trailing slashes to a path,
if the path does not already start or end with a slash.
|
static java.lang.String |
arrayAsString(java.lang.String[] arg,
java.lang.String separator)
Returns a string representation for the given array using the given separator.
|
static java.lang.String |
changeFileNameSuffixTo(java.lang.String filename,
java.lang.String suffix)
Changes the given filenames suffix from the current suffix to the provided suffix.
|
static void |
checkName(java.lang.String name,
java.lang.String constraints,
java.lang.String key,
I_CmsMessageBundle bundle)
Checks if a given name is composed only of the characters
a...z,A...Z,0...9
and the provided constraints . |
static java.lang.String |
collectionAsString(java.util.Collection<?> collection,
java.lang.String separator)
Returns a string representation for the given collection using the given separator.
|
static boolean |
comparePaths(java.lang.String path1,
java.lang.String path2)
Compares two paths, ignoring leading and trailing slashes.
|
static int |
countChar(java.lang.String s,
char c)
Counts the occurrence of a given char in a given String.
|
static <T extends java.lang.Enum<T>> |
enumNameToStringArray(T[] values)
Returns a String array representation for the given enum.
|
static java.lang.String |
escapeHtml(java.lang.String source)
Replaces line breaks to
<br/> and HTML control characters
like < > & " with their HTML entity representation. |
static java.lang.String |
escapeJavaScript(java.lang.String source)
Escapes a String so it may be used in JavaScript String definitions.
|
static java.lang.String |
escapePattern(java.lang.String source)
Escapes a String so it may be used as a Perl5 regular expression.
|
static java.util.Map<java.lang.String,java.lang.String> |
extendAttribute(java.lang.String text,
java.lang.String attribute,
java.lang.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 a
with 2 values: a with key "text" with the new text
without the given attribute, and another with key "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 java.lang.String |
extractHtmlBody(java.lang.String content)
Extracts the content of a
<body> tag in a HTML page. |
static java.lang.String |
extractXmlEncoding(java.lang.String content)
Extracts the xml encoding setting from an xml file that is contained in a String by parsing
the xml head.
|
static java.lang.String |
formatResourceName(java.lang.String name,
int maxLength)
Shortens a resource name or path so that it is not longer than the provided maximum length.
|
static java.lang.String |
formatRuntime(long runtime)
Formats a runtime in the format hh:mm:ss, to be used e.g. in reports.
|
static java.awt.Color |
getColorValue(java.lang.String value,
java.awt.Color defaultValue,
java.lang.String key)
Returns the color value (
) for the given String value. |
static java.lang.String |
getCommonPrefixPath(java.lang.String first,
java.lang.String second)
Returns the common parent path of two paths.
|
static java.lang.String |
getEthernetAddress()
Returns the Ethernet-Address of the locale host.
|
static int |
getIntValue(java.lang.String value,
int defaultValue,
java.lang.String key)
Returns the Integer (int) value for the given String value.
|
static int |
getIntValueRounded(java.lang.String value,
int defaultValue,
java.lang.String key)
Returns the closest Integer (int) value for the given String value.
|
static java.util.Locale |
getLocaleForName(java.lang.String name)
Returns a Locale calculated from the suffix of the given String, or
null if no locale suffix is found. |
static java.util.Locale |
getLocaleForText(java.lang.String text)
Returns the locale for the given text based on the language detection library.
|
static java.lang.String |
getLocaleSuffixForName(java.lang.String name)
Returns the locale suffix from the given String, or
null if no locae suffix is found. |
static long |
getLongValue(java.lang.String value,
long defaultValue,
java.lang.String key)
Returns the Long (long) value for the given String value.
|
static java.util.List<java.lang.String> |
getPathComponents(java.lang.String path)
Splits a path into its non-empty path components.
|
static java.lang.String |
getRelativeSubPath(java.lang.String base,
java.lang.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,
otherwise
null is returned. |
static boolean |
isEmpty(java.lang.String value)
Returns
true if the provided String is either null
or the empty String "" . |
static boolean |
isEmptyOrWhitespaceOnly(java.lang.String value)
Returns
true if the provided String is either null
or contains only white spaces. |
static boolean |
isEqual(java.lang.Object value1,
java.lang.Object value2)
Returns
true if the provided Objects are either both null
or equal according to Object.equals(Object) . |
static boolean |
isNotEmpty(java.lang.String value)
Returns
true if the provided String is neither null
nor the empty String "" . |
static boolean |
isNotEmptyOrWhitespaceOnly(java.lang.String value)
Returns
true if the provided String is neither null
nor contains only white spaces. |
static boolean |
isPrefixPath(java.lang.String firstPath,
java.lang.String secondPath)
Checks if the first path is a prefix of the second path.
|
static boolean |
isProperPrefixPath(java.lang.String firstPath,
java.lang.String secondPath)
Checks if the first path is a prefix of the second path, but not equivalent to it.
|
static boolean |
isValidJavaClassName(java.lang.String className)
Checks if the given class name is a valid Java class name.
|
static java.lang.String |
joinPaths(java.util.List<java.lang.String> paths)
Concatenates multiple paths and separates them with '/'.
|
static java.lang.String |
joinPaths(java.lang.String... paths)
Concatenates multiple paths and separates them with '/'.
|
static int |
lastIndexOf(java.lang.String source,
char[] chars)
Returns the last index of any of the given chars in the given source.
|
static int |
lastWhitespaceIn(java.lang.String source)
Returns the last index a whitespace char the given source.
|
static java.lang.String |
listAsString(java.util.List<?> list,
java.lang.String separator)
Returns a string representation for the given list using the given separator.
|
static java.lang.String |
mapAsJson(java.util.Map<java.lang.String,java.lang.String> map)
Encodes a map with string keys and values as a JSON string with the same keys/values.
|
static <K,V> java.lang.String |
mapAsString(java.util.Map<K,V> map,
java.lang.String sepItem,
java.lang.String sepKeyval)
Returns a string representation for the given map using the given separators.
|
static java.lang.String |
padLeft(java.lang.String input,
int size)
Applies white space padding to the left of the given String.
|
static java.lang.String |
padRight(java.lang.String input,
int size)
Applies white space padding to the right of the given String.
|
static long |
parseDuration(java.lang.String durationStr,
long defaultValue)
Parses a duration and returns the corresponding number of milliseconds.
|
static org.antlr.stringtemplate.StringTemplateGroup |
readStringTemplateGroup(java.io.InputStream stream)
Reads a stringtemplate group from a stream.
|
static com.google.common.base.Optional<java.lang.String> |
replacePrefix(java.lang.String text,
java.lang.String origPrefix,
java.lang.String newPrefix,
boolean ignoreCase)
Replaces a constant prefix with another string constant in a given text.
|
static java.lang.String[] |
splitAsArray(java.lang.String source,
char delimiter)
Splits a String into substrings along the provided char delimiter and returns
the result as an Array of Substrings.
|
static java.lang.String[] |
splitAsArray(java.lang.String source,
java.lang.String delimiter)
Splits a String into substrings along the provided String delimiter and returns
the result as an Array of Substrings.
|
static java.util.List<java.lang.String> |
splitAsList(java.lang.String source,
char delimiter)
Splits a String into substrings along the provided char delimiter and returns
the result as a List of Substrings.
|
static java.util.List<java.lang.String> |
splitAsList(java.lang.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.
|
static java.util.List<java.lang.String> |
splitAsList(java.lang.String source,
java.lang.String delimiter)
Splits a String into substrings along the provided String delimiter and returns
the result as List of Substrings.
|
static java.util.List<java.lang.String> |
splitAsList(java.lang.String source,
java.lang.String delimiter,
boolean trim)
Splits a String into substrings along the provided String delimiter and returns
the result as List of Substrings.
|
static java.util.Map<java.lang.String,java.lang.String> |
splitAsMap(java.lang.String source,
java.lang.String paramDelim,
java.lang.String keyValDelim)
Splits a String into substrings along the provided
paramDelim delimiter,
then each substring is treat as a key-value pair delimited by keyValDelim . |
static java.lang.String |
substitute(java.util.regex.Pattern pattern,
java.lang.String text,
I_CmsRegexSubstitution sub)
Substitutes a pattern in a string using a
I_CmsRegexSubstitution . |
static java.lang.String |
substitute(java.lang.String source,
java.util.Map<java.lang.String,java.lang.String> substitions)
Replaces a set of
searchString and replaceString pairs,
given by the substitutions Map parameter. |
static java.lang.String |
substitute(java.lang.String source,
java.lang.String searchString,
java.lang.String replaceString)
Substitutes
searchString in the given source String with replaceString . |
static java.lang.String |
substituteContextPath(java.lang.String htmlContent,
java.lang.String context)
Substitutes the OpenCms context path (e.g.
|
static java.lang.String |
substitutePerl(java.lang.String content,
java.lang.String searchString,
java.lang.String replaceItem,
java.lang.String occurences)
Substitutes searchString in content with replaceItem.
|
static java.lang.String |
toUnicodeLiteral(java.lang.String s)
Returns the java String literal for the given String.
|
static java.lang.String |
transformValues(java.lang.String oldFormat,
java.lang.String newFormat,
java.lang.String value)
This method transformes a string which matched a format with one or more place holders into another format.
|
static java.lang.String |
trimToSize(java.lang.String source,
int length)
Returns a substring of the source, which is at most length characters long.
|
static java.lang.String |
trimToSize(java.lang.String source,
int length,
int area,
java.lang.String suffix)
Returns a substring of the source, which is at most length characters long, cut
in the last
area chars in the source at a sentence ending char or whitespace. |
static java.lang.String |
trimToSize(java.lang.String source,
int length,
java.lang.String suffix)
Returns a substring of the source, which is at most length characters long.
|
static boolean |
validateRegex(java.lang.String value,
java.lang.String regex,
boolean allowEmpty)
Validates a value against a regular expression.
|
public static final java.lang.String BODY_END_REGEX
public static final java.lang.String BODY_START_REGEX
public static final java.lang.String FALSE
"false"
.public static final java.lang.String LINE_SEPARATOR
public static final java.lang.String MACRO_OPENCMS_CONTEXT
public static final java.util.regex.Pattern PATTERN_LOCALE_SUFFIX
public static final java.util.regex.Pattern PATTERN_NUMBER_SUFFIX
public static final java.util.regex.Pattern PATTERN_SLASHES
public static final java.lang.String PLACEHOLDER_END
public static final java.lang.String PLACEHOLDER_START
public static final char[] SENTENCE_ENDING_CHARS
trimToSize(String, int, int, String)
method.public static final java.lang.String TABULATOR
public static final java.lang.String TRUE
"true"
.public static java.lang.String addLeadingAndTrailingSlash(java.lang.String path)
Directly exposed for JSP EL, not through CmsJspElFunctions
.
path
- the path to which add the slashespublic static java.lang.String arrayAsString(java.lang.String[] arg, java.lang.String separator)
arg
- the array to transform to a Stringseparator
- the item separatorpublic static java.lang.String changeFileNameSuffixTo(java.lang.String filename, java.lang.String suffix)
CmsJspElFunctions
.filename
- the filename to be changedsuffix
- the new suffix of the filepublic static void checkName(java.lang.String name, java.lang.String constraints, java.lang.String key, I_CmsMessageBundle bundle) throws CmsIllegalArgumentException
a...z,A...Z,0...9
and the provided constraints
.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:
name
constraints
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)CmsIllegalArgumentException
- if the check fails (generated from the given key and bundle)public static java.lang.String collectionAsString(java.util.Collection<?> collection, java.lang.String separator)
collection
- the collection to printseparator
- the item separatorpublic static boolean comparePaths(java.lang.String path1, java.lang.String path2)
Directly exposed for JSP EL, not through CmsJspElFunctions
.
path1
- the first pathpath2
- the second pathpublic static int countChar(java.lang.String s, char c)
s
- the stringc
- the char to countpublic static <T extends java.lang.Enum<T>> java.lang.String[] enumNameToStringArray(T[] values)
T
- the type of the enumvalues
- the enum valuespublic static java.lang.String escapeHtml(java.lang.String source)
<br/>
and HTML control characters
like < > & "
with their HTML entity representation.
Directly exposed for JSP EL, not through CmsJspElFunctions
.
source
- the String to escapepublic static java.lang.String escapeJavaScript(java.lang.String source)
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
.
source
- the String to escapepublic static java.lang.String escapePattern(java.lang.String source)
This method replaces the following characters in a String:
{}[]()\$^.*+/
Directly exposed for JSP EL, not through CmsJspElFunctions
.
source
- the string to escapepublic static java.util.Map<java.lang.String,java.lang.String> extendAttribute(java.lang.String text, java.lang.String attribute, java.lang.String defValue)
Map
with 2 values: a String
with key "text"
with the new text
without the given attribute, and another String
with key "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.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 markpublic static java.lang.String extractHtmlBody(java.lang.String content)
<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
.
content
- the content to extract the body frompublic static java.lang.String extractXmlEncoding(java.lang.String content)
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 null
in case no xml head
or encoding information is contained in the input.
content
- the xml content to extract the encoding frompublic static java.lang.String formatResourceName(java.lang.String name, int maxLength)
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
.
name
- the resource name to formatmaxLength
- the maximum length of the resource name (without leading /...
)public static java.lang.String formatRuntime(long runtime)
If the runtime is greater then 24 hours, the format dd:hh:mm:ss is used.
runtime
- the time to formatpublic static java.awt.Color getColorValue(java.lang.String value, java.awt.Color defaultValue, java.lang.String key)
Color
) for the given String value.All parse errors are caught and the given default value is returned in this case.
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 errorspublic static java.lang.String getCommonPrefixPath(java.lang.String first, java.lang.String second)
Directly exposed for JSP EL, not through CmsJspElFunctions
.
first
- the first pathsecond
- the second pathpublic static java.lang.String getEthernetAddress()
A dummy ethernet address is returned, if the ip is representing the loopback address or in case of exceptions.
public static int getIntValue(java.lang.String value, int defaultValue, java.lang.String key)
All parse errors are caught and the given default value is returned in this case.
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 errorspublic static int getIntValueRounded(java.lang.String value, int defaultValue, java.lang.String key)
All parse errors are caught and the given default value is returned in this case.
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 errorspublic static java.util.Locale getLocaleForName(java.lang.String name)
null
if 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
.
name
- the name to get the locale fornull
getLocaleSuffixForName(String)
public static java.util.Locale getLocaleForText(java.lang.String text)
The result will be null
if the detection fails or the detected locale is not configured
in the 'opencms-system.xml' as available locale.
text
- the text to retrieve the locale forpublic static java.lang.String getLocaleSuffixForName(java.lang.String name)
null
if no locae suffix is found.
Uses the the PATTERN_LOCALE_SUFFIX
to 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 -> null
rabbit_en.tar.gz -> null
CmsJspElFunctions
.name
- the resource name to get the locale suffix fornull
otherwisepublic static long getLongValue(java.lang.String value, long defaultValue, java.lang.String key)
All parse errors are caught and the given default value is returned in this case.
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 errorspublic static java.util.List<java.lang.String> getPathComponents(java.lang.String path)
If the path is the root path, an empty list will be returned.
Directly exposed for JSP EL, not through CmsJspElFunctions
.
path
- the path to splitpublic static java.lang.String getRelativeSubPath(java.lang.String base, java.lang.String path)
null
is returned.
Directly exposed for JSP EL, not through CmsJspElFunctions
.
base
- the base pathpath
- the path which should be converted to a relative pathpublic static boolean isEmpty(java.lang.String value)
true
if the provided String is either null
or the empty String ""
.value
- the value to checkpublic static boolean isEmptyOrWhitespaceOnly(java.lang.String value)
true
if the provided String is either null
or contains only white spaces.
Directly exposed for JSP EL, not through CmsJspElFunctions
.
value
- the value to checkpublic static boolean isEqual(java.lang.Object value1, java.lang.Object value2)
true
if the provided Objects are either both null
or equal according to Object.equals(Object)
.value1
- the first object to comparevalue2
- the second object to comparetrue
if the provided Objects are either both null
or equal according to Object.equals(Object)
public static boolean isNotEmpty(java.lang.String value)
true
if the provided String is neither null
nor the empty String ""
.value
- the value to checkpublic static boolean isNotEmptyOrWhitespaceOnly(java.lang.String value)
true
if the provided String is neither null
nor contains only white spaces.value
- the value to checktrue
, if the provided value is null
or contains only white spaces, false
otherwisepublic static boolean isPrefixPath(java.lang.String firstPath, java.lang.String secondPath)
This method is different compared to String.startsWith(java.lang.String, int)
,
because it considers /foo/bar
to
be a prefix path of /foo/bar/baz
,
but not of /foo/bar42
.
Directly exposed for JSP EL, not through CmsJspElFunctions
.
firstPath
- the first pathsecondPath
- the second pathpublic static boolean isProperPrefixPath(java.lang.String firstPath, java.lang.String secondPath)
firstPath
- the first pathsecondPath
- the second pathpublic static boolean isValidJavaClassName(java.lang.String className)
Directly exposed for JSP EL, not through CmsJspElFunctions
.
className
- the name to checkpublic static java.lang.String joinPaths(java.util.List<java.lang.String> paths)
Consecutive slashes will be reduced to a single slash in the resulting string. For example, joinPaths("/foo/", "/bar", "baz") will return "/foo/bar/baz".
paths
- the list of pathspublic static java.lang.String joinPaths(java.lang.String... paths)
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".
paths
- the array of pathspublic static int lastIndexOf(java.lang.String source, char[] chars)
If no char is found, -1 is returned.
source
- the source to checkchars
- the chars to findpublic static int lastWhitespaceIn(java.lang.String source)
If no whitespace char is found, -1 is returned.
source
- the source to checkpublic static java.lang.String listAsString(java.util.List<?> list, java.lang.String separator)
list
- the list to writeseparator
- the item separator stringpublic static java.lang.String mapAsJson(java.util.Map<java.lang.String,java.lang.String> map)
map
- the input mappublic static <K,V> java.lang.String mapAsString(java.util.Map<K,V> map, java.lang.String sepItem, java.lang.String sepKeyval)
K
- type of map keysV
- type of map valuesmap
- the map to writesepItem
- the item separator stringsepKeyval
- the key-value pair separator stringpublic static java.lang.String padLeft(java.lang.String input, int size)
input
- the input to pad leftsize
- the size of the paddingpublic static java.lang.String padRight(java.lang.String input, int size)
input
- the input to pad rightsize
- the size of the paddingpublic static final long parseDuration(java.lang.String durationStr, long defaultValue)
durationStr
- the duration stringdefaultValue
- the default value to return in case the pattern does not matchpublic static org.antlr.stringtemplate.StringTemplateGroup readStringTemplateGroup(java.io.InputStream stream)
stream
- the stream to read frompublic static com.google.common.base.Optional<java.lang.String> replacePrefix(java.lang.String text, java.lang.String origPrefix, java.lang.String newPrefix, boolean ignoreCase)
If the input string does not start with the given prefix, Optional.absent() is returned.
text
- the text for which to replace the prefixorigPrefix
- the original prefixnewPrefix
- the replacement prefixignoreCase
- if true, upper-/lower case differences will be ignoredpublic static java.lang.String[] splitAsArray(java.lang.String source, char delimiter)
source
- the String to splitdelimiter
- the delimiter to split atpublic static java.lang.String[] splitAsArray(java.lang.String source, java.lang.String delimiter)
source
- the String to splitdelimiter
- the delimiter to split atpublic static java.util.List<java.lang.String> splitAsList(java.lang.String source, char delimiter)
source
- the String to splitdelimiter
- the delimiter to split atpublic static java.util.List<java.lang.String> splitAsList(java.lang.String source, char delimiter, boolean trim)
source
- the String to splitdelimiter
- the delimiter to split attrim
- flag to indicate if leading and trailing white spaces should be omittedpublic static java.util.List<java.lang.String> splitAsList(java.lang.String source, java.lang.String delimiter)
source
- the String to splitdelimiter
- the delimiter to split atpublic static java.util.List<java.lang.String> splitAsList(java.lang.String source, java.lang.String delimiter, boolean trim)
source
- the String to splitdelimiter
- the delimiter to split attrim
- flag to indicate if leading and trailing white spaces should be omittedpublic static java.util.Map<java.lang.String,java.lang.String> splitAsMap(java.lang.String source, java.lang.String paramDelim, java.lang.String keyValDelim)
paramDelim
delimiter,
then each substring is treat as a key-value pair delimited by keyValDelim
.source
- the string to splitparamDelim
- the string to delimit each key-value pairkeyValDelim
- the string to delimit key and valuepublic static java.lang.String substitute(java.util.regex.Pattern pattern, java.lang.String text, I_CmsRegexSubstitution sub)
I_CmsRegexSubstitution
.pattern
- the pattern to substitutetext
- the text in which the pattern should be substitutedsub
- the substitution handlerpublic static java.lang.String substitute(java.lang.String source, java.util.Map<java.lang.String,java.lang.String> substitions)
searchString
and replaceString
pairs,
given by the substitutions
Map parameter.source
- the string to scansubstitions
- the map of substitutionssubstitute(String, String, String)
public static java.lang.String substitute(java.lang.String source, java.lang.String searchString, java.lang.String replaceString)
searchString
in the given source String with replaceString
.
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)
source
- the content which is scannedsearchString
- the String which is searched in contentreplaceString
- the String which replaces searchString
public static java.lang.String substituteContextPath(java.lang.String htmlContent, java.lang.String context)
htmlContent
- the HTML to replace the context path incontext
- the context path of the serverpublic static java.lang.String substitutePerl(java.lang.String content, java.lang.String searchString, java.lang.String replaceItem, java.lang.String occurences)
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 replacedpublic static java.lang.String toUnicodeLiteral(java.lang.String s)
This is the form of the String that had to be written into source code using the unicode escape sequence for special characters.
Example: "Ä" would be transformed to "\\u00C4".
s
- a string that may contain non-ascii characterspublic static java.lang.String transformValues(java.lang.String oldFormat, java.lang.String newFormat, java.lang.String value)
PLACEHOLDER_START
and end with PLACEHOLDER_END
.oldFormat
- the original formatnewFormat
- the new formatvalue
- the value which matched the original format and which shall be transformed into the new formatpublic static java.lang.String trimToSize(java.lang.String source, int length)
This is the same as calling trimToSize(String, int, String)
with the
parameters (source, length, " ...")
.
source
- the string to trimlength
- the maximum length of the string to be returnedpublic static java.lang.String trimToSize(java.lang.String source, int length, int area, java.lang.String suffix)
area
chars in the source at a sentence ending char or whitespace.
If a char is cut, the given suffix
is appended to the result.
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 trimmedpublic static java.lang.String trimToSize(java.lang.String source, int length, java.lang.String suffix)
If a char is cut, the given suffix
is appended to the result.
This is almost the same as calling trimToSize(String, int, int, String)
with the
parameters (source, length, length*, suffix)
. If length
if larger then 100, then length* = length / 2
,
otherwise length* = length
.
source
- the string to trimlength
- the maximum length of the string to be returnedsuffix
- the suffix to append in case the String was trimmedpublic static boolean validateRegex(java.lang.String value, java.lang.String regex, boolean allowEmpty)
value
- the value to testregex
- the regular expressionallowEmpty
- if an empty value is allowedtrue
if the value satisfies the validation