Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.tools.utility

public final Class XmlEscapeCharacterConverter

extends Object
Class Inheritance
Annotations
@SuppressWarnings:nls
Imports
java.util.HashMap, .Map

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).

Author
Pascal Filion
Since
2.5
Version
2.5

Field Summary

Modifier and TypeField and Description
public static final String
AMPERSAND_ENTITY_NAME

The entity name for ampersand: &.

public static final String
APOSTROPHE_ENTITY_NAME

The entity name for apostrophe: '.

private static final Map<String, String>
dictionary

The map of symbol mapped to the unicode character.

public static final String
GREATER_THAN_ENTITY_NAME

The entity name for greater-than symbol: >.

public static final String
LESS_THAN_ENTITY_NAME

The entity name for less-than symbol: <.

public static final String
QUOTATION_MARK_NAME

The entity name for quotation mark: ".

Constructor Summary

AccessConstructor and Description
private
XmlEscapeCharacterConverter()

Cannot instantiate XmlEscapeCharacterConverter.

Method Summary

Modifier and TypeMethod and Description
private static Map<String, String>
public static String

Returns:

The given string with any reserved characters converted into the escape characters
escape
(String
A string that may contain characters that need to be escaped
value
,
int[]
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
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.

public static String

Returns:

The Unicode character mapped to the given reference or null if the reference is invalid or unknown
getCharacter
(String
The numeric character or character entity reference stripped of the leading ampersand and trailing semi-colon
reference
)

Returns the Unicode character for the given reference (which is either a numeric character reference or a character entity reference).

public static String

Returns:

The escape character with the entity name of the given character if it is a reserved character; otherwise returns null
getEscapeCharacter
(char
The reserved character to retrieve its escape character with the entity name
character
)

Returns the escaped character for the given reserved character.

public static boolean

Returns:

true if the given character is defined as a reserved characters; false otherwise
isReserved
(char
The character to verify if it's one of the reserved characters
character
)

Determines if the given character is one of the XML/HTML reserved characters.

public static void
reposition(CharSequence
The query that may contain escape characters
query
,
int[]
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
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).

public static String

Returns:

The given string with any escape characters converted into the actual Unicode characters
unescape
(String
A string that may contain escape characters
value
,
int[]
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
position
)

Converts the references (escape characters) the given string may have into their corresponding Unicode characters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AMPERSAND_ENTITY_NAMEback to summary
public static final String AMPERSAND_ENTITY_NAME

The entity name for ampersand: &.

APOSTROPHE_ENTITY_NAMEback to summary
public static final String APOSTROPHE_ENTITY_NAME

The entity name for apostrophe: &apos;.

dictionaryback to summary
private static final Map<String, String> dictionary

The map of symbol mapped to the unicode character.

GREATER_THAN_ENTITY_NAMEback to summary
public static final String GREATER_THAN_ENTITY_NAME

The entity name for greater-than symbol: >.

LESS_THAN_ENTITY_NAMEback to summary
public static final String LESS_THAN_ENTITY_NAME

The entity name for less-than symbol: <.

QUOTATION_MARK_NAMEback to summary
public static final String QUOTATION_MARK_NAME

The entity name for quotation mark: ".

Constructor Detail

XmlEscapeCharacterConverterback to summary
private XmlEscapeCharacterConverter()

Cannot instantiate XmlEscapeCharacterConverter.

Method Detail

buildDictionaryback to summary
private static Map<String, String> buildDictionary()
escapeback to summary
public static String escape(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.

Parameters
value:String

A string that may contain characters that need to be escaped

positions:int[]

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:String

The given string with any reserved characters converted into the escape characters

getCharacterback to summary
public 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).

Parameters
reference:String

The numeric character or character entity reference stripped of the leading ampersand and trailing semi-colon

Returns:String

The Unicode character mapped to the given reference or null if the reference is invalid or unknown

getEscapeCharacterback to summary
public static String getEscapeCharacter(char character)

Returns the escaped character for the given reserved character.

Parameters
character:char

The reserved character to retrieve its escape character with the entity name

Returns:String

The escape character with the entity name of the given character if it is a reserved character; otherwise returns null

isReservedback to summary
public static boolean isReserved(char character)

Determines if the given character is one of the XML/HTML reserved characters.

Parameters
character:char

The character to verify if it's one of the reserved characters

Returns:boolean

true if the given character is defined as a reserved characters; false otherwise

repositionback to summary
public 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).

The escape characters are either the character entity references or the numeric character references used in an XML document.

Important Note

The given query should contain the exact same amount of whitespace than the query used to calculate the given positions.

Parameters
query:CharSequence

The query that may contain escape characters

positions:int[]

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
unescapeback to summary
public static String unescape(String value, int[] position)

Converts the references (escape characters) the given string may have into their corresponding Unicode characters.

  • Character entity reference: &copy; for ©
  • Numeric character reference (decimal value): &#169; for ©
  • Numeric character reference (hexadecimal value): &#xA9; for ©
Parameters
value:String

A string that may contain escape characters

position:int[]

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:String

The given string with any escape characters converted into the actual Unicode characters