public final class XMLText extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
checkId(String s)
Equivalent to
checkId(s, false, '_'). |
static String |
checkId(String s,
boolean keepStartNCNameChar,
char replacementChar)
Converts specified string to a valid, though not always unique, ID.
|
static boolean |
checkText(String text)
Returns
false if specified text contains non-XML
characters. |
static String |
collapseWhiteSpace(String value)
Replaces successive XML space characters by a single space character
(
' ') then removes leading and trailing space characters
if any. |
static String |
compressWhiteSpace(String value)
Replaces successive XML space characters
(
'\t', '\r',
'\n', ' ') by a single space character
(' '). |
static void |
escapeXML(char[] chars,
int offset,
int length,
StringBuilder escaped)
Escapes specified character array
(that is,
'<' is replaced
by "<", '&' is replaced
by "&", etc). |
static void |
escapeXML(char[] chars,
int offset,
int length,
StringBuilder escaped,
int maxCode)
Escapes specified character array
(that is,
'<' is replaced
by "<", '&' is replaced by
"&", etc). |
static String |
escapeXML(String string)
Escapes specified string (that is,
'<' is replaced by "<",
'&' is replaced by "&", etc). |
static void |
escapeXML(String string,
StringBuilder escaped)
Escapes specified string (that is,
'<' is replaced by "<",
'&' is replaced by "&", etc). |
static String |
filterText(String text)
Returns a copy of specified text after removing all non-XML characters
(if any).
|
static boolean |
isName(String s)
Tests if specified string is a lexically correct Name.
|
static boolean |
isNameChar(char c)
Tests if specified character can used in an Name at a position other
the first one.
|
static boolean |
isNameOtherChar(char c)
Tests if specified character, even if not authorized as the first
character of an Name, can be one of the other characters of an
Name.
|
static boolean |
isNameStartChar(char c)
Tests if specified character can used as the start of an Name.
|
static boolean |
isNCName(String s)
Tests if specified string is a lexically correct NCName.
|
static boolean |
isNCNameChar(char c)
Tests if specified character can used in an NCName at a position other
the first one.
|
static boolean |
isNCNameOtherChar(char c)
Tests if specified character, even if not authorized as the first
character of an NCName, can be one of the other characters of an
NCName.
|
static boolean |
isNCNameStartChar(char c)
Tests if specified character can used as the start of an NCName.
|
static boolean |
isNmtoken(String s)
Tests if specified string is a lexically correct NMTOKEN.
|
static boolean |
isPITarget(String s)
Tests if specified string is a lexically correct target for a process
instruction.
|
static boolean |
isXMLChar(char c)
Tests if specified character is a character which can be contained in a
XML document.
|
static boolean |
isXMLSpace(char c)
Tests if specified character is a XML space (
'\t',
'\r', '\n', ' '). |
static boolean |
isXMLSpace(CharSequence chars)
Tests whether specified character sequence only contains XML space
(
'\t', '\r', '\n',
' '). |
static String |
quoteXML(String string)
Escapes specified string (that is,
'<' is replaced by
"<", '&' is replaced by
"&", etc) then puts the escaped string between
quotes ("). |
static void |
quoteXML(String string,
StringBuilder quoted)
Escapes specified string (that is,
'<' is replaced by "<",
'&' is replaced by "&", etc)
then puts the escaped string between quotes ("). |
static String |
replaceWhiteSpace(String value)
Replaces sequence "
\r\n" and characters '\t',
'\r', '\n' by a single
space character ' '. |
static String[] |
splitList(String s)
Splits specified string at XML whitespace character boundaries
(
'\t', '\r', '\n',
' '). |
static String |
unescapeXML(String text)
Unescapes specified string.
|
static void |
unescapeXML(String text,
int offset,
int length,
StringBuilder unescaped)
Unescapes specified string.
|
public static boolean isXMLSpace(char c)
'\t',
'\r', '\n', ' ').c - character to be testedtrue if test is successful; false
otherwisepublic static boolean isXMLSpace(CharSequence chars)
'\t', '\r', '\n',
' ').chars - character sequence to be testedtrue if chars is empty or
only contains XML space; false otherwisepublic static boolean isXMLChar(char c)
c - character to be testedtrue if test is successful; false
otherwisepublic static boolean checkText(String text)
false if specified text contains non-XML
characters. Otherwise, return true.public static String filterText(String text)
text - text to be filteredpublic static boolean isNCNameStartChar(char c)
Corresponds to: Letter | '_'.
isNCNameOtherChar(char),
isNCNameChar(char)public static boolean isNCNameOtherChar(char c)
Corresponds to:
Digit | '.' | '-' | CombiningChar | Extender.
isNCNameStartChar(char),
isNCNameChar(char)public static boolean isNCNameChar(char c)
Corresponds to:
Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender.
isNCNameStartChar(char),
isNCNameOtherChar(char)public static boolean isNCName(String s)
s - string to be testedtrue if test is successful; false
otherwisepublic static boolean isNameStartChar(char c)
Corresponds to: Letter | '_' | ':'.
isNameOtherChar(char),
isNameChar(char)public static boolean isNameOtherChar(char c)
Corresponds to:
Digit | '.' | '-' | ':' | CombiningChar | Extender.
isNameStartChar(char),
isNameChar(char)public static boolean isNameChar(char c)
Corresponds to:
Letter|Digit | '.' | '-' | '_' | ':' |
CombiningChar|Extender.
isNameStartChar(char),
isNameOtherChar(char)public static boolean isName(String s)
s - string to be testedtrue if test is successful; false
otherwisepublic static boolean isNmtoken(String s)
s - string to be testedtrue if test is successful; false
otherwisepublic static boolean isPITarget(String s)
Note that Names starting with "xml"
(case-insensitive) are rejected.
s - string to be testedtrue if test is successful; false
otherwisepublic static String checkId(String s)
checkId(s, false, '_').public static String checkId(String s, boolean keepStartNCNameChar, char replacementChar)
_" for an empty or null string.s - string to be checked as an NCName.keepStartNCNameChar - if true and first char is an NCName, keep it
and prepend replacementChar to before it.replacementChar - character used to replace invalid ones.
Must be a letter or '_'.replacementChar as a string for an empty or
null string.public static String collapseWhiteSpace(String value)
' ') then removes leading and trailing space characters
if any.value - string to be processedpublic static String compressWhiteSpace(String value)
'\t', '\r',
'\n', ' ') by a single space character
(' ').value - string to be processedpublic static String replaceWhiteSpace(String value)
\r\n" and characters '\t',
'\r', '\n' by a single
space character ' '.value - string to be processedpublic static String[] splitList(String s)
'\t', '\r', '\n',
' ').
Returns list of parts.s - string to be splitpublic static String quoteXML(String string)
'<' is replaced by
"<", '&' is replaced by
"&", etc) then puts the escaped string between
quotes (").string - string to be escaped and quotedpublic static void quoteXML(String string, StringBuilder quoted)
'<' is replaced by "<",
'&' is replaced by "&", etc)
then puts the escaped string between quotes (").string - string to be escaped and quotedquoted - buffer used to store escaped and quoted string
(characters are appended to this buffer)public static String escapeXML(String string)
'<' is replaced by "<",
'&' is replaced by "&", etc).string - string to be escapedpublic static void escapeXML(String string, StringBuilder escaped)
'<' is replaced by "<",
'&' is replaced by "&", etc).string - string to be escapedescaped - buffer used to store escaped string (characters are
appended to this buffer)public static void escapeXML(char[] chars,
int offset,
int length,
StringBuilder escaped)
'<' is replaced
by "<", '&' is replaced
by "&", etc).chars - character array to be escapedoffset - specifies first character in array to be escapedlength - number of characters in array to be escapedescaped - buffer used to store escaped string (characters are
appended to this buffer)public static void escapeXML(char[] chars,
int offset,
int length,
StringBuilder escaped,
int maxCode)
'<' is replaced
by "<", '&' is replaced by
"&", etc).chars - character array to be escapedoffset - specifies first character in array to be escapedlength - number of characters in array to be escapedescaped - buffer used to store escaped string (characters are
appended to this buffer)maxCode - characters with code > maxCode are escaped as
&#code;.
Pass 127 for US-ASCII, 255 for ISO-8859-1, otherwise pass
Integer.MAX_VALUE.public static String unescapeXML(String text)
escapeXML(java.lang.String).text - string to be unescapedpublic static void unescapeXML(String text, int offset, int length, StringBuilder unescaped)
escapeXML(java.lang.String).text - string to be unescapedoffset - specifies first character in string to be unescapedlength - number of characters in string to be unescapedunescaped - buffer used to store unescaped string (characters are
appended to this buffer)