public class Text
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char[] |
hexTable
used for the md5
|
static java.util.BitSet |
URISave
The list of characters that are not encoded by the
escape()
and unescape() METHODS. |
static java.util.BitSet |
URISaveEx
Same as
URISave but also contains the '/' |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
digest(java.lang.String algorithm,
byte[] data)
Digest the plain string using the given algorithm.
|
static java.lang.String |
digest(java.lang.String algorithm,
java.lang.String data,
java.lang.String enc)
Digest the plain string using the given algorithm.
|
static java.lang.String |
encodeIllegalHTMLCharacters(java.lang.String text)
Replaces HTML characters in the given string that might need escaping
as HTML text or attribute
|
static java.lang.String |
encodeIllegalXMLCharacters(java.lang.String text)
Replaces XML characters in the given string that might need escaping
as XML text or attribute
|
static java.lang.String |
escape(java.lang.String string)
Does a URL encoding of the
string . |
static java.lang.String |
escape(java.lang.String string,
char escape)
Does an URL encoding of the
string using the
escape character. |
static java.lang.String |
escape(java.lang.String string,
char escape,
boolean isPath)
Does an URL encoding of the
string using the
escape character. |
static java.lang.String |
escapeIllegalJcr10Chars(java.lang.String name)
Escapes all illegal JCR 1.0 name characters of a string.
|
static java.lang.String |
escapeIllegalJcrChars(java.lang.String name)
Escapes all illegal JCR name characters of a string.
|
static java.lang.String |
escapeIllegalXpathSearchChars(java.lang.String s)
Escapes illegal XPath search characters at the end of a string.
|
static java.lang.String |
escapePath(java.lang.String path)
Does a URL encoding of the
path . |
static java.lang.String[] |
explode(java.lang.String str,
int ch)
returns an array of strings decomposed of the original string, split at
every occurrence of 'ch'.
|
static java.lang.String[] |
explode(java.lang.String str,
int ch,
boolean respectEmpty)
returns an array of strings decomposed of the original string, split at
every occurrence of 'ch'.
|
static java.lang.String |
getAbsoluteParent(java.lang.String path,
int level)
Returns the nth absolute parent of the path, where n=level.
|
static java.lang.String |
getLocalName(java.lang.String qname)
Returns the local name of the given
qname . |
static java.lang.String |
getName(java.lang.String path)
Returns the name part of the path.
|
static java.lang.String |
getName(java.lang.String path,
boolean ignoreTrailingSlash)
Same as
getName(String) but adding the possibility
to pass paths that end with a trailing '/' |
static java.lang.String |
getName(java.lang.String path,
char delim)
Returns the name part of the path, delimited by the given
delim . |
static java.lang.String |
getNamespacePrefix(java.lang.String qname)
Returns the namespace prefix of the given
qname . |
static java.lang.String |
getRelativeParent(java.lang.String path,
int level)
Returns the nth relative parent of the path, where n=level.
|
static java.lang.String |
getRelativeParent(java.lang.String path,
int level,
boolean ignoreTrailingSlash)
Same as
getRelativeParent(String, int) but adding the possibility
to pass paths that end with a trailing '/' |
static java.lang.String |
implode(java.lang.String[] arr,
java.lang.String delim)
Concatenates all strings in the string array using the specified delimiter.
|
static boolean |
isDescendant(java.lang.String path,
java.lang.String descendant)
Determines if the
descendant path is hierarchical a
descendant of path . |
static boolean |
isDescendantOrEqual(java.lang.String path,
java.lang.String descendant)
Determines if the
descendant path is hierarchical a
descendant of path or equal to it. |
static boolean |
isSibling(java.lang.String p1,
java.lang.String p2)
Determines, if two paths denote hierarchical siblins.
|
static java.lang.String |
md5(java.lang.String data)
Calculate an MD5 hash of the string given using 'utf-8' encoding.
|
static java.lang.String |
md5(java.lang.String data,
java.lang.String enc)
Calculate an MD5 hash of the string given.
|
static java.lang.String |
replace(java.lang.String text,
java.lang.String oldString,
java.lang.String newString)
Replaces all occurrences of
oldString in text
with newString . |
static java.lang.String |
replaceVariables(java.util.Properties variables,
java.lang.String value,
boolean ignoreMissing)
Performs variable replacement on the given string value.
|
static java.lang.String |
unescape(java.lang.String string)
Does a URL decoding of the
string . |
static java.lang.String |
unescape(java.lang.String string,
char escape)
Does a URL decoding of the
string using the
escape character. |
static java.lang.String |
unescapeIllegalJcrChars(java.lang.String name)
Unescapes previously escaped jcr chars.
|
public static final char[] hexTable
public static java.util.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 java.util.BitSet URISaveEx
URISave
but also contains the '/'public static java.lang.String md5(java.lang.String data, java.lang.String enc) throws java.io.UnsupportedEncodingException
data
- the data to encodeenc
- the character encoding to usejava.io.UnsupportedEncodingException
public static java.lang.String md5(java.lang.String data)
data
- the data to encodepublic static java.lang.String digest(java.lang.String algorithm, java.lang.String data, java.lang.String enc) throws java.security.NoSuchAlgorithmException, java.io.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 usejava.security.NoSuchAlgorithmException
- if the desired algorithm is not supported by
the MessageDigest class.java.io.UnsupportedEncodingException
- if the encoding is not supportedpublic static java.lang.String digest(java.lang.String algorithm, byte[] data) throws java.security.NoSuchAlgorithmException
algorithm
- The algorithm for the digest. This algorithm must be
supported by the MessageDigest class.data
- the data to digest with the given algorithmjava.security.NoSuchAlgorithmException
- if the desired algorithm is not supported by
the MessageDigest class.public static java.lang.String[] explode(java.lang.String str, int ch)
str
- the string to decomposech
- the character to use a split patternpublic static java.lang.String[] explode(java.lang.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 java.lang.String implode(java.lang.String[] arr, java.lang.String delim)
arr
- delim
- public static java.lang.String replace(java.lang.String text, java.lang.String oldString, java.lang.String newString)
oldString
in text
with newString
.text
- oldString
- old substring to be replaced with newString
newString
- new substring to replace occurrences of oldString
public static java.lang.String encodeIllegalXMLCharacters(java.lang.String text)
text
- text to be escapedpublic static java.lang.String encodeIllegalHTMLCharacters(java.lang.String text)
text
- text to be escapedpublic static java.lang.String escape(java.lang.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.java.lang.NullPointerException
- if string
is null
.public static java.lang.String escape(java.lang.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 pathjava.lang.NullPointerException
- if string
is null
.public static java.lang.String escape(java.lang.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 encodejava.lang.NullPointerException
- if string
is null
.public static java.lang.String escapePath(java.lang.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 encodejava.lang.NullPointerException
- if path
is null
.public static java.lang.String unescape(java.lang.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 characterjava.lang.NullPointerException
- if string
is null
.java.lang.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 java.lang.String unescape(java.lang.String string)
string
. Please note that in
opposite to the URLDecoder
it does not transform the +
into spaces.string
- the string to decodejava.lang.NullPointerException
- if string
is null
.java.lang.ArrayIndexOutOfBoundsException
- if not enough character follow an
escape characterjava.lang.IllegalArgumentException
- if the 2 characters following the escape
character do not represent a hex-number.public static java.lang.String escapeIllegalJcrChars(java.lang.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 java.lang.String escapeIllegalJcr10Chars(java.lang.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 java.lang.String escapeIllegalXpathSearchChars(java.lang.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 java.lang.String unescapeIllegalJcrChars(java.lang.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 java.lang.String getName(java.lang.String path)
path
- the pathnull
if path
is null
.public static java.lang.String getName(java.lang.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 java.lang.String getName(java.lang.String path, boolean ignoreTrailingSlash)
getName(String)
but adding the possibility
to pass paths that end with a trailing '/'getName(String)
public static java.lang.String getNamespacePrefix(java.lang.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 namejava.lang.NullPointerException
- if qname
is null
getLocalName(String)
public static java.lang.String getLocalName(java.lang.String qname)
qname
. Please note, that
this method does not validate the name.
The qname has the format: qname := [prefix ':'] local;
qname
- a qualified namejava.lang.NullPointerException
- if qname
is null
getNamespacePrefix(String)
public static boolean isSibling(java.lang.String p1, java.lang.String p2)
p1
- first pathp2
- second pathpublic static boolean isDescendant(java.lang.String path, java.lang.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(java.lang.String path, java.lang.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 java.lang.String getRelativeParent(java.lang.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 java.lang.String getRelativeParent(java.lang.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 java.lang.String getAbsoluteParent(java.lang.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 java.lang.String replaceVariables(java.util.Properties variables, java.lang.String value, boolean ignoreMissing) throws java.lang.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.java.lang.IllegalArgumentException
- if the replacement of a referenced
variable is not foundCopyright © 2010 - 2020 Adobe. All Rights Reserved