Class AbstractSAXOutputProcessor

java.lang.Object
org.jdom2.output.support.AbstractOutputProcessor
org.jdom2.output.support.AbstractSAXOutputProcessor
All Implemented Interfaces:
SAXOutputProcessor

public class AbstractSAXOutputProcessor extends AbstractOutputProcessor implements SAXOutputProcessor
Outputs a JDOM document as a stream of SAX2 events.

Most ContentHandler callbacks are supported. Neither ignorableWhitespace() nor skippedEntity() have been implemented.

At this time, it is not possible to access notations and unparsed entity references in a DTD from JDOM. Therefore, full DTDHandler call-backs have not been implemented yet.

The ErrorHandler call-backs have not been implemented, since these are supposed to be invoked when the document is parsed and at this point the document exists in memory and is known to have no errors.

The SAX2 API does not support whitespace formatting outside the root element. As a consequence any Formatting options that would normally affect the structures outside the root element will be ignored.
Author:
Brett McLaughlin, Jason Hunter, Fred Trimble, Bradley S. Huffman, Rolf Lear
  • Constructor Details

    • AbstractSAXOutputProcessor

      public AbstractSAXOutputProcessor()
  • Method Details

    • process

      public void process(SAXTarget out, Format format, Document doc) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      This will print the Document to the given SAXTarget.

      Warning: using your own SAXTarget may cause the outputter's preferred character encoding to be ignored. If you use encodings other than UTF-8, we recommend using the method that takes an OutputStream instead.

      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      doc - Document to format.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, DocType doctype) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out the DocType.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      doctype - DocType to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, Element element) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out an Element, including its Attributes, and all contained (child) elements, etc.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      element - Element to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, List<? extends Content> list) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      This will handle printing out a list of nodes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      list - List of nodes.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, CDATA cdata) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out a CDATA node.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      cdata - CDATA to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, Text text) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out a Text node. Performs the necessary entity escaping and whitespace stripping.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      text - Text to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, Comment comment) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out a Comment.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      comment - Comment to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, ProcessingInstruction pi) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      pi - ProcessingInstruction to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • process

      public void process(SAXTarget out, Format format, EntityRef entity) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out a EntityRef.
      Specified by:
      process in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      entity - EntityRef to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • processAsDocument

      public void processAsDocument(SAXTarget out, Format format, List<? extends Content> nodes) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      This will handle printing out a list of nodes that is encapsulated in start/end Document SAX events. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".
      Specified by:
      processAsDocument in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      nodes - List of nodes.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • processAsDocument

      public void processAsDocument(SAXTarget out, Format format, Element node) throws JDOMException
      Description copied from interface: SAXOutputProcessor
      Print out an Element encapsulated in start/end Document SAX events, including its Attributes, and all contained (child) elements, etc.
      Specified by:
      processAsDocument in interface SAXOutputProcessor
      Parameters:
      out - SAXTarget to use.
      format - Format instance specifying output style
      node - Element to output.
      Throws:
      JDOMException - if there is an issue encountered during output.
    • printDocument

      protected void printDocument(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Document document) throws SAXException
      This will handle printing of a Document.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      nstack - the NamespaceStack
      document - Document to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printDocType

      protected void printDocType(SAXTarget out, FormatStack fstack, DocType docType) throws SAXException
      This will handle printing of a DocType.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      docType - DocType to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printProcessingInstruction

      protected void printProcessingInstruction(SAXTarget out, FormatStack fstack, ProcessingInstruction pi) throws SAXException
      This will handle printing of a ProcessingInstruction.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      pi - ProcessingInstruction to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printComment

      protected void printComment(SAXTarget out, FormatStack fstack, Comment comment) throws SAXException
      This will handle printing of a Comment.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      comment - Comment to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printEntityRef

      protected void printEntityRef(SAXTarget out, FormatStack fstack, EntityRef entity) throws SAXException
      This will handle printing of an EntityRef.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      entity - EntotyRef to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printCDATA

      protected void printCDATA(SAXTarget out, FormatStack fstack, CDATA cdata) throws SAXException
      This will handle printing of a CDATA.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      cdata - CDATA to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printText

      protected void printText(SAXTarget out, FormatStack fstack, Text text) throws SAXException
      This will handle printing of a Text.
      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      text - Text to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printElement

      protected void printElement(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Element element) throws SAXException
      This will handle printing of an Element.

      This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.

      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      nstack - the NamespaceStack
      element - Element to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • printContent

      protected void printContent(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Walker walker) throws SAXException
      This will handle printing of a List of Content.

      It relies on the appropriate Walker to get the formatting right.

      Parameters:
      out - SAXTarget to use.
      fstack - the FormatStack
      nstack - the NamespaceStack
      walker - Waker of Content to write.
      Throws:
      SAXException - if the destination SAXTarget fails
    • createParser

      protected XMLReader createParser() throws Exception

      Creates a SAX XMLReader.

      Returns:
      XMLReader a SAX2 parser.
      Throws:
      Exception - if no parser can be created.