public class Text extends Object
Modifier and Type | Field and Description |
---|---|
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 '/' |
Modifier and Type | Method and Description |
---|---|
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 |
escapeIllegalJcrChars(String name)
Escapes all illegal JCR name characters of a string.
|
static String |
escapeIllegalXpathSearchChars(String s)
Escapes all illegal XPath search characters 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 occurance of 'ch'.
|
static String[] |
explode(String str,
int ch,
boolean respectEmpty)
returns an array of strings decomposed of the original string, split at
every occurance 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 occurences 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.
|
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 String md5(String data, String enc) throws UnsupportedEncodingException
data
- the data to encodeenc
- the character encoding to useUnsupportedEncodingException
public static String md5(String data)
data
- the data to encodepublic 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 useNoSuchAlgorithmException
- if the desired algorithm is not supported by
the MessageDigest class.UnsupportedEncodingException
- if the encoding is not supportedpublic static String digest(String algorithm, byte[] data) throws NoSuchAlgorithmException
algorithm
- The alogrithm for the digest. This algorithm must be
supported by the MessageDigest class.data
- the data to digest with the given algorithmNoSuchAlgorithmException
- 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 patternpublic 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 generatedpublic 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 newString
newString
- new substring to replace occurences of oldString
public static String encodeIllegalXMLCharacters(String text)
text
- text to be escapedpublic 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 pathNullPointerException
- 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 encodeNullPointerException
- 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 encodeNullPointerException
- 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 characterNullPointerException
- 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 decodeNullPointerException
- if string
is null
.ArrayIndexOutOfBoundsException
- if not enough character follow an
escape characterIllegalArgumentException
- 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:
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 *)
name
- the name to escapepublic 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 encodepublic 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 unescapepublic static String getName(String path)
path
- the pathnull
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 delimiternull
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 nameNullPointerException
- if qname
is null
getLocalName(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 nameNullPointerException
- if qname
is null
getNamespacePrefix(String)
public static boolean isSibling(String p1, String p2)
p1
- first pathp2
- second pathpublic static boolean isDescendant(String path, String descendant)
descendant
path is hierarchical a
descendant of path
.path
- the current pathdescendant
- the potential descendanttrue
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 descendanttrue
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 parentpublic 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 parentpublic 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 foundCopyright © 2004–2024 The Apache Software Foundation. All rights reserved.