JDOM
2.0.5

org.jdom2.output.support
Class AbstractDOMOutputProcessor

java.lang.Object
  extended by org.jdom2.output.support.AbstractOutputProcessor
      extended by org.jdom2.output.support.AbstractDOMOutputProcessor
All Implemented Interfaces:
DOMOutputProcessor

public abstract class AbstractDOMOutputProcessor
extends AbstractOutputProcessor
implements DOMOutputProcessor

This class provides a concrete implementation of DOMOutputProcessor for supporting the DOMOutputter.

Overview

This class is marked abstract even though all methods are fully implemented. The process*(...) methods are public because they match the DOMOutputProcessor interface but the remaining methods are all protected.

People who want to create a custom DOMOutputProcessor for DOMOutputter are able to extend this class and modify any functionality they want. Before sub-classing this you should first check to see if the Format class can get you the results you want.

Subclasses of this should have reentrant methods. This is easiest to accomplish simply by not allowing any instance fields. If your sub-class has an instance field/variable, then it's probably broken.

The Stacks

One significant feature of this implementation is that it creates and maintains both a NamespaceStack and FormatStack that are managed in the printElement(FormatStack, NamespaceStack, org.w3c.dom.Document, Element) method. The stacks are pushed and popped in that method only. They significantly improve the performance and readability of the code.

The NamespaceStack is only sent through to the printElement(FormatStack, NamespaceStack, org.w3c.dom.Document, Element) and printContent(FormatStack, NamespaceStack, org.w3c.dom.Document, org.w3c.dom.Node, Walker) methods, but the FormatStack is pushed through to all print* Methods.

Content Processing

This class delegates the formatting of the content to the Walker classes and you can create your own custom walker by overriding the AbstractOutputProcessor.buildWalker(FormatStack, List, boolean) method.

Since:
JDOM2
Author:
Rolf Lear
See Also:
DOMOutputter, DOMOutputProcessor

Constructor Summary
AbstractDOMOutputProcessor()
           
 
Method Summary
protected  org.w3c.dom.Node helperContentDispatcher(FormatStack fstack, NamespaceStack nstack, org.w3c.dom.Document basedoc, Content content)
          This method contains code which is reused in a number of places.
protected  org.w3c.dom.Attr printAttribute(FormatStack fstack, org.w3c.dom.Document basedoc, Attribute attribute)
          This will handle printing of a Attribute.
protected  org.w3c.dom.CDATASection printCDATA(FormatStack fstack, org.w3c.dom.Document basedoc, CDATA cdata)
          This will handle printing of a CDATA.
protected  org.w3c.dom.Comment printComment(FormatStack fstack, org.w3c.dom.Document basedoc, Comment comment)
          This will handle printing of a Comment.
protected  void printContent(FormatStack fstack, NamespaceStack nstack, org.w3c.dom.Document basedoc, org.w3c.dom.Node target, Walker walker)
          This will handle printing of a List of Content.
protected  org.w3c.dom.Document printDocument(FormatStack fstack, NamespaceStack nstack, org.w3c.dom.Document basedoc, Document doc)
          This will handle printing of a Document.
protected  org.w3c.dom.Element printElement(FormatStack fstack, NamespaceStack nstack, org.w3c.dom.Document basedoc, Element element)
          This will handle printing of an Element.
protected  org.w3c.dom.EntityReference printEntityRef(FormatStack fstack, org.w3c.dom.Document basedoc, EntityRef entity)
          This will handle printing of an EntityRef.
protected  org.w3c.dom.ProcessingInstruction printProcessingInstruction(FormatStack fstack, org.w3c.dom.Document basedoc, ProcessingInstruction pi)
          This will handle printing of a ProcessingInstruction.
