Top Description Constructors Methods
org.jdom2.output.support

public abstract Class AbstractDOMOutputProcessor

extends AbstractOutputProcessor
implements DOMOutputProcessor
Class Inheritance
All Implemented Interfaces
org.jdom2.output.support.DOMOutputProcessor
Known Direct Subclasses
org.jdom2.output.DOMOutputter.DefaultDOMOutputProcessor
Imports
java.util.ArrayList, .Collections, .List, org.jdom2.Attribute, .CDATA, .Comment, .Content, .Content.CType, .Document, .Element, .EntityRef, .JDOMConstants, .Namespace, .ProcessingInstruction, .Text, org.jdom2.output.DOMOutputter, .Format, .Format.TextMode, org.jdom2.util.NamespaceStack

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 buildWalker(FormatStack, List, boolean) method.

Author
Rolf Lear
Since
JDOM2
See Also
DOMOutputter, DOMOutputProcessor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static String
getXmlnsTagFor(Namespace
Namespace to add definition of
ns
)

This will handle adding any Namespace attributes to the DOM tree.

protected Node

Returns:

the input JDOM Content converted to a DOM Node.
helperContentDispatcher
(final FormatStack
The current FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Content
The content to dispatch
content
)

This method contains code which is reused in a number of places.

protected Attr

Returns:

The input JDOM Attribute converted to a DOM Attr
printAttribute
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Attribute
Attribute to write.
attribute
)

This will handle printing of a Attribute.

protected CDATASection

Returns:

The input JDOM CDATA converted to a DOM CDATASection
printCDATA
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final CDATA
CDATA to write.
cdata
)

This will handle printing of a CDATA.

protected Comment

Returns:

The input JDOM Comment converted to a DOM Comment
printComment
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Comment
Comment to write.
comment
)

This will handle printing of a Comment.

protected void
printContent(final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Node
the DOM node this content should be appended to.
target
,
final Walker
List of Content to write.
walker
)

This will handle printing of a List of Content.

protected Document

Returns:

The input JDOM document converted to a DOM document.
printDocument
(final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Document
Document to write.
doc
)

This will handle printing of a Document.

protected Element

Returns:

The input JDOM Element converted to a DOM Element
printElement
(final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Element
Element to write.
element
)

This will handle printing of an Element.

protected EntityReference

Returns:

The input JDOM EntityRef converted to a DOM EntityReference
printEntityRef
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final EntityRef
EntotyRef to write.
entity
)

This will handle printing of an EntityRef.

protected ProcessingInstruction

Returns:

The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction.
printProcessingInstruction
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final ProcessingInstruction
ProcessingInstruction to write.
pi
)

This will handle printing of a ProcessingInstruction.

protected Text

Returns:

The input JDOM Text converted to a DOM Text
printText
(final FormatStack
the FormatStack
fstack
,
final Document
The org.w3c.dom.Document for creating DOM Nodes
basedoc
,
final Text
Text to write.
text
)

This will handle printing of a Text.

public Document
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
Document
Document to format.
doc
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Document to the given DOM Document.
public Element
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
Element
Element to format.
element
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Element using the given DOM Document to create the resulting DOM Element.
public List<Node>
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
List<? extends Content>
JDOM Content to convert.
list
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the list of JDOM Content using the given DOM Document to create the resulting list of DOM Nodes.
public CDATASection
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
CDATA
CDATA to format.
cdata
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the CDATA using the given DOM Document to create the resulting DOM CDATASection.
public Text
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
Text
Text to format.
text
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Text using the given DOM Document to create the resulting DOM Text.
public Comment
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
Comment
Comment to format.
comment
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Comment using the given DOM Document to create the resulting DOM Comment.
public ProcessingInstruction
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
ProcessingInstruction
ProcessingInstruction to format.
pi
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the ProcessingInstruction using the given DOM Document to create the resulting DOM ProcessingInstruction.
public EntityReference
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
EntityRef
EntityRef to format.
entity
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the EntityRef using the given DOM Document to create the resulting DOM EntityReference.
public Attr
process(Document
The DOM document to use for the conversion
basedoc
,
Format
Format instance specifying output style
format
,
Attribute
Attribute to format.
attribute
)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Attribute using the given DOM Document to create the resulting DOM Attr.
Inherited from org.jdom2.output.support.AbstractOutputProcessor:
buildWalker

Constructor Detail

AbstractDOMOutputProcessorback to summary
public AbstractDOMOutputProcessor()

Method Detail

getXmlnsTagForback to summary
private static String getXmlnsTagFor(Namespace ns)

This will handle adding any Namespace attributes to the DOM tree.

Parameters
ns:Namespace

Namespace to add definition of

