Class HTMLEmitter

All Implemented Interfaces:
Result, Receiver, ReceiverWithOutputProperties
Direct Known Subclasses:
HTML40Emitter, HTML50Emitter

public abstract class HTMLEmitter extends XMLEmitter
This class generates HTML output
  • Field Details

    • version

      protected int version
  • Constructor Details

    • HTMLEmitter

      public HTMLEmitter()
      Constructor
  • Method Details

    • setEmptyTag

      protected static void setEmptyTag(String tag)
    • isEmptyTag

      protected static boolean isEmptyTag(String tag)
    • setEscapeNonAscii

      public void setEscapeNonAscii(Boolean escape)
      Say that all non-ASCII characters should be escaped, regardless of the character encoding
      Overrides:
      setEscapeNonAscii in class XMLEmitter
      Parameters:
      escape - true if all non ASCII characters should be escaped
    • isHTMLElement

      protected abstract boolean isHTMLElement(NodeName name)
      Decide whether an element is "serialized as an HTML element" in the language of the 3.0 specification
      Parameters:
      name - the name of the element
      Returns:
      true if the element is to be serialized as an HTML element
    • open

      public void open() throws XPathException
      Output start of document
      Specified by:
      open in interface Receiver
      Overrides:
      open in class XMLEmitter
      Throws:
      XPathException - if an error occurs
    • openDocument

      protected void openDocument() throws XPathException
      Description copied from class: XMLEmitter
      Do the real work of starting the document. This happens when the first content is written.
      Overrides:
      openDocument in class XMLEmitter
      Throws:
      XPathException - if an error occurs opening the output file
    • writeDocType

      protected void writeDocType(NodeName name, String displayName, String systemId, String publicId) throws XPathException
      Output the document type declaration
      Overrides:
      writeDocType in class XMLEmitter
      Parameters:
      name - the qualified name of the element
      displayName - The element name
      systemId - The DOCTYPE system identifier
      publicId - The DOCTYPE public identifier
      Throws:
      XPathException - if an error occurs writing to the output
    • startElement

      public void startElement(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) throws XPathException
      Output element start tag
      Specified by:
      startElement in interface Receiver
      Overrides:
      startElement in class XMLEmitter
      Parameters:
      elemName - the name of the element
      type - the type annotation of the element
      attributes - the attributes of this element
      namespaces - the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elements
      location - an object providing information about the module, line, and column where the node originated
      properties - bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in class ReceiverOption
      Throws:
      XPathException - if an error occurs
    • startContentOLD

      public void startContentOLD() throws XPathException
      Throws:
      XPathException
    • writeAttribute

      protected void writeAttribute(NodeName elCode, String attname, String value, int properties) throws XPathException
      Write attribute name=value pair. Overrides the XML behaviour if the name and value are the same (we assume this is a boolean attribute to be minimised), or if the value is a URL.
      Overrides:
      writeAttribute in class XMLEmitter
      Parameters:
      elCode - The element name is not used in this version of the method, but is used in the HTML subclass.
      attname - The attribute name, which has already been validated to ensure it can be written in this encoding
      value - The value of the attribute
      properties - Any special properties of the attribute
      Throws:
      XPathException - if an error occurs
    • writeEscape

      protected void writeEscape(UnicodeString chars, boolean inAttribute) throws IOException, XPathException
      Escape characters. Overrides the XML behaviour
      Overrides:
      writeEscape in class XMLEmitter
      Parameters:
      chars - The character sequence containing the string
      inAttribute - Set to true if the text is in an attribute value
      Throws:
      IOException - if an IO exception occurs
      XPathException - if an IO exception occurs
    • rejectControlCharacters

      protected abstract boolean rejectControlCharacters()
      Ask whether control characters should be rejected: true for HTML4, false for HTML5
      Returns:
      true if control characters should be rejected
    • writeEmptyElementTagCloser

      protected void writeEmptyElementTagCloser(String displayName, NodeName nameCode) throws IOException
      Close an empty element tag. (This is overridden in XHTMLEmitter).
      Overrides:
      writeEmptyElementTagCloser in class XMLEmitter
      Parameters:
      displayName - the name of the empty element
      nameCode - the fingerprint of the name of the empty element
      Throws:
      IOException - if an IO exception occurs
    • endElement

      public void endElement() throws XPathException
      Output an element end tag.
      Specified by:
      endElement in interface Receiver
      Overrides:
      endElement in class XMLEmitter
      Throws:
      XPathException - if an error occurs
    • characters

      public void characters(UnicodeString chars, Location locationId, int properties) throws XPathException
      Character data.
      Specified by:
      characters in interface Receiver
      Overrides:
      characters in class XMLEmitter
      Parameters:
      chars - The characters
      locationId - provides information such as line number and system ID.
      properties - Bit significant value. The following bits are defined:
      DISABLE_ESCAPING
      Disable escaping for this text node
      USE_CDATA
      Output as a CDATA section
      Throws:
      XPathException - if an error occurs
    • processingInstruction

      public void processingInstruction(String target, UnicodeString data, Location locationId, int properties) throws XPathException
      Handle a processing instruction.
      Specified by:
      processingInstruction in interface Receiver
      Overrides:
      processingInstruction in class XMLEmitter
      Parameters:
      target - The PI name. This must be a legal name (it will not be checked).
      data - The data portion of the processing instruction
      locationId - provides information such as line number and system ID.
      properties - Additional information about the PI.
      Throws:
      XPathException - if an error occurs