JDOM
2.0.5

org.jdom2.output.support
Class AbstractSAXOutputProcessor

java.lang.Object
  extended by org.jdom2.output.support.AbstractOutputProcessor
      extended by 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 Summary
AbstractSAXOutputProcessor()
           
 
Method Summary
protected  org.xml.sax.XMLReader createParser()
           Creates a SAX XMLReader.
protected  void printCDATA(SAXTarget out, FormatStack fstack, CDATA cdata)
          This will handle printing of a CDATA.
protected  void printComment(SAXTarget out, FormatStack fstack, Comment comment)
          This will handle printing of a Comment.
protected  void printContent(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Walker walker)
          This will handle printing of a List of Content.
protected  void printDocType(SAXTarget out, FormatStack fstack, DocType docType)
          This will handle printing of a DocType.
protected  void printDocument(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Document document)
          This will handle printing of a Document.
protected  void printElement(SAXTarget out, FormatStack fstack, NamespaceStack nstack, Element element)
          This will handle printing of an Element.
protected  void printEntityRef(SAXTarget out, FormatStack fstack, EntityRef entity)
          This will handle printing of an EntityRef.
protected  void printProcessingInstruction(SAXTarget out, FormatStack fstack, ProcessingInstruction pi)
          This will handle printing of a ProcessingInstruction.
protected  void printText(SAXTarget out, FormatStack fstack, Text text)
          This will handle printing of a Text.
 void process(SAXTarget out, Format format, CDATA cdata)
          Print out a CDATA node.
 void process(SAXTarget out, Format format, Comment comment)
          Print out a Comment.
 void process(SAXTarget out, Format format, DocType doctype)
          Print out the DocType.
 void process(SAXTarget out, Format format, Document doc)
          This will print the Document to the given SAXTarget.
 void process(SAXTarget out, Format format, Element element)
          Print out an Element, including its Attributes, and all contained (child) elements, etc.
 void process(SAXTarget out, Format format, EntityRef entity)
          Print out a EntityRef.
 void process(SAXTarget out, Format format, java.util.List<? extends Content> list)
          This will handle printing out a list of nodes.
 void process(SAXTarget out, Format format, ProcessingInstruction pi)
          Print out a ProcessingInstruction.
 void process(SAXTarget out, Format format, Text text)
          Print out a Text node.
 void processAsDocument(SAXTarget out, Format format, Element node)
          Print out an Element encapsulated in start/end Document SAX events, including its Attributes, and all contained (child) elements, etc.
 void processAsDocument(SAXTarget out, Format format, java.util.List<? extends Content> nodes)
          This will handle printing out a list of nodes thats encapsulated in start/end Document SAX events.
 
Methods inherited from class org.jdom2.output.support.AbstractOutputProcessor
buildWalker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                    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,
                    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,
                    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. Perfoms 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
Print out a ProcessingInstruction.

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,
                              java.util.List<? extends Content> nodes)
                       throws JDOMException
Description copied from interface: SAXOutputProcessor
This will handle printing out a list of nodes thats 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 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.

JDOM
2.0.5

Copyright � 2013 Jason Hunter, Brett McLaughlin. All Rights Reserved.