Class XMLEscapeWriterASCII

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

public final class XMLEscapeWriterASCII extends XMLEscapeWriterBase implements XMLEscapeWriter
A utility class for escaping XML data using the UTF-8 encoding.
Version:
12 May 2005
  • Field Details

  • Constructor Details

    • 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 Details

    • 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 '&amp' 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:

      • '&amp' by the ampersand entity "&amp"
      • '<' by the entity "&lt;"
      • Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity. Writes the character so that the text value for the element remains well-formed.

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

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

      private static void doNothing()
      Does nothing.

      This method exists so that we can explicitly say that we should do nothing in certain conditions.