|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.util.CmsStringUtil
Provides String utility functions.
Field Summary | |
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 convienient shorthand to the line separator constant. |
static java.lang.String |
MACRO_OPENCMS_CONTEXT
Context macro. |
static java.lang.String |
TABULATOR
a convienient shorthand for tabulations. |
static java.lang.String |
TRUE
Constant for "true" . |
Method Summary | |
static java.lang.String |
changeFileNameSuffixTo(java.lang.String filename,
java.lang.String suffix)
Changes the filename suffix. |
static void |
checkName(java.lang.String name,
java.lang.String contraints,
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 contraints . |
static java.lang.String |
escapeHtml(java.lang.String source)
Replaces occurences of special control characters in the given input with a HTML 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 |
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 sourrounded 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)
Formats a resource name that it is displayed with the maximum length and path information is adjusted. |
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 int |
getIntValue(java.lang.String value,
int defaultValue,
java.lang.String key)
Returns the Integer (int) value for the given String value. |
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 |
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 |
isValidJavaClassName(java.lang.String className)
Checks if the given class name is a valid Java class name. |
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 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 |
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 |
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 |
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 |
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.lang.String |
substitute(java.lang.String source,
java.util.Map 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 |
trimToSize(java.lang.String source,
int length)
Returns a substring of string 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. |
static boolean |
validateResourceName(java.lang.String name)
Checks if the provided name is a valid resource name, that is contains only valid characters. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
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.lang.String TABULATOR
public static final java.lang.String TRUE
"true"
.
Method Detail |
public static java.lang.String changeFileNameSuffixTo(java.lang.String filename, java.lang.String suffix)
filename
- the filename to be changedsuffix
- the new suffix of the file
public static void checkName(java.lang.String name, java.lang.String contraints, java.lang.String key, I_CmsMessageBundle bundle) throws CmsIllegalArgumentException
a...z,A...Z,0...9
and the provided contraints
.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
contraints
name
- the name to checkcontraints
- the additional character contraintskey
- 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 escapeHtml(java.lang.String source)
This method currrently replaces line breaks to <br/>
and special HTML chars
like < > & "
with their HTML entity representation.
source
- the String to escape
public static java.lang.String escapeJavaScript(java.lang.String source)
This method replaces line breaks, quotationmarks and \ characters.
source
- the String to escape
public static java.lang.String escapePattern(java.lang.String source)
This method replaces the following characters in a String:
{}[]()\$^.*+/
source
- the string to escape
public static java.util.Map 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 sourrounded 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 mark
public static java.lang.String extractHtmlBody(java.lang.String content)
This method should be pretty robust and work even if the input HTML does not contains a valid body tag.
content
- the content to extract the body from
public 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 from
public static java.lang.String formatResourceName(java.lang.String name, int maxLength)
Example: formatResourceName("/myfolder/subfolder/index.html", 21) returns /.../subfolder/index.html
.
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 format
public 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 errors
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 errors
public static boolean isEmpty(java.lang.String value)
true
if the provided String is either null
or the empty String ""
.
value
- the value to check
public static boolean isEmptyOrWhitespaceOnly(java.lang.String value)
true
if the provided String is either null
or contains only white spaces.
value
- the value to check
public static boolean isNotEmpty(java.lang.String value)
true
if the provided String is neither null
nor the empty String ""
.
value
- the value to check
public static boolean isNotEmptyOrWhitespaceOnly(java.lang.String value)
true
if the provided String is neither null
nor contains only white spaces.
value
- the value to check
public static boolean isValidJavaClassName(java.lang.String className)
className
- the name to check
public static java.lang.String padLeft(java.lang.String input, int size)
input
- the input to pad leftsize
- the size of the padding
public static java.lang.String padRight(java.lang.String input, int size)
input
- the input to pad rightsize
- the size of the padding
public static java.lang.String[] splitAsArray(java.lang.String source, char delimiter)
source
- the String to splitdelimiter
- the delimiter to split at
public static java.lang.String[] splitAsArray(java.lang.String source, java.lang.String delimiter)
source
- the String to splitdelimiter
- the delimiter to split at
public static java.util.List splitAsList(java.lang.String source, char delimiter)
source
- the String to splitdelimiter
- the delimiter to split at
public static java.util.List 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 whitespaces should be omitted
public static java.util.List splitAsList(java.lang.String source, java.lang.String delimiter)
source
- the String to splitdelimiter
- the delimiter to split at
public static java.util.List 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 whitespaces should be omitted
public static java.lang.String substitute(java.lang.String source, java.util.Map substitions)
searchString
and replaceString
pairs,
given by the substitutions
Map parameter.
source
- the constent which is scannedsubstitions
- the map of substitutions
substitute(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 server
public 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 occurences of searchString shall be replaced
public static java.lang.String toUnicodeLiteral(java.lang.String s)
This is the form of the String that had to be written into sourcecode using the unicode escape sequence for special characters.
Example: "Ä" would be transformed to "\\u00C4".
s
- a string that may contain non-ascii characters
public static java.lang.String trimToSize(java.lang.String source, int length)
source
- the string to trimlength
- the maximum length of the string to be returned
public 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 allowed
true
if the value satisfies the validationpublic static boolean validateResourceName(java.lang.String name)
PLEASE NOTE: This logic is NOT yet used in the current release.
name
- the resource name to check
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |