|
|||||||||||
| 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 String |
BODY_END_REGEX
Regular expression that matches the HTML body end tag. |
static String |
BODY_START_REGEX
Regular expression that matches the HTML body start tag. |
static String |
LINE_SEPARATOR
a convienient shorthand to the line separator constant. |
static String |
MACRO_OPENCMS_CONTEXT
Context macro. |
static String |
TABULATOR
a convienient shorthand for tabulations. |
| Method Summary | |
static String |
changeFileNameSuffixTo(String filename,
String suffix)
Changes the filename suffix. |
static String |
escapeHtml(String source)
Replaces occurences of special control characters in the given input with a HTML representation. |
static String |
escapeJavaScript(String source)
Escapes a String so it may be used in JavaScript String definitions. |
static String |
escapePattern(String source)
Escapes a String so it may be used as a Perl5 regular expression. |
static Map |
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 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 String |
extractHtmlBody(String content)
Extracts the content of a <body> tag in a HTML page. |
static String |
extractXmlEncoding(String content)
Extracts the xml encoding setting from an xml file that is contained in a String by parsing the xml head. |
static String |
formatRuntime(long runtime)
Formats a runtime in the format hh:mm:ss, to be used e.g. |
static boolean |
isEmpty(String value)
Returns true if the provided String is either null
or the empty String "". |
static boolean |
isEmptyOrWhitespaceOnly(String value)
Returns true if the provided String is either null
or contains only white spaces. |
static boolean |
isNotEmpty(String value)
Returns true if the provided String is neither null
nor the empty String "". |
static boolean |
isNotEmptyOrWhitespaceOnly(String value)
Returns true if the provided String is neither null
nor contains only white spaces. |
static boolean |
isValidJavaClassName(String className)
Checks if the given class name is a valid Java class name. |
static String |
padLeft(String input,
int size)
Applies white space padding to the left of the given String. |
static String |
padRight(String input,
int size)
Applies white space padding to the right of the given String. |
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. |
static List |
splitAsList(String source,
char delimiter)
Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings. |
static List |
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. |
static List |
splitAsList(String source,
String delimiter)
Splits a String into substrings along the provided String delimiter and returns the result as List of Substrings. |
static List |
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. |
static String |
substitute(String content,
String searchString,
String replaceItem)
Substitutes searchString in content with replaceItem. |
static String |
substituteContextPath(String htmlContent,
String context)
Substitutes the OpenCms context path (e.g. |
static String |
substitutePerl(String content,
String searchString,
String replaceItem,
String occurences)
Substitutes searchString in content with replaceItem. |
static boolean |
validateRegex(String value,
String regex,
boolean allowEmpty)
Validates a value against a regular expression. |
static boolean |
validateResourceName(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 String BODY_END_REGEX
public static final String BODY_START_REGEX
public static final String LINE_SEPARATOR
public static final String TABULATOR
public static final String MACRO_OPENCMS_CONTEXT
| Method Detail |
public static String changeFileNameSuffixTo(String filename,
String suffix)
filename - the filename to be changedsuffix - the new suffix of the file
public static String escapeHtml(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 String escapeJavaScript(String source)
This method replaces line breaks, quotationmarks and \ characters.
source - the String to escape
public static String escapePattern(String source)
This method replaces the following characters in a String:
{}[]()\$^.*+/
source - the string to escape
public static Map extendAttribute(String text,
String attribute,
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 String extractHtmlBody(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 String extractXmlEncoding(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 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 boolean isEmpty(String value)
true if the provided String is either null
or the empty String "".
value - the value to check
public static boolean isEmptyOrWhitespaceOnly(String value)
true if the provided String is either null
or contains only white spaces.
value - the value to check
public static boolean isNotEmpty(String value)
true if the provided String is neither null
nor the empty String "".
value - the value to check
public static boolean isNotEmptyOrWhitespaceOnly(String value)
true if the provided String is neither null
nor contains only white spaces.
value - the value to check
public static boolean isValidJavaClassName(String className)
className - the name to check
public static String padLeft(String input,
int size)
input - the input to pad leftsize - the size of the padding
public static String padRight(String input,
int size)
input - the input to pad rightsize - the size of the padding
public static String[] splitAsArray(String source,
char delimiter)
source - the String to splitdelimiter - the delimiter to split at
public static String[] splitAsArray(String source,
String delimiter)
source - the String to splitdelimiter - the delimiter to split at
public static List splitAsList(String source,
char delimiter)
source - the String to splitdelimiter - the delimiter to split at
public static List splitAsList(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 List splitAsList(String source,
String delimiter)
source - the String to splitdelimiter - the delimiter to split at
public static List splitAsList(String source,
String delimiter,
boolean trim)
source - source the String to splitdelimiter - the delimiter to split attrim - flag to indicate if leading and trailing whitespaces should be omitted
public static String substitute(String content,
String searchString,
String replaceItem)
content - the content which is scannedsearchString - the String which is searched in contentreplaceItem - the new String which replaces searchString
public static String substituteContextPath(String htmlContent,
String context)
htmlContent - the HTML to replace the context path incontext - the context path of the server
public static String substitutePerl(String content,
String searchString,
String replaceItem,
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 boolean validateRegex(String value,
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(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 | ||||||||||