Class 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 Detail

      • AbstractSAXOutputProcessor

        public AbstractSAXOutputProcessor()
    • Method Detail

      • 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,
                            java.util.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,
                            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.
      • processAsDocument

        public void processAsDocument​(SAXTarget out,
                                      Format format,
                                      java.util.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.
      • printDocument

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

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

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

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

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

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

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

        protected void printElement​(SAXTarget out,
                                    FormatStack fstack,
                                    NamespaceStack nstack,
                                    Element element)
                             throws org.xml.sax.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:
        org.xml.sax.SAXException - if the destination SAXTarget fails
      • printContent

        protected void printContent​(SAXTarget out,
                                    FormatStack fstack,
                                    NamespaceStack nstack,
                                    Walker walker)
                             throws org.xml.sax.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:
        org.xml.sax.SAXException - if the destination SAXTarget fails
      • createParser

        protected org.xml.sax.XMLReader createParser()
                                              throws java.lang.Exception

        Creates a SAX XMLReader.

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