helperContentDispatcherback to summary
protected Node helperContentDispatcher(final FormatStack fstack, final NamespaceStack nstack, final Document basedoc, final 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:FormatStack

The current FormatStack

nstack:NamespaceStack

the NamespaceStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

content:Content

The content to dispatch

Returns:Node

the input JDOM Content converted to a DOM Node.

printAttributeback to summary
protected Attr printAttribute(final FormatStack fstack, final Document basedoc, final Attribute attribute)

This will handle printing of a Attribute.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

attribute:Attribute

Attribute to write.

Returns:Attr

The input JDOM Attribute converted to a DOM Attr

printCDATAback to summary
protected CDATASection printCDATA(final FormatStack fstack, final Document basedoc, final CDATA cdata)

This will handle printing of a CDATA.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

cdata:CDATA

CDATA to write.

Returns:CDATASection

The input JDOM CDATA converted to a DOM CDATASection

printCommentback to summary
protected Comment printComment(final FormatStack fstack, final Document basedoc, final Comment comment)

This will handle printing of a Comment.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

comment:Comment

Comment to write.

Returns:Comment

The input JDOM Comment converted to a DOM Comment

printContentback to summary
protected void printContent(final FormatStack fstack, final NamespaceStack nstack, final Document basedoc, final Node target, final Walker walker)

This will handle printing of a List of Content. Uses the Walker to ensure formatting.

Parameters
fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

target:Node

the DOM node this content should be appended to.

walker:Walker

List of Content to write.

printDocumentback to summary
protected Document printDocument(final FormatStack fstack, final NamespaceStack nstack, final Document basedoc, final Document doc)

This will handle printing of a Document.

Parameters
fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

doc:Document

Document to write.

Returns:Document

The input JDOM document converted to a DOM document.

printElementback to summary
protected Element printElement(final FormatStack fstack, final NamespaceStack nstack, final Document basedoc, final 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:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

element:Element

Element to write.

Returns:Element

The input JDOM Element converted to a DOM Element

printEntityRefback to summary
protected EntityReference printEntityRef(final FormatStack fstack, final Document basedoc, final EntityRef entity)

This will handle printing of an EntityRef.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

entity:EntityRef

EntotyRef to write.

Returns:EntityReference

The input JDOM EntityRef converted to a DOM EntityReference

printProcessingInstructionback to summary
protected ProcessingInstruction printProcessingInstruction(final FormatStack fstack, final Document basedoc, final ProcessingInstruction pi)

This will handle printing of a ProcessingInstruction.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

pi:ProcessingInstruction

ProcessingInstruction to write.

Returns:ProcessingInstruction

The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction.

printTextback to summary
protected Text printText(final FormatStack fstack, final Document basedoc, final Text text)

This will handle printing of a Text.

Parameters
fstack:FormatStack

the FormatStack

basedoc:Document

The org.w3c.dom.Document for creating DOM Nodes

text:Text

Text to write.

Returns:Text

The input JDOM Text converted to a DOM Text

processback to summary
public Document process(Document basedoc, Format format, Document doc)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Document to the given DOM Document.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

doc:Document

Document to format.

Returns:Document

The same DOM Document as the input document, but with the JDOM content converted and added.

Annotations
@Override
processback to summary
public Element process(Document basedoc, Format format, Element element)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Element using the given DOM Document to create the resulting DOM Element.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

element:Element

Element to format.

Returns:Element

The input JDOM Element converted to a DOM Element

Annotations
@Override
processback to summary
public List<Node> process(Document basedoc, Format format, List<? extends Content> list)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the list of JDOM Content using the given DOM Document to create the resulting list of DOM Nodes.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

list:List<? extends Content>

JDOM Content to convert.

Returns:List<Node>

The input JDOM Content List converted to a List of DOM Nodes

Annotations
@Override
processback to summary
public CDATASection process(Document basedoc, Format format, CDATA cdata)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the CDATA using the given DOM Document to create the resulting DOM CDATASection.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

cdata:CDATA

CDATA to format.

Returns:CDATASection

The input JDOM CDATA converted to a DOM CDATASection

Annotations
@Override
processback to summary
public Text process(Document basedoc, Format format, Text text)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Text using the given DOM Document to create the resulting DOM Text.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

text:Text

Text to format.

Returns:Text

The input JDOM Text converted to a DOM Text

Annotations
@Override
processback to summary
public Comment process(Document basedoc, Format format, Comment comment)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Comment using the given DOM Document to create the resulting DOM Comment.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

comment:Comment

Comment to format.

Returns:Comment

The input JDOM Comment converted to a DOM Comment

Annotations
@Override
processback to summary
public ProcessingInstruction process(Document basedoc, Format format, ProcessingInstruction pi)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the ProcessingInstruction using the given DOM Document to create the resulting DOM ProcessingInstruction.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

pi:ProcessingInstruction

ProcessingInstruction to format.

Returns:ProcessingInstruction

The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction

Annotations
@Override
processback to summary
public EntityReference process(Document basedoc, Format format, EntityRef entity)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the EntityRef using the given DOM Document to create the resulting DOM EntityReference.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

entity:EntityRef

EntityRef to format.

Returns:EntityReference

The input JDOM EntityRef converted to a DOM EntityReference

Annotations
@Override
processback to summary
public Attr process(Document basedoc, Format format, Attribute attribute)

Implements org.jdom2.output.support.DOMOutputProcessor.process.

Doc from org.jdom2.output.support.DOMOutputProcessor.process.

This will convert the Attribute using the given DOM Document to create the resulting DOM Attr.

Parameters
basedoc:Document

The DOM document to use for the conversion

format:Format

Format instance specifying output style

attribute:Attribute

Attribute to format.

Returns:Attr

The input JDOM Attribute converted to a DOM Attr

Annotations
@Override