protected  org.w3c.dom.Text printText(FormatStack fstack, org.w3c.dom.Document basedoc, Text text)
          This will handle printing of a Text.
 org.w3c.dom.Attr process(org.w3c.dom.Document basedoc, Format format, Attribute attribute)
          This will convert the Attribute using the given DOM Document to create the resulting DOM Attr.
 org.w3c.dom.CDATASection process(org.w3c.dom.Document basedoc, Format format, CDATA cdata)
          This will convert the CDATA using the given DOM Document to create the resulting DOM CDATASection.
 org.w3c.dom.Comment process(org.w3c.dom.Document basedoc, Format format, Comment comment)
          This will convert the Comment using the given DOM Document to create the resulting DOM Comment.
 org.w3c.dom.Document process(org.w3c.dom.Document basedoc, Format format, Document doc)
          This will convert the Document to the given DOM Document.
 org.w3c.dom.Element process(org.w3c.dom.Document basedoc, Format format, Element element)
          This will convert the Element using the given DOM Document to create the resulting DOM Element.
 org.w3c.dom.EntityReference process(org.w3c.dom.Document basedoc, Format format, EntityRef entity)
          This will convert the EntityRef using the given DOM Document to create the resulting DOM EntityReference.
 java.util.List<org.w3c.dom.Node> process(org.w3c.dom.Document basedoc, Format format, java.util.List<? extends Content> list)
          This will convert the list of JDOM Content using the given DOM Document to create the resulting list of DOM Nodes.
 org.w3c.dom.ProcessingInstruction process(org.w3c.dom.Document basedoc, Format format, ProcessingInstruction pi)
          This will convert the ProcessingInstruction using the given DOM Document to create the resulting DOM ProcessingInstruction.
 org.w3c.dom.Text process(org.w3c.dom.Document basedoc, Format format, Text text)
          This will convert the Text using the given DOM Document to create the resulting DOM Text.
 
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

AbstractDOMOutputProcessor

public AbstractDOMOutputProcessor()
Method Detail

process

public org.w3c.dom.Document process(org.w3c.dom.Document basedoc,
                                    Format format,
                                    Document doc)
Description copied from interface: DOMOutputProcessor
This will convert the Document to the given DOM Document.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
doc - Document to format.
Returns:
The same DOM Document as the input document, but with the JDOM content converted and added.

process

public org.w3c.dom.Element process(org.w3c.dom.Document basedoc,
                                   Format format,
                                   Element element)
Description copied from interface: DOMOutputProcessor
This will convert the Element using the given DOM Document to create the resulting DOM Element.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
element - Element to format.
Returns:
The input JDOM Element converted to a DOM Element

process

public java.util.List<org.w3c.dom.Node> process(org.w3c.dom.Document basedoc,
                                                Format format,
                                                java.util.List<? extends Content> list)
Description copied from interface: DOMOutputProcessor
This will convert the list of JDOM Content using the given DOM Document to create the resulting list of DOM Nodes.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
list - JDOM Content to convert.
Returns:
The input JDOM Content List converted to a List of DOM Nodes

process

public org.w3c.dom.CDATASection process(org.w3c.dom.Document basedoc,
                                        Format format,
                                        CDATA cdata)
Description copied from interface: DOMOutputProcessor
This will convert the CDATA using the given DOM Document to create the resulting DOM CDATASection.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
cdata - CDATA to format.
Returns:
The input JDOM CDATA converted to a DOM CDATASection

process

public org.w3c.dom.Text process(org.w3c.dom.Document basedoc,
                                Format format,
                                Text text)
Description copied from interface: DOMOutputProcessor
This will convert the Text using the given DOM Document to create the resulting DOM Text.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
text - Text to format.
Returns:
The input JDOM Text converted to a DOM Text

process

public org.w3c.dom.Comment process(org.w3c.dom.Document basedoc,
                                   Format format,
                                   Comment comment)
Description copied from interface: DOMOutputProcessor
This will convert the Comment using the given DOM Document to create the resulting DOM Comment.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
comment - Comment to format.
Returns:
The input JDOM Comment converted to a DOM Comment

process

public org.w3c.dom.ProcessingInstruction process(org.w3c.dom.Document basedoc,
                                                 Format format,
                                                 ProcessingInstruction pi)
Description copied from interface: DOMOutputProcessor
This will convert the ProcessingInstruction using the given DOM Document to create the resulting DOM ProcessingInstruction.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
pi - ProcessingInstruction to format.
Returns:
The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction

process

public org.w3c.dom.EntityReference process(org.w3c.dom.Document basedoc,
                                           Format format,
                                           EntityRef entity)
Description copied from interface: DOMOutputProcessor
This will convert the EntityRef using the given DOM Document to create the resulting DOM EntityReference.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
entity - EntityRef to format.
Returns:
The input JDOM EntityRef converted to a DOM EntityReference

