|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.wicket.util.string.Strings
public final class Strings
A variety of static String utility methods.
The escapeMarkup() and toMultilineMarkup() methods are useful for turning normal Java Strings into HTML strings.
The lastPathComponent(), firstPathComponent(), afterFirstPathComponent() and beforeLastPathComponent() methods can chop up a String into path components using a separator character. If the separator cannot be found the original String is returned.
Similarly, the beforeLast(), beforeFirst(), afterFirst() and afterLast() methods return sections before and after a separator character. But if the separator cannot be found, an empty string is returned.
Some other miscellaneous methods will strip a given ending off a String if it can be found (stripEnding()), replace all occurrences of one String with another (replaceAll), do type conversions (toBoolean(), toChar(), toString()), check a String for emptiness (isEmpty()), convert a Throwable to a String (toString(Throwable)) or capitalize a String (capitalize()).
Field Summary | |
---|---|
static java.lang.String |
LINE_SEPARATOR
The line separator for the current platform. |
Method Summary | |
---|---|
static java.lang.String |
afterFirst(java.lang.String s,
char c)
Returns everything after the first occurrence of the given character in s. |
static java.lang.String |
afterFirstPathComponent(java.lang.String path,
char separator)
Gets everything after the first path component of a path using a given separator. |
static java.lang.String |
afterLast(java.lang.String s,
char c)
Returns everything after the last occurrence of the given character in s. |
static java.lang.String |
beforeFirst(java.lang.String s,
char c)
Returns everything before the first occurrence of the given character in s. |
static java.lang.String |
beforeLast(java.lang.String s,
char c)
Returns everything before the last occurrence of the given character in s. |
static java.lang.String |
beforeLastPathComponent(java.lang.String path,
char separator)
Gets everything before the last path component of a path using a given separator. |
static java.lang.String |
capitalize(java.lang.String s)
Capitalizes a string. |
static java.lang.CharSequence |
escapeMarkup(java.lang.String s)
Converts a Java String to an HTML markup string, but does not convert normal spaces to non-breaking space entities (<nbsp>). |
static java.lang.CharSequence |
escapeMarkup(java.lang.String s,
boolean escapeSpaces)
Converts a Java String to an HTML markup String by replacing illegal characters with HTML entities where appropriate. |
static java.lang.CharSequence |
escapeMarkup(java.lang.String s,
boolean escapeSpaces,
boolean convertToHtmlUnicodeEscapes)
Converts a Java String to an HTML markup String by replacing illegal characters with HTML entities where appropriate. |
static java.lang.String |
firstPathComponent(java.lang.String path,
char separator)
Gets the first path component of a path using a given separator. |
static java.lang.String |
fromEscapedUnicode(java.lang.String escapedUnicodeString)
Converts encoded \uxxxx to unicode chars and changes special saved chars to their original forms. |
static boolean |
isEmpty(java.lang.CharSequence string)
Checks whether the string is considered empty. |
static boolean |
isEqual(java.lang.String string1,
java.lang.String string2)
Checks whether two strings are equals taken care of 'null' values and treating 'null' same as trim(string).equals("") |
static boolean |
isTrue(java.lang.String s)
Converts the text in s to a corresponding boolean. |
static java.lang.String |
join(java.lang.String separator,
java.lang.String[] fragments)
Joins string fragments using the specified separator |
static java.lang.String |
lastPathComponent(java.lang.String path,
char separator)
Gets the last path component of a path using a given separator. |
static int |
lengthInBytes(java.lang.String string,
java.nio.charset.Charset charset)
Calculates the length of string in bytes, uses specified charset if provided. |
static java.lang.CharSequence |
replaceAll(java.lang.CharSequence s,
java.lang.CharSequence searchFor,
java.lang.CharSequence replaceWith)
Replace all occurrences of one string replaceWith another string. |
static java.lang.String |
replaceHtmlEscapeNumber(java.lang.String str)
Replace HTML numbers like 值 by the appropriate character. |
static java.lang.String[] |
split(java.lang.String s,
char c)
Simpler, faster version of String.split() for splitting on a simple character. |
static java.lang.String |
stripEnding(java.lang.String s,
java.lang.String ending)
Strips the ending from the string s . |
static java.lang.String |
stripJSessionId(java.lang.CharSequence url)
Strip any jsessionid and possibly other redundant info that might be in our way. |
static java.lang.Boolean |
toBoolean(java.lang.String s)
Converts the string s to a Boolean. |
static char |
toChar(java.lang.String s)
Converts the 1 character string s to a character. |
static java.lang.String |
toEscapedUnicode(java.lang.String unicodeString)
Converts unicodes to encoded \uxxxx. |
static java.lang.CharSequence |
toMultilineMarkup(java.lang.CharSequence s)
Converts a String to multiline HTML markup by replacing newlines with line break entities (<br/>) and multiple occurrences of newline with paragraph break entities (<p>). |
static java.lang.String |
toString(Component component,
java.lang.Throwable location)
Creates a location stacktrace string representation for the component for reference when the render check fails. |
static java.lang.String |
toString(java.lang.Object object)
Converts the given object to a string. |
static java.lang.String |
toString(java.lang.Throwable throwable)
Converts a Throwable to a string. |
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 LINE_SEPARATOR
Method Detail |
---|
public static java.lang.String afterFirst(java.lang.String s, char c)
s
- The stringc
- The character
public static java.lang.String afterFirstPathComponent(java.lang.String path, char separator)
For example, afterFirstPathComponent("foo.bar.baz", '.') would return "bar.baz" and afterFirstPathComponent("foo", '.') would return "".
path
- The path to parseseparator
- The path separator character
public static java.lang.String afterLast(java.lang.String s, char c)
s
- The stringc
- The character
public static java.lang.String beforeFirst(java.lang.String s, char c)
s
- The stringc
- The character
public static java.lang.String beforeLast(java.lang.String s, char c)
s
- The stringc
- The character
public static java.lang.String beforeLastPathComponent(java.lang.String path, char separator)
For example, beforeLastPathComponent("foo.bar.baz", '.') would return "foo.bar" and beforeLastPathComponent("foo", '.') would return "".
path
- The path to parseseparator
- The path separator character
public static java.lang.String capitalize(java.lang.String s)
s
- The string
public static java.lang.CharSequence escapeMarkup(java.lang.String s)
s
- The string to escape
escapeMarkup(String, boolean)
public static java.lang.CharSequence escapeMarkup(java.lang.String s, boolean escapeSpaces)
s
- The string to escapeescapeSpaces
- True to replace ' ' with nonbreaking space
public static java.lang.CharSequence escapeMarkup(java.lang.String s, boolean escapeSpaces, boolean convertToHtmlUnicodeEscapes)
s
- The string to escapeescapeSpaces
- True to replace ' ' with nonbreaking spaceconvertToHtmlUnicodeEscapes
- True to convert non-7 bit characters to unicode HTML (...)
public static java.lang.String firstPathComponent(java.lang.String path, char separator)
For example, firstPathComponent("foo.bar", '.') would return "foo" and firstPathComponent("foo", '.') would return "foo".
path
- The path to parseseparator
- The path separator character
public static java.lang.String fromEscapedUnicode(java.lang.String escapedUnicodeString)
escapedUnicodeString
- escaped unicode string, like '你好'.
public static boolean isEmpty(java.lang.CharSequence string)
string
is considered empty. Empty means that the string may
contain whitespace, but no visible characters.
"\n\t " is considered empty, while " a" is not.
string
- The string
public static boolean isEqual(java.lang.String string1, java.lang.String string2)
string1
- string2
-
public static boolean isTrue(java.lang.String s) throws StringValueConversionException
s
to a corresponding boolean. On, yes, y, true and 1 are
converted to true
. Off, no, n, false and 0 (zero) are converted to
false
. An empty string is converted to false
. Conversion is
case-insensitive, and does not take internationalization into account.
'Ja', 'Oui', 'Igen', 'Nein', 'Nee', 'Non', 'Nem' are all illegal values.
s
- the value to convert into a boolean
s
StringValueConversionException
- when the value of s
is not recognized.public static java.lang.String join(java.lang.String separator, java.lang.String[] fragments)
separator
- fragments
-
public static java.lang.String lastPathComponent(java.lang.String path, char separator)
For example, lastPathComponent("foo.bar", '.') would return "bar" and lastPathComponent("foo", '.') would return "foo".
path
- The path to parseseparator
- The path separator character
public static java.lang.CharSequence replaceAll(java.lang.CharSequence s, java.lang.CharSequence searchFor, java.lang.CharSequence replaceWith)
s
- The string to processsearchFor
- The value to search forreplaceWith
- The value to searchFor replaceWith
public static java.lang.String replaceHtmlEscapeNumber(java.lang.String str)
str
- The text to be evaluated
public static java.lang.String[] split(java.lang.String s, char c)
s
- The string to splitc
- The character to split on
public static java.lang.String stripEnding(java.lang.String s, java.lang.String ending)
s
.
s
- The string to stripending
- The ending to strip off
public static java.lang.String stripJSessionId(java.lang.CharSequence url)
url
- The url to strip
public static java.lang.Boolean toBoolean(java.lang.String s) throws StringValueConversionException
isTrue
for valid values of s.
s
- The string to convert.
TRUE
when isTrue(s)
.
StringValueConversionException
- when s is not a valid valueisTrue(String)
public static char toChar(java.lang.String s) throws StringValueConversionException
s
- The 1 character string to convert to a char.
StringValueConversionException
- when the string is longer or shorter than 1 character, or null
.public static java.lang.String toEscapedUnicode(java.lang.String unicodeString)
unicodeString
- The unicode string
public static java.lang.CharSequence toMultilineMarkup(java.lang.CharSequence s)
s
- String to transform
public static java.lang.String toString(java.lang.Object object)
throwables
and String arrays of length 1 (in which case it just returns to string in that
array, as this is a common thing to have in the Servlet API).
object
- The object
public static java.lang.String toString(Component component, java.lang.Throwable location)
location
is used as a verb in the rendered string. Use
"added", "constructed" or similar verbs as values.
component
- the component that was constructed or added and failed to renderlocation
- the location where the component was created or added in the java code.
public static java.lang.String toString(java.lang.Throwable throwable)
throwable
- The throwable
public static int lengthInBytes(java.lang.String string, java.nio.charset.Charset charset)
charset
if provided.
string
- charset
- (optional) character set to use when converting string to bytes
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |