|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.util.Text
public class Text
This Class provides some text related utilities
| Field Summary | |
|---|---|
static char[] |
hexTable
used for the md5 |
static BitSet |
URISave
The list of characters that are not encoded by the escape()
and unescape() METHODS. |
static BitSet |
URISaveEx
Same as URISave but also contains the '/' |
| Method Summary | |
|---|---|
static String |
digest(String algorithm,
byte[] data)
Digest the plain string using the given algorithm. |
static String |
digest(String algorithm,
String data,
String enc)
Digest the plain string using the given algorithm. |
static String |
encodeIllegalXMLCharacters(String text)
Replaces illegal XML characters in the given string by their corresponding predefined entity references. |
static String |
escape(String string)
Does a URL encoding of the string. |
static String |
escape(String string,
char escape)
Does an URL encoding of the string using the
escape character. |
static String |
escape(String string,
char escape,
boolean isPath)
Does an URL encoding of the string using the
escape character. |
static String |
escapeIllegalJcr10Chars(String name)
Escapes all illegal JCR 1.0 name characters of a string. |
static String |
escapeIllegalJcrChars(String name)
Escapes all illegal JCR name characters of a string. |
static String |
escapeIllegalXpathSearchChars(String s)
Escapes illegal XPath search characters at the end of a string. |
static String |
escapePath(String path)
Does a URL encoding of the path. |
static String[] |
explode(String str,
int ch)
returns an array of strings decomposed of the original string, split at every occurrence of 'ch'. |
static String[] |
explode(String str,
int ch,
boolean respectEmpty)
returns an array of strings decomposed of the original string, split at every occurrence of 'ch'. |
static String |
getAbsoluteParent(String path,
int level)
Returns the nth absolute parent of the path, where n=level. |
static String |
getLocalName(String qname)
Returns the local name of the given qname. |
static String |
getName(String path)
Returns the name part of the path. |
static String |
getName(String path,
boolean ignoreTrailingSlash)
Same as getName(String) but adding the possibility
to pass paths that end with a trailing '/' |
static String |
getName(String path,
char delim)
Returns the name part of the path, delimited by the given delim. |
static String |
getNamespacePrefix(String qname)
Returns the namespace prefix of the given qname. |
static String |
getRelativeParent(String path,
int level)
Returns the nth relative parent of the path, where n=level. |
static String |
getRelativeParent(String path,
int level,
boolean ignoreTrailingSlash)
Same as getRelativeParent(String, int) but adding the possibility
to pass paths that end with a trailing '/' |
static String |
implode(String[] arr,
String delim)
Concatenates all strings in the string array using the specified delimiter. |
static boolean |
isDescendant(String path,
String descendant)
Determines if the descendant path is hierarchical a
descendant of path. |
static boolean |
isDescendantOrEqual(String path,
String descendant)
Determines if the descendant path is hierarchical a
descendant of path or equal to it. |
static boolean |
isSibling(String p1,
String p2)
Determines, if two paths denote hierarchical siblins. |
static String |
md5(String data)
Calculate an MD5 hash of the string given using 'utf-8' encoding. |
static String |
md5(String data,
String enc)
Calculate an MD5 hash of the string given. |
static String |
replace(String text,
String oldString,
String newString)
Replaces all occurrences of oldString in text
with newString. |
static String |
replaceVariables(Properties variables,
String value,
boolean ignoreMissing)
Performs variable replacement on the given string value. |
static String |
unescape(String string)
Does a URL decoding of the string. |
static String |
unescape(String string,
char escape)
Does a URL decoding of the string using the
escape character. |
static String |
unescapeIllegalJcrChars(String name)
Unescapes previously escaped jcr chars. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final char[] hexTable
public static BitSet URISave
escape()
and unescape() METHODS. They contains the characters as
defined 'unreserved' in section 2.3 of the RFC 2396 'URI generic syntax':
unreserved = alphanum | mark
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
public static BitSet URISaveEx
URISave but also contains the '/'
| Method Detail |
|---|
public static String md5(String data,
String enc)
throws UnsupportedEncodingException
data - the data to encodeenc - the character encoding to use
UnsupportedEncodingExceptionpublic static String md5(String data)
data - the data to encode
public static String digest(String algorithm,
String data,
String enc)
throws NoSuchAlgorithmException,
UnsupportedEncodingException
algorithm - The alogrithm for the digest. This algorithm must be
supported by the MessageDigest class.data - The plain text String to be digested.enc - The character encoding to use
NoSuchAlgorithmException - if the desired algorithm is not supported by
the MessageDigest class.
UnsupportedEncodingException - if the encoding is not supported
public static String digest(String algorithm,
byte[] data)
throws NoSuchAlgorithmException
algorithm - The algorithm for the digest. This algorithm must be
supported by the MessageDigest class.data - the data to digest with the given algorithm
NoSuchAlgorithmException - if the desired algorithm is not supported by
the MessageDigest class.
public static String[] explode(String str,
int ch)
str - the string to decomposech - the character to use a split pattern
public static String[] explode(String str,
int ch,
boolean respectEmpty)
str - the string to decomposech - the character to use a split patternrespectEmpty - if true, empty elements are generated
public static String implode(String[] arr,
String delim)
arr - delim -
public static String replace(String text,
String oldString,
String newString)
oldString in text
with newString.
text - oldString - old substring to be replaced with newStringnewString - new substring to replace occurrences of oldString
public static String encodeIllegalXMLCharacters(String text)
text - text to be escaped
public static String escape(String string,
char escape)
string using the
escape character. The characters that don't need encoding
are those defined 'unreserved' in section 2.3 of the 'URI generic syntax'
RFC 2396, but without the escape character.
string - the string to encode.escape - the escape character.
NullPointerException - if string is null.
public static String escape(String string,
char escape,
boolean isPath)
string using the
escape character. The characters that don't need encoding
are those defined 'unreserved' in section 2.3 of the 'URI generic syntax'
RFC 2396, but without the escape character. If isPath is
true, additionally the slash '/' is ignored, too.
string - the string to encode.escape - the escape character.isPath - if true, the string is treated as path
NullPointerException - if string is null.public static String escape(String string)
string. The characters that
don't need encoding are those defined 'unreserved' in section 2.3 of
the 'URI generic syntax' RFC 2396.
string - the string to encode
NullPointerException - if string is null.public static String escapePath(String path)
path. The characters that
don't need encoding are those defined 'unreserved' in section 2.3 of
the 'URI generic syntax' RFC 2396. In contrast to the
escape(String) method, not the entire path string is escaped,
but every individual part (i.e. the slashes are not escaped).
path - the path to encode
NullPointerException - if path is null.
public static String unescape(String string,
char escape)
string using the
escape character. Please note that in opposite to the
URLDecoder it does not transform the + into spaces.
string - the string to decodeescape - the escape character
NullPointerException - if string is null.
IllegalArgumentException - if the 2 characters following the escape
character do not represent a hex-number
or if not enough characters follow an
escape characterpublic static String unescape(String string)
string. Please note that in
opposite to the URLDecoder it does not transform the +
into spaces.
string - the string to decode
NullPointerException - if string is null.
ArrayIndexOutOfBoundsException - if not enough character follow an
escape character
IllegalArgumentException - if the 2 characters following the escape
character do not represent a hex-number.public static String escapeIllegalJcrChars(String name)
unescapeIllegalJcrChars(String) for decoding.
QName EBNF:
name - the name to escape
public static String escapeIllegalJcr10Chars(String name)
unescapeIllegalJcrChars(String) for decoding.
QName EBNF:
name - the name to escape
public static String escapeIllegalXpathSearchChars(String s)
Example:
A search string like 'test?' will run into a ParseException
documented in http://issues.apache.org/jira/browse/JCR-1248
s - the string to encode
public static String unescapeIllegalJcrChars(String name)
Please note, that this does not exactly the same as the url related
unescape(String), since it handles the byte-encoding
differently.
name - the name to unescape
public static String getName(String path)
path - the path
null if path is null.
public static String getName(String path,
char delim)
delim.
If the given path is already a name (i.e. contains no delim
characters) it is returned.
path - the pathdelim - the delimiter
null if path is null.
public static String getName(String path,
boolean ignoreTrailingSlash)
getName(String) but adding the possibility
to pass paths that end with a trailing '/'
getName(String)public static String getNamespacePrefix(String qname)
qname. If the
prefix is missing, an empty string is returned. Please note, that this
method does not validate the name or prefix.
the qname has the format: qname := [prefix ':'] local;
qname - a qualified name
NullPointerException - if qname is nullgetLocalName(String)public static String getLocalName(String qname)
qname. Please note, that
this method does not validate the name.
the qname has the format: qname := [prefix ':'] local;
qname - a qualified name
NullPointerException - if qname is nullgetNamespacePrefix(String)
public static boolean isSibling(String p1,
String p2)
p1 - first pathp2 - second path
public static boolean isDescendant(String path,
String descendant)
descendant path is hierarchical a
descendant of path.
path - the current pathdescendant - the potential descendant
true if the descendant is a descendant;
false otherwise.
public static boolean isDescendantOrEqual(String path,
String descendant)
descendant path is hierarchical a
descendant of path or equal to it.
path - the path to checkdescendant - the potential descendant
true if the descendant is a descendant
or equal; false otherwise.
public static String getRelativeParent(String path,
int level)
Example:
Text.getRelativeParent("/foo/bar/test", 1) == "/foo/bar"
path - the path of the pagelevel - the level of the parent
public static String getRelativeParent(String path,
int level,
boolean ignoreTrailingSlash)
getRelativeParent(String, int) but adding the possibility
to pass paths that end with a trailing '/'
getRelativeParent(String, int)
public static String getAbsoluteParent(String path,
int level)
Example:
Text.getAbsoluteParent("/foo/bar/test", 1) == "/foo/bar"
path - the path of the pagelevel - the level of the parent
public static String replaceVariables(Properties variables,
String value,
boolean ignoreMissing)
throws IllegalArgumentException
${...} sequence within the given value is replaced
with the value of the named parser variable. If a variable is not found
in the properties an IllegalArgumentException is thrown unless
ignoreMissing is true. In the later case, the
missing variable is replaced by the empty string.
value - the original valueignoreMissing - if true, missing variables are replaced
by the empty string.
IllegalArgumentException - if the replacement of a referenced
variable is not found
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||