process

public org.w3c.dom.Attr process(org.w3c.dom.Document basedoc,
                                Format format,
                                Attribute attribute)
Description copied from interface: DOMOutputProcessor
This will convert the Attribute using the given DOM Document to create the resulting DOM Attr.

Specified by:
process in interface DOMOutputProcessor
Parameters:
basedoc - The DOM document to use for the conversion
format - Format instance specifying output style
attribute - Attribute to format.
Returns:
The input JDOM Attribute converted to a DOM Attr

printDocument

protected org.w3c.dom.Document printDocument(FormatStack fstack,
                                             NamespaceStack nstack,
                                             org.w3c.dom.Document basedoc,
                                             Document doc)
This will handle printing of a Document.

Parameters:
fstack - the FormatStack
nstack - the NamespaceStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
doc - Document to write.
Returns:
The input JDOM document converted to a DOM document.

printProcessingInstruction

protected org.w3c.dom.ProcessingInstruction printProcessingInstruction(FormatStack fstack,
                                                                       org.w3c.dom.Document basedoc,
                                                                       ProcessingInstruction pi)
This will handle printing of a ProcessingInstruction.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
pi - ProcessingInstruction to write.
Returns:
The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction.

printComment

protected org.w3c.dom.Comment printComment(FormatStack fstack,
                                           org.w3c.dom.Document basedoc,
                                           Comment comment)
This will handle printing of a Comment.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
comment - Comment to write.
Returns:
The input JDOM Comment converted to a DOM Comment

printEntityRef

protected org.w3c.dom.EntityReference printEntityRef(FormatStack fstack,
                                                     org.w3c.dom.Document basedoc,
                                                     EntityRef entity)
This will handle printing of an EntityRef.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
entity - EntotyRef to write.
Returns:
The input JDOM EntityRef converted to a DOM EntityReference

printCDATA

protected org.w3c.dom.CDATASection printCDATA(FormatStack fstack,
                                              org.w3c.dom.Document basedoc,
                                              CDATA cdata)
This will handle printing of a CDATA.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
cdata - CDATA to write.
Returns:
The input JDOM CDATA converted to a DOM CDATASection

printText

protected org.w3c.dom.Text printText(FormatStack fstack,
                                     org.w3c.dom.Document basedoc,
                                     Text text)
This will handle printing of a Text.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
text - Text to write.
Returns:
The input JDOM Text converted to a DOM Text

printAttribute

protected org.w3c.dom.Attr printAttribute(FormatStack fstack,
                                          org.w3c.dom.Document basedoc,
                                          Attribute attribute)
This will handle printing of a Attribute.

Parameters:
fstack - the FormatStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
attribute - Attribute to write.
Returns:
The input JDOM Attribute converted to a DOM Attr

printElement

protected org.w3c.dom.Element printElement(FormatStack fstack,
                                           NamespaceStack nstack,
                                           org.w3c.dom.Document basedoc,
                                           Element element)
This will handle printing of an Element.

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

The actual formatting of the content is managed by the Walker created for the Element's content.

Parameters:
fstack - the FormatStack
nstack - the NamespaceStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
element - Element to write.
Returns:
The input JDOM Element converted to a DOM Element

printContent

protected void printContent(FormatStack fstack,
                            NamespaceStack nstack,
                            org.w3c.dom.Document basedoc,
                            org.w3c.dom.Node target,
                            Walker walker)
This will handle printing of a List of Content. Uses the Walker to ensure formatting.

Parameters:
fstack - the FormatStack
nstack - the NamespaceStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
target - the DOM node this content should be appended to.
walker - List of Content to write.

helperContentDispatcher

protected org.w3c.dom.Node helperContentDispatcher(FormatStack fstack,
                                                   NamespaceStack nstack,
                                                   org.w3c.dom.Document basedoc,
                                                   Content content)
This method contains code which is reused in a number of places. It simply determines what content is passed in, and dispatches it to the correct print* method.

Parameters:
fstack - The current FormatStack
nstack - the NamespaceStack
basedoc - The org.w3c.dom.Document for creating DOM Nodes
content - The content to dispatch
Returns:
the input JDOM Content converted to a DOM Node.

JDOM
2.0.5

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