Package org.apache.jackrabbit.util
Class Text
java.lang.Object
org.apache.jackrabbit.util.Text
This Class provides some text related utilities
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringDigest the plain string using the given algorithm.static StringDigest the plain string using the given algorithm.static StringReplaces HTML characters in the given string that might need escaping as HTML text or attributestatic StringReplaces XML characters in the given string that might need escaping as XML text or attributestatic StringDoes a URL encoding of thestring.static StringDoes an URL encoding of thestringusing theescapecharacter.static StringDoes an URL encoding of thestringusing theescapecharacter.static StringEscapes all illegal JCR 1.0 name characters of a string.static StringescapeIllegalJcrChars(String name) Escapes all illegal JCR name characters of a string.static StringEscapes illegal XPath search characters at the end of a string.static StringescapePath(String path) Does a URL encoding of thepath.static String[]returns an array of strings decomposed of the original string, split at every occurrence of 'ch'.static String[]returns an array of strings decomposed of the original string, split at every occurrence of 'ch'.static StringgetAbsoluteParent(String path, int level) Returns the nth absolute parent of the path, where n=level.static StringgetLocalName(String qname) Returns the local name of the givenqname.static StringReturns the name part of the path.static StringSame asgetName(String)but adding the possibility to pass paths that end with a trailing '/'static StringReturns the name part of the path, delimited by the givendelim.static StringgetNamespacePrefix(String qname) Returns the namespace prefix of the givenqname.static StringgetRelativeParent(String path, int level) Returns the nth relative parent of the path, where n=level.static StringgetRelativeParent(String path, int level, boolean ignoreTrailingSlash) Same asgetRelativeParent(String, int)but adding the possibility to pass paths that end with a trailing '/'static StringConcatenates all strings in the string array using the specified delimiter.static booleanisDescendant(String path, String descendant) Determines if thedescendantpath is hierarchical a descendant ofpath.static booleanisDescendantOrEqual(String path, String descendant) Determines if thedescendantpath is hierarchical a descendant ofpathor equal to it.static booleanDetermines, if two paths denote hierarchical siblins.static StringCalculate an MD5 hash of the string given using 'utf-8' encoding.static StringCalculate an MD5 hash of the string given.static StringReplaces all occurrences ofoldStringintextwithnewString.static StringreplaceVariables(Properties variables, String value, boolean ignoreMissing) Performs variable replacement on the given string value.static StringDoes a URL decoding of thestring.static StringDoes a URL decoding of thestringusing theescapecharacter.static StringUnescapes previously escaped jcr chars.
-
Field Details
-
hexTable
public static final char[] hexTableused for the md5 -
URISave
The list of characters that are not encoded by theescape()andunescape()METHODS. They contains the characters as defined 'unreserved' in section 2.3 of the RFC 2396 'URI generic syntax':unreserved = alphanum | mark mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" -
URISaveEx
Same asURISavebut also contains the '/'
-
-
Method Details
-
md5
Calculate an MD5 hash of the string given.- Parameters:
data- the data to encodeenc- the character encoding to use- Returns:
- a hex encoded string of the md5 digested input
- Throws:
UnsupportedEncodingException
-
md5
Calculate an MD5 hash of the string given using 'utf-8' encoding.- Parameters:
data- the data to encode- Returns:
- a hex encoded string of the md5 digested input
-
digest
public static String digest(String algorithm, String data, String enc) throws NoSuchAlgorithmException, UnsupportedEncodingException Digest the plain string using the given algorithm.- Parameters:
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- Returns:
- The digested plain text String represented as Hex digits.
- Throws:
NoSuchAlgorithmException- if the desired algorithm is not supported by the MessageDigest class.UnsupportedEncodingException- if the encoding is not supported
-
digest
Digest the plain string using the given algorithm.- Parameters:
algorithm- The algorithm for the digest. This algorithm must be supported by the MessageDigest class.data- the data to digest with the given algorithm- Returns:
- The digested plain text String represented as Hex digits.
- Throws:
NoSuchAlgorithmException- if the desired algorithm is not supported by the MessageDigest class.
-
explode
returns an array of strings decomposed of the original string, split at every occurrence of 'ch'. if 2 'ch' follow each other with no intermediate characters, empty "" entries are avoided.- Parameters:
str- the string to decomposech- the character to use a split pattern- Returns:
- an array of strings
-
explode
returns an array of strings decomposed of the original string, split at every occurrence of 'ch'.- Parameters:
str- the string to decomposech- the character to use a split patternrespectEmpty- iftrue, empty elements are generated- Returns:
- an array of strings
-
implode
Concatenates all strings in the string array using the specified delimiter.- Parameters:
arr-delim-- Returns:
- the concatenated string
-
replace
Replaces all occurrences ofoldStringintextwithnewString.- Parameters:
text-oldString- old substring to be replaced withnewStringnewString- new substring to replace occurrences ofoldString- Returns:
- a string
-
encodeIllegalXMLCharacters
Replaces XML characters in the given string that might need escaping as XML text or attribute- Parameters:
text- text to be escaped- Returns:
- a string
-
encodeIllegalHTMLCharacters
Replaces HTML characters in the given string that might need escaping as HTML text or attribute- Parameters:
text- text to be escaped- Returns:
- a string
-
escape
Does an URL encoding of thestringusing theescapecharacter. 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.- Parameters:
string- the string to encode.escape- the escape character.- Returns:
- the escaped string
- Throws:
NullPointerException- ifstringisnull.
-
escape
Does an URL encoding of thestringusing theescapecharacter. 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. IfisPathistrue, additionally the slash '/' is ignored, too.- Parameters:
string- the string to encode.escape- the escape character.isPath- iftrue, the string is treated as path- Returns:
- the escaped string
- Throws:
NullPointerException- ifstringisnull.
-
escape
Does a URL encoding of thestring. The characters that don't need encoding are those defined 'unreserved' in section 2.3 of the 'URI generic syntax' RFC 2396.- Parameters:
string- the string to encode- Returns:
- the escaped string
- Throws:
NullPointerException- ifstringisnull.
-
escapePath
Does a URL encoding of thepath. 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 theescape(String)method, not the entire path string is escaped, but every individual part (i.e. the slashes are not escaped).- Parameters:
path- the path to encode- Returns:
- the escaped path
- Throws:
NullPointerException- ifpathisnull.
-
unescape
Does a URL decoding of thestringusing theescapecharacter. Please note that in opposite to theURLDecoderit does not transform the + into spaces.- Parameters:
string- the string to decodeescape- the escape character- Returns:
- the decoded string
- Throws:
NullPointerException- ifstringisnull.IllegalArgumentException- if the 2 characters following the escape character do not represent a hex-number or if not enough characters follow an escape character
-
unescape
Does a URL decoding of thestring. Please note that in opposite to theURLDecoderit does not transform the + into spaces.- Parameters:
string- the string to decode- Returns:
- the decoded string
- Throws:
NullPointerException- ifstringisnull.ArrayIndexOutOfBoundsException- if not enough character follow an escape characterIllegalArgumentException- if the 2 characters following the escape character do not represent a hex-number.
-
escapeIllegalJcrChars
Escapes all illegal JCR name characters of a string. The encoding is loosely modeled after URI encoding, but only encodes the characters it absolutely needs to in order to make the resulting string a valid JCR name. UseunescapeIllegalJcrChars(String)for decoding.QName EBNF:
simplename ::= onecharsimplename | twocharsimplename | threeormorecharname onecharsimplename ::= (* Any Unicode character except: '.', '/', ':', '[', ']', '*', '|' or any whitespace character *) twocharsimplename ::= '.' onecharsimplename | onecharsimplename '.' | onecharsimplename onecharsimplename threeormorecharname ::= nonspace string nonspace string ::= char | string char char ::= nonspace | ' ' nonspace ::= (* Any Unicode character except: '/', ':', '[', ']', '*', '|' or any whitespace character *)
- Parameters:
name- the name to escape- Returns:
- the escaped name
-
escapeIllegalJcr10Chars
Escapes all illegal JCR 1.0 name characters of a string. UseunescapeIllegalJcrChars(String)for decoding.QName EBNF:
simplename ::= onecharsimplename | twocharsimplename | threeormorecharname onecharsimplename ::= (* Any Unicode character except: '.', '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *) twocharsimplename ::= '.' onecharsimplename | onecharsimplename '.' | onecharsimplename onecharsimplename threeormorecharname ::= nonspace string nonspace string ::= char | string char char ::= nonspace | ' ' nonspace ::= (* Any Unicode character except: '/', ':', '[', ']', '*', ''', '"', '|' or any whitespace character *)
- Parameters:
name- the name to escape- Returns:
- the escaped name
- Since:
- Apache Jackrabbit 2.3.2 and 2.2.10
- See Also:
-
escapeIllegalXpathSearchChars
Escapes illegal XPath search characters at the end of a string.Example:
A search string like 'test?' will run into a ParseException documented in http://issues.apache.org/jira/browse/JCR-1248- Parameters:
s- the string to encode- Returns:
- the escaped string
-
unescapeIllegalJcrChars
Unescapes previously escaped jcr chars.Please note, that this does not exactly the same as the url related
unescape(String), since it handles the byte-encoding differently.- Parameters:
name- the name to unescape- Returns:
- the unescaped name
-
getName
Returns the name part of the path. If the given path is already a name (i.e. contains no slashes) it is returned.- Parameters:
path- the path- Returns:
- the name part or
nullifpathisnull.
-
getName
Returns the name part of the path, delimited by the givendelim. If the given path is already a name (i.e. contains nodelimcharacters) it is returned.- Parameters:
path- the pathdelim- the delimiter- Returns:
- the name part or
nullifpathisnull.
-
getName
Same asgetName(String)but adding the possibility to pass paths that end with a trailing '/'- See Also:
-
getNamespacePrefix
Returns the namespace prefix of the givenqname. 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;
- Parameters:
qname- a qualified name- Returns:
- the prefix of the name or "".
- Throws:
NullPointerException- ifqnameisnull- See Also:
-
getLocalName
Returns the local name of the givenqname. Please note, that this method does not validate the name.The qname has the format: qname := [prefix ':'] local;
- Parameters:
qname- a qualified name- Returns:
- the localname
- Throws:
NullPointerException- ifqnameisnull- See Also:
-
isSibling
Determines, if two paths denote hierarchical siblins.- Parameters:
p1- first pathp2- second path- Returns:
- true if on same level, false otherwise
-
isDescendant
Determines if thedescendantpath is hierarchical a descendant ofpath.- Parameters:
path- the current pathdescendant- the potential descendant- Returns:
trueif thedescendantis a descendant;falseotherwise.
-
isDescendantOrEqual
Determines if thedescendantpath is hierarchical a descendant ofpathor equal to it.- Parameters:
path- the path to checkdescendant- the potential descendant- Returns:
trueif thedescendantis a descendant or equal;falseotherwise.
-
getRelativeParent
Returns the nth relative parent of the path, where n=level.Example:
Text.getRelativeParent("/foo/bar/test", 1) == "/foo/bar"- Parameters:
path- the path of the pagelevel- the level of the parent
-
getRelativeParent
Same asgetRelativeParent(String, int)but adding the possibility to pass paths that end with a trailing '/'- See Also:
-
getAbsoluteParent
Returns the nth absolute parent of the path, where n=level.Example:
Text.getAbsoluteParent("/foo/bar/test", 1) == "/foo/bar"- Parameters:
path- the path of the pagelevel- the level of the parent
-
replaceVariables
public static String replaceVariables(Properties variables, String value, boolean ignoreMissing) throws IllegalArgumentException Performs variable replacement on the given string value. Each${...}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 unlessignoreMissingistrue. In the later case, the missing variable is replaced by the empty string.- Parameters:
value- the original valueignoreMissing- iftrue, missing variables are replaced by the empty string.- Returns:
- value after variable replacements
- Throws:
IllegalArgumentException- if the replacement of a referenced variable is not found
-