Class XmlEscapeCharacterConverter
java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.utility.XmlEscapeCharacterConverter
This converter handles references when dealing with text or markup in an XML document. Those
references (escape characters) are defined in ISO-8859-1 Reference.
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).
- Since:
- 2.5
- Version:
- 2.5
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The entity name for ampersand: &.static final String
The entity name for apostrophe: '.static final String
The entity name for greater-than symbol: >.static final String
The entity name for less-than symbol: <.static final String
The entity name for quotation mark: ". -
Method Summary
Modifier and TypeMethodDescriptionstatic String
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 String
getCharacter
(String reference) Returns the Unicode character for the given reference (which is either a numeric character reference or a character entity reference).static 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
(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 String
Converts the references (escape characters) the given string may have into their corresponding Unicode characters.
-
Field Details
-
AMPERSAND_ENTITY_NAME
The entity name for ampersand: &.- See Also:
-
APOSTROPHE_ENTITY_NAME
The entity name for apostrophe: '.- See Also:
-
GREATER_THAN_ENTITY_NAME
The entity name for greater-than symbol: >.- See Also:
-
LESS_THAN_ENTITY_NAME
The entity name for less-than symbol: <.- See Also:
-
QUOTATION_MARK_NAME
The entity name for quotation mark: ".- See Also:
-
-
Method Details
-
escape
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.- Parameters:
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 characters- Returns:
- The given string with any reserved characters converted into the escape characters
-
getCharacter
Returns the Unicode character for the given reference (which is either a numeric character reference or a character entity reference).- Parameters:
reference
- The numeric character or character entity reference stripped of the leading ampersand and trailing semi-colon- Returns:
- The Unicode character mapped to the given reference or
null
if the reference is invalid or unknown
-
getEscapeCharacter
Returns the escaped character for the given reserved character.- Parameters:
character
- The reserved character to retrieve its escape character with the entity name- Returns:
- The escape character with the entity name of the given character if it is a reserved
character; otherwise returns
null
-
isReserved
public static boolean isReserved(char character) Determines if the given character is one of the XML/HTML reserved characters.- Parameters:
character
- The character to verify if it's one of the reserved characters- Returns:
true
if the given character is defined as a reserved characters;false
otherwise
-
reposition
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).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.
- Parameters:
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 range. After execution contains the adjusted positions by moving it based on the difference between the escape and non-escaped versions of the query- Since:
- 2.5
-
unescape
Converts the references (escape characters) the given string may have into their corresponding Unicode characters.- Character entity reference: © for ©
- Numeric character reference (decimal value): © for ©
- Numeric character reference (hexadecimal value): © for ©
- Parameters:
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- Returns:
- The given string with any escape characters converted into the actual Unicode characters
-