public final class XmlUtils
extends java.lang.Object
Modifier and Type | Class | Description |
---|---|---|
static class |
XmlUtils.Context |
Escaping context.
|
static class |
XmlUtils.EscapingPolicy |
Modifier and Type | Method | Description |
---|---|---|
static java.lang.String |
codePointToString(int codePoint) |
|
static java.lang.String |
escape(java.lang.String s,
XmlUtils.Context context,
XmlUtils.EscapingPolicy policy) |
Returns an escaped version of a string.
|
static boolean |
isNameChar(int codePoint) |
|
static boolean |
isNameStartChar(int codePoint) |
Returns
true if a code point is valid as first character of an xml name. |
static boolean |
isValidName(java.lang.String s) |
Returns
true if a string is a valid xml name. |
static boolean |
isValidXml(java.lang.String s,
XmlVersion version) |
|
static boolean |
isValidXml10(java.lang.String s) |
Returns
true if a string is null or contains only valid XML 1.0 characters. |
static boolean |
isValidXml11(java.lang.String s) |
Returns
true if a string is null or contains only valid XML 1.1 characters. |
static boolean |
isWhiteSpace(char[] ch,
int offset,
int count) |
|
static boolean |
isWhiteSpace(int codePoint) |
Returns
true if a code point is a white space. |
static boolean |
isWhiteSpace(java.lang.String s) |
Returns
true if a string is null or contains only white spaces. |
static boolean |
isXml10Char(int codePoint) |
Returns
true if a code point is valid for XML 1.0. |
static boolean |
isXml11Char(int codePoint) |
Returns
true if a code point is valid for XML 1.1. |
static boolean |
isXmlChar(int codePoint,
XmlVersion version) |
|
static boolean |
needsEscape(java.lang.String s,
XmlUtils.Context context,
XmlUtils.EscapingPolicy policy) |
Returns
true is a string must be escaped. |
static java.lang.String |
validate(java.lang.String s,
XmlVersion version,
cdc.util.lang.FailureReaction reaction) |
|
static java.lang.String |
validate(java.lang.String s,
XmlVersion version,
cdc.util.lang.FailureReaction reaction,
int def) |
Checks that a string contains only valid characters, and replaces invalid chars.
|
public static java.lang.String codePointToString(int codePoint)
public static boolean isWhiteSpace(int codePoint)
true
if a code point is a white space.codePoint
- The code point.true
if codePoint
is a white space.public static boolean isWhiteSpace(java.lang.String s)
true
if a string is null
or contains only white spaces.s
- The string.true
if s
is null
or contains only white spaces.public static boolean isWhiteSpace(char[] ch, int offset, int count)
public static boolean isXml10Char(int codePoint)
true
if a code point is valid for XML 1.0.
Note: A valid character may need escape.
codePoint
- The code point.true
if codePoint
is a valid XML 1.0 code point.public static boolean isXml11Char(int codePoint)
true
if a code point is valid for XML 1.1.
Note: A valid character may need escape.
codePoint
- The code point.true
if codePoint
is a valid XML 1.1 code point.public static boolean isXmlChar(int codePoint, XmlVersion version)
public static boolean isValidXml10(java.lang.String s)
true
if a string is null
or contains only valid XML 1.0 characters.
Note: A valid character may need escape.
s
- The string.true
if s
is null
or contains only valid XML 1.0 characters.public static boolean isValidXml11(java.lang.String s)
true
if a string is null
or contains only valid XML 1.1 characters.
Note: A valid character may need escape.
s
- The string.true
if s
is null
or contains only valid XML 1.1 characters.public static boolean isValidXml(java.lang.String s, XmlVersion version)
public static boolean isNameStartChar(int codePoint)
true
if a code point is valid as first character of an xml name.codePoint
- The code point.true
if codePoint
is valid as first character of an xml name.public static boolean isNameChar(int codePoint)
public static boolean isValidName(java.lang.String s)
true
if a string is a valid xml name.
If must not be null or empty, its first character must be a valid start character, and other characters must be valid.
s
- The string.true
if s
is a valid xml name.public static java.lang.String validate(java.lang.String s, XmlVersion version, cdc.util.lang.FailureReaction reaction, int def)
s
- The string.version
- The Xml version.reaction
- The reaction to adopt in when an invalid character is met.def
- The default code point to use to replace invalid characters.java.lang.IllegalArgumentException
- when invalid characters are met and reaction
is FAIL.public static java.lang.String validate(java.lang.String s, XmlVersion version, cdc.util.lang.FailureReaction reaction)
public static boolean needsEscape(java.lang.String s, XmlUtils.Context context, XmlUtils.EscapingPolicy policy)
true
is a string must be escaped.
<
and &
must always be escaped.
>
does not need escape. It is escaped if required with policy.
"
needs to be escaped in attributes delimited by "
. Otherwise, is escaped if required by policy.
'
needs to be escaped in attributes delimited by '
. Otherwise, is escaped if required by policy.
\t
, \n
and \r
should be escaped in attributes. They are if escaped if required by policy.
s
- The string.context
- The context.policy
- The escaping policy.true
is s
must be escaped incontext
and using policy
.public static java.lang.String escape(java.lang.String s, XmlUtils.Context context, XmlUtils.EscapingPolicy policy)
s
- The string.context
- The context.policy
- The escaping policy.s
incontext
and using policy
.Copyright © 2019. All rights reserved.