Class ToHTMLStream

All Implemented Interfaces:
DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, SerializationHandler, Serializer, ContentHandler, DTDHandler, ErrorHandler, DeclHandler, LexicalHandler

public class ToHTMLStream extends ToStream
This serializer takes a series of SAX or SAX-like events and writes its output to the given stream. This class is not a public API, it is public because it is used from another package.
  • Field Details

  • Constructor Details

    • ToHTMLStream

      public ToHTMLStream()
      Default constructor.
  • Method Details

    • setSpecialEscapeURLs

      public void setSpecialEscapeURLs(boolean bool)
      Tells if the formatter should use special URL escaping.
      Parameters:
      bool - True if URLs should be specially escaped with the %xx form.
    • setOmitMetaTag

      public void setOmitMetaTag(boolean bool)
      Tells if the formatter should omit the META tag.
      Parameters:
      bool - True if the META tag should be omitted.
    • setOutputFormat

      public void setOutputFormat(Properties format)
      Specifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document. This method can be called multiple times before starting the serialization of a particular result-tree. In principle all serialization parameters can be changed, with the exception of method="html" (it must be method="html" otherwise we shouldn't even have a ToHTMLStream object here!)
      Specified by:
      setOutputFormat in interface Serializer
      Overrides:
      setOutputFormat in class ToStream
      Parameters:
      format - The output format or serialzation parameters to use.
    • getElemDesc

      public static final ElemDesc getElemDesc(String name)
      Get a description of the given element.
      Parameters:
      name - non-null name of element, case insensitive.
      Returns:
      non-null reference to ElemDesc, which may be m_dummy if no element description matches the given name.
    • endDocument

      public final void endDocument() throws SAXException
      Receive notification of the end of a document.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      SAXException
    • startElement

      public void startElement(String namespaceURI, String localName, String name, Attributes atts) throws SAXException
      Receive notification of the beginning of an element.
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class ToStream
      Parameters:
      namespaceURI -
      localName -
      name - The element type name.
      atts - The attributes attached to the element, if any.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • endElement

      public final void endElement(String namespaceURI, String localName, String name) throws SAXException
      Receive notification of the end of an element.
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class ToStream
      Parameters:
      namespaceURI -
      localName -
      name - The element type name
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
    • writeAttrURI

      public void writeAttrURI(Writer writer, String string, boolean doURLEscaping) throws IOException
      Write the specified string after substituting non ASCII characters, with %HH, where HH is the hex of the byte value.
      Parameters:
      string - String to convert to XML format.
      doURLEscaping - True if we should try to encode as per http://www.ietf.org/rfc/rfc2396.txt.
      Throws:
      SAXException - if a bad surrogate pair is detected.
      IOException
    • writeAttrString

      public void writeAttrString(Writer writer, String string, String encoding) throws IOException
      Writes the specified string after substituting specials, and UTF-16 surrogates for character references &#xnn.
      Overrides:
      writeAttrString in class ToStream
      Parameters:
      string - String to convert to XML format.
      encoding - CURRENTLY NOT IMPLEMENTED.
      Throws:
      SAXException
      IOException
    • characters

      public final void characters(char[] chars, int start, int length) throws SAXException
      Receive notification of character data.

      The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

      The application must not attempt to read from the array outside of the specified range.

      Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class ToStream
      Parameters:
      chars - The characters from the XML document.
      start - The start position in the array.
      length - The number of characters to read from the array.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      SAXException
      See Also:
    • cdata

      public final void cdata(char[] ch, int start, int length) throws SAXException
      Receive notification of cdata.

      The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

      The application must not attempt to read from the array outside of the specified range.

      Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

      Parameters:
      ch - The characters from the XML document.
      start - The start position in the array.
      length - The number of characters to read from the array.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      SAXException
      See Also:
    • processingInstruction

      public void processingInstruction(String target, String data) throws SAXException
      Receive notification of a processing instruction.
      Parameters:
      target - The processing instruction target.
      data - The processing instruction data, or null if none was supplied.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      SAXException
    • entityReference

      public final void entityReference(String name) throws SAXException
      Receive notivication of a entityReference.
      Specified by:
      entityReference in interface ExtendedContentHandler
      Overrides:
      entityReference in class SerializerBase
      Parameters:
      name - non-null reference to entity name string.
      Throws:
      SAXException
    • endElement

      public final void endElement(String elemName) throws SAXException
      Description copied from class: ToStream
      Receive notification of the end of an element.
      Specified by:
      endElement in interface ExtendedContentHandler
      Overrides:
      endElement in class ToStream
      Parameters:
      elemName - The element type name
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • processAttributes

      public void processAttributes(Writer writer, int nAttrs) throws IOException, SAXException
      Process the attributes, which means to write out the currently collected attributes to the writer. The attributes are not cleared by this method
      Overrides:
      processAttributes in class ToStream
      Parameters:
      writer - the writer to write processed attributes to.
      nAttrs - the number of attributes in m_attributes to be processed
      Throws:
      SAXException
      IOException
    • namespaceAfterStartElement

      public void namespaceAfterStartElement(String prefix, String uri) throws SAXException
      This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.
      Specified by:
      namespaceAfterStartElement in interface ExtendedContentHandler
      Overrides:
      namespaceAfterStartElement in class SerializerBase
      Parameters:
      uri - the URI of the namespace
      prefix - the prefix associated with the given URI.
      Throws:
      SAXException
      See Also:
    • startDTD

      public void startDTD(String name, String publicId, String systemId) throws SAXException
      Description copied from class: ToStream
      Report the start of DTD declarations, if any. Any declarations are assumed to be in the internal subset unless otherwise indicated.
      Specified by:
      startDTD in interface LexicalHandler
      Overrides:
      startDTD in class ToStream
      Parameters:
      name - The document type name.
      publicId - The declared public identifier for the external DTD subset, or null if none was declared.
      systemId - The declared system identifier for the external DTD subset, or null if none was declared.
      Throws:
      SAXException - The application may raise an exception.
      See Also:
    • endDTD

      public void endDTD() throws SAXException
      Report the end of DTD declarations.
      Specified by:
      endDTD in interface LexicalHandler
      Overrides:
      endDTD in class ToStream
      Throws:
      SAXException - The application may raise an exception.
      See Also:
    • attributeDecl

      public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException
      This method does nothing.
      Specified by:
      attributeDecl in interface DeclHandler
      Overrides:
      attributeDecl in class ToStream
      Parameters:
      eName - The name of the associated element.
      aName - The name of the attribute.
      type - A string representing the attribute type.
      valueDefault - A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
      value - A string representing the attribute's default value, or null if there is none.
      Throws:
      SAXException - The application may raise an exception.
    • elementDecl

      public void elementDecl(String name, String model) throws SAXException
      This method does nothing.
      Specified by:
      elementDecl in interface DeclHandler
      Overrides:
      elementDecl in class ToStream
      Parameters:
      name - The element type name.
      model - The content model as a normalized string.
      Throws:
      SAXException - The application may raise an exception.
    • internalEntityDecl

      public void internalEntityDecl(String name, String value) throws SAXException
      This method does nothing.
      Specified by:
      internalEntityDecl in interface DeclHandler
      Overrides:
      internalEntityDecl in class ToStream
      Parameters:
      name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
      value - The replacement text of the entity.
      Throws:
      SAXException - The application may raise an exception.
      See Also:
    • externalEntityDecl

      public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException
      This method does nothing.
      Specified by:
      externalEntityDecl in interface DeclHandler
      Overrides:
      externalEntityDecl in class ToStream
      Parameters:
      name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
      publicId - The declared public identifier of the entity, or null if none was declared.
      systemId - The declared system identifier of the entity.
      Throws:
      SAXException - The application may raise an exception.
      See Also:
    • addUniqueAttribute

      public void addUniqueAttribute(String name, String value, int flags) throws SAXException
      This method is used to add an attribute to the currently open element. The caller has guaranted that this attribute is unique, which means that it not been seen before and will not be seen again.
      Parameters:
      name - the qualified name of the attribute
      value - the value of the attribute which can contain only ASCII printable characters characters in the range 32 to 127 inclusive.
      flags - the bit values of this integer give optimization information.
      Throws:
      SAXException
    • comment

      public void comment(char[] ch, int start, int length) throws SAXException
      Description copied from class: ToStream
      Receive notification of an XML comment anywhere in the document. This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).
      Specified by:
      comment in interface LexicalHandler
      Overrides:
      comment in class ToStream
      Parameters:
      ch - An array holding the characters in the comment.
      start - The starting position in the array.
      length - The number of characters to use from the array.
      Throws:
      SAXException - The application may raise an exception.
    • reset

      public boolean reset()
      Description copied from class: ToStream
      Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).
      Specified by:
      reset in interface Serializer
      Overrides:
      reset in class ToStream
      Returns:
      true if the class was successfuly reset.