Top Description Inners Fields Constructors Methods
org.jdom2.output

public Class DOMOutputter

extends Object
Class Inheritance
Imports
java.util.List, org.jdom2.Attribute, .CDATA, .Comment, .Content, .DocType, .Document, .Element, .EntityRef, .JDOMException, .ProcessingInstruction, .Text, org.jdom2.adapters.DOMAdapter, .JAXPDOMAdapter, org.jdom2.internal.ReflectionConstructor, org.jdom2.output.support.AbstractDOMOutputProcessor, .DOMOutputProcessor

Outputs a JDOM org.jdom2.Document as a DOM org.w3c.dom.Document. Also provides methods to output other types of JDOM Content in the equivalent DOM nodes.

There are two versions of most functions, one that creates an independent DOM node using the DOMAdapter to create a new org.w3c.dom.Document. The other version creates the new DOM Nodes using the supplied org.w3c.dom.Document instance.

Authors
Brett McLaughlin, Jason Hunter, Matthew Merlo, Dan Schaffer, Yusuf Goolamabbas, Bradley S. Huffman, Rolf lear

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DOMOutputter.DefaultDOMOutputProcessor

Create a final/concrete instance of the AbstractDOMOutputProcessor.

Field Summary

Modifier and TypeField and Description
private DOMAdapter
adapter

Adapter to use for interfacing with the DOM implementation

private static final DOMAdapter
DEFAULT_ADAPTER

Default adapter class

private static final DOMOutputProcessor
private Format
private DOMOutputProcessor

Constructor Summary

AccessConstructor and Description
public
DOMOutputter()

This creates a new DOMOutputter which will attempt to first locate a DOM implementation to use via JAXP, and if JAXP does not exist or there's a problem, will fall back to the default parser.

public
DOMOutputter(DOMOutputProcessor
the custom processor to use.
processor
)

This creates a new DOMOutputter which uses the default (JAXP) DOM implementation but with a custom processor.

public
DOMOutputter(DOMAdapter
The adapter to use to create the base Document instance (null implies the default).
adapter
,
Format
The output Format to use (null implies the default).
format
,
DOMOutputProcessor
The custom mechanism for doing the output (null implies the default).
processor
)

The complete constructor for specifying a custom DOMAdaptor, Format, and DOMOutputProcessor.

public
DOMOutputter(String
String name of class to use for DOM output
adapterClass
)

Deprecated use DOMOutputter#DOMOutputter(DOMAdapter) instead.
This creates a new DOMOutputter using the specified DOMAdapter implementation as a way to choose the underlying parser.
public
DOMOutputter(DOMAdapter
the DOMAdapter instance to use for creating the base org.w3c.dom.Document Specify the null value to get the default adapter.
adapter
)

This creates a new DOMOutputter using the specified DOMAdapter implementation as a way to choose the underlying parser.

Method Summary

Modifier and TypeMethod and Description
public DOMAdapter

Returns:

the current DOMAdapter.
getDOMAdapter
()

Get the DOMAdapter currently set for this DOMOutputter.

public DOMOutputProcessor

Returns:

the current DOMOutputProcessor
getDOMOutputProcessor
()

Get the current DOMOutputProcessor

public boolean

Returns:

the forceNamespaceAware flag value
getForceNamespaceAware
()

Deprecated All DOMOutputters are always NamesapceAware. Always true.
Returns whether DOMs will be constructed with namespaces even when the source document has elements all in the empty namespace.
public Format

Returns:

the current Format instance
getFormat
()

Get the Format instance currently used by this DOMOutputter.

public Document

Returns:

an org.w3c.dom.Document version
output
(Document
Document to output.
document
)

This converts the JDOM Document parameter to a DOM Document, returning the DOM version.

public DocumentType

Returns:

an org.w3c.dom.DocumentType version
output
(DocType
DocType to output.
doctype
)

This converts the JDOM DocType parameter to a DOM DocumentType, returning the DOM version.

public Element

Returns:

an org.w3c.dom.Element version
output
(Element
Element to output.
element
)

This converts the JDOM Element parameter to a DOM Element, returning the DOM version.

public Text

Returns:

an org.w3c.dom.Text version
output
(Text
Text to output.
text
)

This converts the JDOM Text parameter to a DOM Text Node, returning the DOM version.

public CDATASection

Returns:

an org.w3c.dom.CDATASection version
output
(CDATA
CDATA to output.
cdata
)

This converts the JDOM CDATA parameter to a DOM CDATASection Node, returning the DOM version.

public ProcessingInstruction

Returns:

an org.w3c.dom.Element version
output
(ProcessingInstruction
ProcessingInstruction to output.
pi
)

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version.

public Comment

Returns:

an org.w3c.dom.Comment version
output
(Comment
Comment to output.
comment
)

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version.

public EntityReference

Returns:

an org.w3c.dom.EntityReference version
output
(EntityRef
EntityRef to output.
entity
)

This converts the JDOM EntityRef parameter to a DOM EntityReference Node, returning the DOM version.

public Attr

Returns:

an org.w3c.dom.Attr version
output
(Attribute
Attribute to output.
attribute
)

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version.

public List<Node>

Returns:

an org.w3c.dom.Attr version
output
(List<? extends Content>
Attribute to output.
list
)

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version.

public Element

Returns:

an org.w3c.dom.Element version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
Element
Element to output.
element
)

This converts the JDOM Element parameter to a DOM Element, returning the DOM version.

public Text

Returns:

an org.w3c.dom.Text version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
Text
Text to output.
text
)

This converts the JDOM Text parameter to a DOM Text Node, returning the DOM version.

public CDATASection

Returns:

an org.w3c.dom.CDATASection version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
CDATA
CDATA to output.
cdata
)

This converts the JDOM CDATA parameter to a DOM CDATASection Node, returning the DOM version.

public ProcessingInstruction

Returns:

an org.w3c.dom.Element version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
ProcessingInstruction
ProcessingInstruction to output.
pi
)

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version.

public Comment

Returns:

an org.w3c.dom.Comment version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
Comment
Comment to output.
comment
)

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version.

public EntityReference

Returns:

an org.w3c.dom.EntityReference version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
EntityRef
EntityRef to output.
entity
)

This converts the JDOM EntityRef parameter to a DOM EntityReference Node, returning the DOM version.

public Attr

Returns:

an org.w3c.dom.Attr version
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
Attribute
Attribute to output.
attribute
)

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version.

public List<Node>

Returns:

a List of org.w3c.dom.Node
output
(Document
The DOM Document to use for creating DOM Nodes.
basedoc
,
List<? extends Content>
of JDOM Content to output.
list
)

This converts the list of JDOM Content in to a list of DOM Nodes, returning the DOM version.

public void
setDOMAdapter(DOMAdapter
the new DOMAdapter to use (null implies the default).
adapter
)

Set the DOMAdapter currently set for this DOMOutputter.

public void
setDOMOutputProcessor(DOMOutputProcessor
the new processor to set (null implies the default)
processor
)

Set a new DOMOutputProcessor for this DOMOutputter.

public void
setForceNamespaceAware(boolean
true to force NamespaceAware
flag
)

Deprecated All DOMOutputters are now always NamespaceAware.
Controls how NO_NAMESPACE nodes are handled.
public void
setFormat(Format
the new Format instance to use (null implies the default)
format
)

Set a new Format instance for this DOMOutputter

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adapterback to summary
private DOMAdapter adapter

Adapter to use for interfacing with the DOM implementation

DEFAULT_ADAPTERback to summary
private static final DOMAdapter DEFAULT_ADAPTER

Default adapter class

DEFAULT_PROCESSORback to summary
private static final DOMOutputProcessor DEFAULT_PROCESSOR
formatback to summary
private Format format
processorback to summary
private DOMOutputProcessor processor

Constructor Detail

DOMOutputterback to summary
public DOMOutputter()

This creates a new DOMOutputter which will attempt to first locate a DOM implementation to use via JAXP, and if JAXP does not exist or there's a problem, will fall back to the default parser.

DOMOutputterback to summary
public DOMOutputter(DOMOutputProcessor processor)

This creates a new DOMOutputter which uses the default (JAXP) DOM implementation but with a custom processor.

Parameters
processor:DOMOutputProcessor

the custom processor to use.

Since
JDOM2
DOMOutputterback to summary
public DOMOutputter(DOMAdapter adapter, Format format, DOMOutputProcessor processor)

The complete constructor for specifying a custom DOMAdaptor, Format, and DOMOutputProcessor.

Parameters
adapter:DOMAdapter

