com.topologi.diffx.xml.esc
Class XMLEscapeASCII

java.lang.Object
  extended by com.topologi.diffx.xml.esc.XMLEscapeASCII
All Implemented Interfaces:
XMLEscape

public final class XMLEscapeASCII
extends Object
implements XMLEscape

A singleton for escaping XML data when using the 'ASCII' encoding.

Any character that isn't part of the ASCI range is going to be replaced by a character entity.

Version:
0.7.7
Author:
Christophe Lauret

Field Summary
static XMLEscape ASCII_ESCAPE
          A static instance of the UTF8 escape class.
 
Method Summary
 String getEncoding()
          Returns the encoding used.
 String toAttributeValue(char[] ch, int off, int len)
          Returns a well-formed attribute value.
 String toAttributeValue(String value)
          Default implementation calling the XMLEscape.toAttributeValue(char[], int, int).
 String toElementText(char[] ch, int off, int len)
          Writes a well-formed XML literal text value.
 String toElementText(String value)
          Default implementation calling the XMLEscape.toAttributeValue(char[], int, int).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topologi.diffx.xml.esc.XMLEscape
getEncoding, toAttributeValue, toElementText
 

Field Detail

ASCII_ESCAPE

public static final XMLEscape ASCII_ESCAPE
A static instance of the UTF8 escape class.

Method Detail

toAttributeValue

public String toAttributeValue(char[] ch,
                               int off,
                               int len)
Description copied from interface: XMLEscape
Returns a well-formed attribute value.

This method must replace any character in the specified value by the corresponding numeric character reference or the predefined XML general entities, if the character is not allowed or not in the encoding range.

Attribute values must not contain any ampersand (#x26) or less than (#x3C) characters. This method will replace them by the corresponding named entity.

Quotes and apostrophes must also be escaped depending on what was used in the attribute markup. Since this method is not aware of which type of quotes was used, both are escaped. Double quotes (#x22) are escaped using a named character entity. In case the end result is HTML 4, single quotes (#x27) are escaped using a numeric character entity.

Characters in ranges (#x00-#x1F) and (#x80-#x9F) are silently ignored except for line feed (#x0A), carriage return (#x0D) and tab (#x09).

Specified by:
toAttributeValue in interface XMLEscape
Parameters:
ch - The value that needs to be attribute-escaped.
off - The start (offset) of the characters.
len - The length of characters to.
Returns:
A well-formed value for the attribute.
See Also:
Extensible Markup Language (XML) 1.0 - 2.3 Common Syntactic Constructs

toElementText

public String toElementText(char[] ch,
                            int off,
                            int len)
Description copied from interface: XMLEscape
Writes a well-formed XML literal text value.

This method must replace any character in the specified text by the corresponding numeric character reference or the predefined XML general entities, if the character is not allowed or not in the encoding range.

Literal text values must not contain any 'ampersand' (#x26) or 'less than' (#x3C) characters. This method will replace them by the corresponding named entity.

Out of precaution this method may also encode the 'greater than' (#xCE) character, in case it follows "]]".

Characters in ranges (#x00-#x1F) and (#x80-#x9F) are silently ignored except for line feed (#x0A), carriage return (#x0D) and tab (#x09).

Specified by:
toElementText in interface XMLEscape
Parameters:
ch - The value that needs to be attribute-escaped.
off - The start (offset) of the characters.
len - The length of characters to.
Returns:
A well-formed value for the text node.
See Also:
Extensible Markup Language (XML) 1.0 - 2.4 Character Data and Markup

toAttributeValue

public final String toAttributeValue(String value)
Default implementation calling the XMLEscape.toAttributeValue(char[], int, int). Returns a well-formed attribute value.

Method provided for convenience, using the same specifications as XMLEscape.toAttributeValue(char[], int, int).

This method should return null if the given value is null.

Specified by:
toAttributeValue in interface XMLEscape
Parameters:
value - The value that needs to be attribute-escaped.
Returns:
A well-formed value for the attribute.

toElementText

public final String toElementText(String value)
Default implementation calling the XMLEscape.toAttributeValue(char[], int, int). Returns a well-formed text value for the element.

Method provided for convenience, using the same specifications as XMLEscape.toElementText(char[], int, int).

This method should return null if the given value is null.

Specified by:
toElementText in interface XMLEscape
Parameters:
value - The value that needs to be text-escaped.
Returns:
A well-formed value for the text node.

getEncoding

public final String getEncoding()
Returns the encoding used. Returns the encoding used by the implementing class.

Specified by:
getEncoding in interface XMLEscape
Returns:
The encoding used by the implementing class.