Class UTF8Escaper

  • All Implemented Interfaces:
    ICharacterEscaper

    public class UTF8Escaper
    extends java.lang.Object
    implements ICharacterEscaper
    Handler for writing UTF output stream (for any form of UTF, despite the name). This code is specifically for XML 1.0 and would require changes for XML 1.1 (to handle the added legal characters, rather than throwing an exception).
    Version:
    1.0
    Author:
    Dennis M. Sosnoski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static UTF8Escaper s_instance
      Singleton instance of class.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private UTF8Escaper()
      Private constructor to prevent external creation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ICharacterEscaper getInstance()
      Get instance of escaper.
      void writeAttribute​(java.lang.String text, java.io.Writer writer)
      Write attribute value with character entity substitutions.
      void writeCData​(java.lang.String text, java.io.Writer writer)
      Write CDATA to document.
      void writeContent​(java.lang.String text, java.io.Writer writer)
      Write content value with character entity substitutions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • s_instance

        private static final UTF8Escaper s_instance
        Singleton instance of class.
    • Constructor Detail

      • UTF8Escaper

        private UTF8Escaper()
        Private constructor to prevent external creation.
    • Method Detail

      • writeAttribute

        public void writeAttribute​(java.lang.String text,
                                   java.io.Writer writer)
                            throws java.io.IOException
        Write attribute value with character entity substitutions. This assumes that attributes use the regular quote ('"') delimitor.
        Specified by:
        writeAttribute in interface ICharacterEscaper
        Parameters:
        text - attribute value text
        writer - sink for output text
        Throws:
        java.io.IOException - on error writing to document
      • writeContent

        public void writeContent​(java.lang.String text,
                                 java.io.Writer writer)
                          throws java.io.IOException
        Write content value with character entity substitutions.
        Specified by:
        writeContent in interface ICharacterEscaper
        Parameters:
        text - content value text
        writer - sink for output text
        Throws:
        java.io.IOException - on error writing to document
      • writeCData

        public void writeCData​(java.lang.String text,
                               java.io.Writer writer)
                        throws java.io.IOException
        Write CDATA to document. This writes the beginning and ending sequences for a CDATA section as well as the actual text, verifying that only characters allowed by the encoding are included in the text.
        Specified by:
        writeCData in interface ICharacterEscaper
        Parameters:
        text - content value text
        writer - sink for output text
        Throws:
        java.io.IOException - on error writing to document
      • getInstance

        public static ICharacterEscaper getInstance()
        Get instance of escaper.
        Returns:
        escaper instance