The adapter to use to create the base Document instance (null implies the default).

format:Format

The output Format to use (null implies the default).

processor:DOMOutputProcessor

The custom mechanism for doing the output (null implies the default).

Since
JDOM2
DOMOutputterback to summary
public DOMOutputter(String adapterClass)

Deprecated

use DOMOutputter#DOMOutputter(DOMAdapter) instead.

This creates a new DOMOutputter using the specified DOMAdapter implementation as a way to choose the underlying parser.

Parameters
adapterClass:String

String name of class to use for DOM output

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if the adapter could not be instantiated. (it should be JDOMException, but that would require a change to this deprecated method's signature...
DOMOutputterback to summary
public DOMOutputter(DOMAdapter adapter)

This creates a new DOMOutputter using the specified DOMAdapter implementation as a way to choose the underlying parser.

If the specified adapter is not thread-safe then the user should ensure that the adapter instance is never shared between multiple DOMOutputters. The default DOMAdapter JAXPDOMAdapter is thread-safe.

Parameters
adapter:DOMAdapter

the DOMAdapter instance to use for creating the base org.w3c.dom.Document Specify the null value to get the default adapter.

Since
JDOM2

Method Detail

getDOMAdapterback to summary
public DOMAdapter getDOMAdapter()

Get the DOMAdapter currently set for this DOMOutputter.

Returns:DOMAdapter

the current DOMAdapter.

Since
JDOM2
getDOMOutputProcessorback to summary
public DOMOutputProcessor getDOMOutputProcessor()

Get the current DOMOutputProcessor

Returns:DOMOutputProcessor

the current DOMOutputProcessor

Since
JDOM2
getForceNamespaceAwareback to summary
public boolean getForceNamespaceAware()

Deprecated

All DOMOutputters are always NamesapceAware. Always true.

Returns whether DOMs will be constructed with namespaces even when the source document has elements all in the empty namespace.

Returns:boolean

the forceNamespaceAware flag value

Annotations
@Deprecated
getFormatback to summary
public Format getFormat()

Get the Format instance currently used by this DOMOutputter.

Returns:Format

the current Format instance

Since
JDOM2
outputback to summary
public Document output(Document document) throws JDOMException

This converts the JDOM Document parameter to a DOM Document, returning the DOM version. The DOM implementation is the one supplied by the current DOMAdapter.

Parameters
document:Document

Document to output.

Returns:Document

an org.w3c.dom.Document version

Exceptions
JDOMException:
if output failed.
outputback to summary
public DocumentType output(DocType doctype) throws JDOMException

This converts the JDOM DocType parameter to a DOM DocumentType, returning the DOM version. The DOM implementation is the one supplied by the current DOMAdapter.

Unlike the other DOM Nodes, you cannot use a DOM Document to simply create a DOM DocumentType Node, it has to be created at the same time as the DOM Document instance. As a result, there is no version of this method that takes a DOM Document instance.

Parameters
doctype:DocType

DocType to output.

Returns:DocumentType

an org.w3c.dom.DocumentType version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Element output(Element element) throws JDOMException

This converts the JDOM Element parameter to a DOM Element, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
element:Element

Element to output.

Returns:Element

an org.w3c.dom.Element version

Exceptions
JDOMException:
if output failed.
outputback to summary
public Text output(Text text) throws JDOMException

This converts the JDOM Text parameter to a DOM Text Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
text:Text

Text to output.

Returns:Text

an org.w3c.dom.Text version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public CDATASection output(CDATA cdata) throws JDOMException

This converts the JDOM CDATA parameter to a DOM CDATASection Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
cdata:CDATA

CDATA to output.

Returns:CDATASection

an org.w3c.dom.CDATASection version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public ProcessingInstruction output(ProcessingInstruction pi) throws JDOMException

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
pi:ProcessingInstruction

ProcessingInstruction to output.

Returns:ProcessingInstruction

an org.w3c.dom.Element version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Comment output(Comment comment) throws JDOMException

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
comment:Comment

Comment to output.

Returns:Comment

an org.w3c.dom.Comment version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public EntityReference output(EntityRef entity) throws JDOMException

This converts the JDOM EntityRef parameter to a DOM EntityReference Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
entity:EntityRef

EntityRef to output.

Returns:EntityReference

an org.w3c.dom.EntityReference version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Attr output(Attribute attribute) throws JDOMException

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
attribute:Attribute

Attribute to output.

Returns:Attr

an org.w3c.dom.Attr version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public List<Node> output(List<? extends Content> list) throws JDOMException

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
list:List<? extends Content>

Attribute to output.

Returns:List<Node>

an org.w3c.dom.Attr version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Element output(Document basedoc, Element element) throws JDOMException

This converts the JDOM Element parameter to a DOM Element, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

element:Element

Element to output.

Returns:Element

an org.w3c.dom.Element version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Text output(Document basedoc, Text text) throws JDOMException

This converts the JDOM Text parameter to a DOM Text Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

text:Text

Text to output.

Returns:Text

an org.w3c.dom.Text version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public CDATASection output(Document basedoc, CDATA cdata) throws JDOMException

This converts the JDOM CDATA parameter to a DOM CDATASection Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

cdata:CDATA

CDATA to output.

Returns:CDATASection

an org.w3c.dom.CDATASection version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public ProcessingInstruction output(Document basedoc, ProcessingInstruction pi) throws JDOMException

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

pi:ProcessingInstruction

ProcessingInstruction to output.

Returns:ProcessingInstruction

an org.w3c.dom.Element version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Comment output(Document basedoc, Comment comment) throws JDOMException

This converts the JDOM ProcessingInstruction parameter to a DOM ProcessingInstruction, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

comment:Comment

Comment to output.

Returns:Comment

an org.w3c.dom.Comment version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public EntityReference output(Document basedoc, EntityRef entity) throws JDOMException

This converts the JDOM EntityRef parameter to a DOM EntityReference Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

entity:EntityRef

EntityRef to output.

Returns:EntityReference

an org.w3c.dom.EntityReference version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public Attr output(Document basedoc, Attribute attribute) throws JDOMException

This converts the JDOM Attribute parameter to a DOM Attr Node, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

attribute:Attribute

Attribute to output.

Returns:Attr

an org.w3c.dom.Attr version

Exceptions
JDOMException:
if output failed.
Since
JDOM2
outputback to summary
public List<Node> output(Document basedoc, List<? extends Content> list) throws JDOMException

This converts the list of JDOM Content in to a list of DOM Nodes, returning the DOM version. The DOM Node will be linked to an independent DOM Document instance supplied by the current DOMAdapter

Parameters
basedoc:Document

The DOM Document to use for creating DOM Nodes.

list:List<? extends Content>

of JDOM Content to output.

Returns:List<Node>

a List of org.w3c.dom.Node

Exceptions
JDOMException:
if output failed.
Since
JDOM2
setDOMAdapterback to summary
public void setDOMAdapter(DOMAdapter adapter)

Set the DOMAdapter currently set for this DOMOutputter.

Parameters
adapter:DOMAdapter

the new DOMAdapter to use (null implies the default).

Since
JDOM2
setDOMOutputProcessorback to summary
public void setDOMOutputProcessor(DOMOutputProcessor processor)

Set a new DOMOutputProcessor for this DOMOutputter.

Parameters
processor:DOMOutputProcessor

the new processor to set (null implies the default)

Since
JDOM2
setForceNamespaceAwareback to summary
public void setForceNamespaceAware(boolean flag)

Deprecated

All DOMOutputters are now always NamespaceAware.

Controls how NO_NAMESPACE nodes are handled. If true the outputter always creates a namespace aware DOM.

Parameters
flag:boolean

true to force NamespaceAware

Annotations
@Deprecated
setFormatback to summary
public void setFormat(Format format)

Set a new Format instance for this DOMOutputter

Parameters
format:Format

the new Format instance to use (null implies the default)

Since
JDOM2
org.jdom2.output back to summary

private final Class DOMOutputter.DefaultDOMOutputProcessor

extends AbstractDOMOutputProcessor
Class Inheritance

Create a final/concrete instance of the AbstractDOMOutputProcessor. Making it final improves performance.
Author
Rolf Lear

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.jdom2.output.support.AbstractDOMOutputProcessor:
helperContentDispatcherprintAttributeprintCDATAprintCommentprintContentprintDocumentprintElementprintEntityRefprintProcessingInstructionprintTextprocessprocessprocessprocessprocessprocessprocessprocessprocess

Constructor Detail

DefaultDOMOutputProcessorback to summary
private DefaultDOMOutputProcessor()