com.topologi.diffx.xml.esc
Class XMLEscapeWriterASCII

java.lang.Object
  extended by com.topologi.diffx.xml.esc.XMLEscapeWriterASCII
All Implemented Interfaces:
XMLEscapeWriter

public final class XMLEscapeWriterASCII
extends Object
implements XMLEscapeWriter

A utility class for escaping XML data using the UTF-8 encoding.

Version:
12 May 2005
Author:
Christophe Lauret

Constructor Summary
XMLEscapeWriterASCII(Writer writer)
          Creates a new XML escape writer using the utf-8 encoding.
 
Method Summary
 String getEncoding()
          Returns the encoding for this writer.
 void writeAttValue(char[] ch, int off, int len)
          Replaces '<', '&', '"' and '\'' as well an any character that is not part of the standard unicode range.
 void writeAttValue(String value)
          Default implementation calling the XMLEscapeWriter.writeAttValue(char[], int, int).
 void writeText(char c)
          Replace characters which are invalid in element values, by the corresponding entity in a given String.
 void writeText(char[] ch, int off, int len)
          Replace characters which are invalid in element values, by the corresponding entity.
 void writeText(String value)
          Default implementation calling the XMLEscapeWriter.writeAttValue(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.XMLEscapeWriter
getEncoding, writeAttValue, writeText, writeText
 

Constructor Detail

XMLEscapeWriterASCII

public XMLEscapeWriterASCII(Writer writer)
                     throws NullPointerException
Creates a new XML escape writer using the utf-8 encoding.

Parameters:
writer - The writer to wrap.
Throws:
NullPointerException - if the writer is null.
Method Detail

writeAttValue

public void writeAttValue(char[] ch,
                          int off,
                          int len)
                   throws IOException
Replaces '<', '&', '"' and '\'' as well an any character that is not part of the standard unicode range.
 Char ::= #x9 | #xA | #xD |
          [#x20-#xD7FF] |
          [#xE000-#xFFFD] |
          [#x10000-#x10FFFF]
 
Writes 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 '&' or '<. Quotes and apostrophes must also be escaped by "&quot;" and "&apos;" respectively.

Specified by:
writeAttValue in interface XMLEscapeWriter
Parameters:
ch - The value that needs to be attribute-escaped.
off - The start (offset) of the characters.
len - The length of characters to.
Throws:
IOException - If thrown by the underlying writer.

writeText

public void writeText(char c)
               throws IOException
Replace characters which are invalid in element values, by the corresponding entity in a given String.

these characters are:


writeAttValue

public final void writeAttValue(String value)
                         throws IOException
Default implementation calling the XMLEscapeWriter.writeAttValue(char[], int, int). Writes a well-formed attribute value.

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

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

Specified by:
writeAttValue in interface XMLEscapeWriter
Parameters:
value - The value that needs to be attribute-escaped.
Throws:
IOException - If thrown by the underlying writer.

writeText

public final void writeText(String value)
                     throws IOException
Default implementation calling the XMLEscapeWriter.writeAttValue(char[], int, int). Writes the text string so that the text value for the element remains well-formed.

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

This method should do nothing if the given value is null.

Specified by:
writeText in interface XMLEscapeWriter
Parameters:
value - The text that needs to be text-escaped.
Throws:
IOException - If thrown by the underlying writer.

writeText

public void writeText(char[] ch,
                      int off,
                      int len)
               throws IOException
Replace characters which are invalid in element values, by the corresponding entity.

This method calls XMLEscapeWriter.writeText(char) for each character. Writes a well-formed text value for the element.

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.

The text of an element must not contain '&' or '<.

Specified by:
writeText in interface XMLEscapeWriter
Parameters:
ch - The value that needs to be attribute-escaped.
off - The start (offset) of the characters.
len - The length of characters to.
Throws:
IOException - If thrown by the underlying writer.

getEncoding

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

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