public final class XmlEscapeCharacterConverter
extends java.lang.Object
The conversion supports both converting a numeric character reference (&#nnnn; where nnnn is the code point in decimal form or &xhhhh; where hhhh is the code point in hexadecimal point) and a character entity reference (&name; where name is the case-sensitive name of the entity).
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AMPERSAND_ENTITY_NAME
The entity name for ampersand: &.
|
static java.lang.String |
APOSTROPHE_ENTITY_NAME
The entity name for apostrophe: '.
|
static java.lang.String |
GREATER_THAN_ENTITY_NAME
The entity name for greater-than symbol: >.
|
static java.lang.String |
LESS_THAN_ENTITY_NAME
The entity name for less-than symbol: <.
|
static java.lang.String |
QUOTATION_MARK_NAME
The entity name for quotation mark: ".
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escape(java.lang.String value,
int[] positions)
Converts the characters that are reserved in an XML document the given string may have into
their corresponding references (escape characters) using the character entity reference.
|
static java.lang.String |
getCharacter(java.lang.String reference)
Returns the Unicode character for the given reference (which is either a numeric character
reference or a character entity reference).
|
static java.lang.String |
getEscapeCharacter(char character)
Returns the escaped character for the given reserved character.
|
static boolean |
isReserved(char character)
Determines if the given character is one of the XML/HTML reserved characters.
|
static void |
reposition(java.lang.CharSequence query,
int[] positions)
Re-adjusts the given positions, which is based on the non-escaped version of the given
query, by making sure it is pointing at the same position within query,
which contains references (escape characters).
|
static java.lang.String |
unescape(java.lang.String value,
int[] position)
Converts the references (escape characters) the given string may have into their corresponding
Unicode characters.
|
public static final java.lang.String AMPERSAND_ENTITY_NAME
public static final java.lang.String APOSTROPHE_ENTITY_NAME
public static final java.lang.String GREATER_THAN_ENTITY_NAME
public static final java.lang.String LESS_THAN_ENTITY_NAME
public static final java.lang.String QUOTATION_MARK_NAME
public static java.lang.String escape(java.lang.String value, int[] positions)
value
- A string that may contain characters that need to be escapedpositions
- This array of length one or two can be used to adjust the position of the
cursor or a text range within the string during the conversion of the reserved characterspublic static java.lang.String getCharacter(java.lang.String reference)
reference
- The numeric character or character entity reference stripped of the leading
ampersand and trailing semi-colonnull
if the
reference is invalid or unknownpublic static java.lang.String getEscapeCharacter(char character)
character
- The reserved character to retrieve its escape character with the entity namenull
public static boolean isReserved(char character)
character
- The character to verify if it's one of the reserved characterstrue
if the given character is defined as a reserved characters;
false
otherwisepublic static void reposition(java.lang.CharSequence query, int[] positions)
The escape characters are either the character entity references or the numeric character references used in an XML document.
Important: The given query should contain the exact same amount of whitespace than the query used to calculate the given positions.
query
- The query that may contain escape characterspositions
- The position within the non-escaped version of the given query, which is
either a single element position or two positions that is used as a text rangepublic static java.lang.String unescape(java.lang.String value, int[] position)
value
- A string that may contain escape charactersposition
- This array of length one can be used to adjust the position of the cursor
within the string during the conversion of the escape characters