com.alkacon.geranium.client.util
public final class ClientStringUtil extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
escapeHtml(java.lang.String source)
Replaces occurrences of special control characters in the given input with
a HTML representation.
|
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 |
getMessage(java.lang.Throwable t)
Returns the exception message.
|
static java.lang.String |
getStackTrace(java.lang.Throwable t,
java.lang.String separator)
Returns the stack trace of the Throwable as a string.
|
static java.lang.String |
getStackTraceAsString(java.lang.StackTraceElement[] trace,
java.lang.String separator)
Returns the stack trace as a string.
|
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 |
isPrefixPath(java.lang.String firstPath,
java.lang.String secondPath)
Checks whether one path is a prefix path of another, i.e. its path components are
the initial path components of the second path.
|
static java.lang.String |
joinPaths(java.lang.String... paths)
Concatenates multiple paths and separates them with '/'.
|
static <E> java.lang.String |
listAsString(java.util.List<E> list,
java.lang.String separator)
Returns a string representation for the given list using the given separator.
|
static double |
parseFloat(java.lang.String str)
The parseFloat() function parses a string and returns a float.
|
static int |
parseInt(java.lang.String str)
The parseInt() function parses a string and returns an integer.
|
static void |
pushArray(com.google.gwt.core.client.JavaScriptObject array,
java.lang.String s)
Pushes a String into a javascript array.
|
static java.lang.String |
shortenString(java.lang.String text,
int maxLength)
Shortens the string to the given maximum length.
|
static java.lang.String[] |
splitAsArray(java.lang.String str,
java.lang.String splitter)
Splits a String into substrings along the provided char delimiter and returns
the result as an Array 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.lang.String source,
java.lang.String searchString,
java.lang.String replaceString)
Substitutes
searchString in the given source String with replaceString. |
public static java.lang.String getMessage(java.lang.Throwable t)
t - the exception to get the message forpublic static java.lang.String getStackTrace(java.lang.Throwable t,
java.lang.String separator)
t - the Throwable for which the stack trace should be returnedseparator - the separator between the lines of the stack tracepublic static java.lang.String getStackTraceAsString(java.lang.StackTraceElement[] trace,
java.lang.String separator)
trace - the stack traceseparator - the separator between the lines of the stack tracepublic static double parseFloat(java.lang.String str)
Only the first number in the string is returned. Leading and trailing spaces are allowed.
str - the string to be parsedpublic static int parseInt(java.lang.String str)
Only the first number in the string is returned. Leading and trailing spaces are allowed. If the first character cannot be converted to a number, parseInt() returns zero.
str - the string to be parsedpublic static void pushArray(com.google.gwt.core.client.JavaScriptObject array,
java.lang.String s)
array - the array to push the String intos - the String to push into the arraypublic static java.lang.String shortenString(java.lang.String text,
int maxLength)
Will include HTML entity ellipses replacing the cut off text.
text - the string to shortenmaxLength - the maximum lengthpublic static java.lang.String escapeHtml(java.lang.String source)
This method currently replaces line breaks to <br/> and special HTML chars
like < > & " with their HTML entity representation.
source - the String to escapepublic 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 searchStringpublic static java.lang.String formatResourceName(java.lang.String name,
int maxLength)
In order to reduce the length of the displayed names, single folder names are removed/replaced with ... successively, starting with the second! folder. The first folder is removed as last.
Example: formatResourceName("/myfolder/subfolder/index.html", 21) returns /myfolder/.../index.html.
name - the resource name to formatmaxLength - the maximum length of the resource name (without leading /...)public 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.value - the value to checkpublic 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 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".
paths - the array of pathspublic static <E> java.lang.String listAsString(java.util.List<E> list,
java.lang.String separator)
E - type of list entrieslist - the list to writeseparator - the item separator stringpublic static java.lang.String[] splitAsArray(java.lang.String str,
java.lang.String splitter)
str - the String to splitsplitter - 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 boolean isPrefixPath(java.lang.String firstPath,
java.lang.String secondPath)
It is not enough to just use String.startsWith(java.lang.String, int), because we want /foo/bar to
be a prefix path of /foo/bar/baz, but not of /foo/bar42.
firstPath - the first pathsecondPath - the second pathpublic 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 value