Top Description Inners Fields Constructors Methods
org.jdom2.output

public final Class StAXStreamOutputter

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.util.List, javax.xml.stream.XMLStreamException, .XMLStreamWriter, org.jdom2.Attribute, .CDATA, .Comment, .Content, .DocType, .Document, .Element, .EntityRef, .ProcessingInstruction, .Text, org.jdom2.output.support.AbstractStAXStreamProcessor, .StAXStreamProcessor, .XMLOutputProcessor

Outputs a JDOM document as a StAX XMLStreamWriter of bytes.

The StAXStreamOutputter can manage many styles of document formatting, from untouched to 'pretty' printed. The default is to output the document content exactly as created, but this can be changed by setting a new Format object:

All of the output*(...) methods will flush the destination XMLStreamWriter before returning, and none of them will close() the destination.

To omit output of the declaration use Format#setOmitDeclaration. To omit printing of the encoding in the declaration use Format#setOmitEncoding.

If changing the Format settings are insufficient for your output needs you can customise this StAXStreamOutputter further by setting a different StAXStreamProcessor with the setStAXStreamProcessor(StAXStreamProcessor) method or an appropriate constructor. A fully-enabled Abstract class AbstractStAXStreamProcessor is available to be further extended to your needs if all you want to do is tweak some details.

Author
Rolf Lear
Since
JDOM2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StAXStreamOutputter.DefaultStAXStreamProcessor

Create a final and static instance of the AbstractStAXStreamProcessor The final part is important because it improves performance.

Field Summary

Modifier and TypeField and Description
private static final StAXStreamOutputter.DefaultStAXStreamProcessor
DEFAULTPROCESSOR

This constant StAXStreamProcessor is used for all non-customised StAXStreamOutputters

private Format
private StAXStreamProcessor

Constructor Summary

AccessConstructor and Description
public
StAXStreamOutputter(Format
The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this StAXStreamOutputter. A null input format indicates that StAXStreamOutputter should use the default Format#getRawFormat()
format
,
StAXStreamProcessor
The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.
processor
)

This will create an StAXStreamOutputter with the specified format characteristics.

public
StAXStreamOutputter()

This will create an StAXStreamOutputter with a default Format and XMLOutputProcessor.

public
StAXStreamOutputter(Format
The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this StAXStreamOutputter. A null input format indicates that StAXStreamOutputter should use the default Format#getRawFormat()
format
)

This will create an StAXStreamOutputter with the specified format characteristics.

public
StAXStreamOutputter(StAXStreamProcessor
The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.
processor
)

This will create an StAXStreamOutputter with the specified XMLOutputProcessor.

Method Summary

Modifier and TypeMethod and Description
public StAXStreamOutputter
clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this StAXStreamOutputter.
public Format

Returns:

the current Format instance used by this StAXStreamOutputter.
getFormat
()

Returns the current format in use by the StAXStreamOutputter.

public StAXStreamProcessor

Returns:

the current XMLOutputProcessor instance.
getStAXStream
()

Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.

public final void
output(Document
Document to format.
doc
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

This will print the Document to the given Writer.

public final void
output(DocType
DocType to output.
doctype
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out the DocType.

public final void
output(Element
Element to output.
element
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out an Element, including its Attributes, and all contained (child) elements, etc.

public final void
output(List<? extends Content>
List of nodes.
list
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

This will handle printing out a list of nodes.

public final void
output(CDATA
CDATA to output.
cdata
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out a CDATA node.

public final void
output(Text
Text to output.
text
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out a Text node.

public final void
output(Comment
Comment to output.
comment
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out a Comment.

public final void
output(ProcessingInstruction
ProcessingInstruction to output.
pi
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out a ProcessingInstruction.

public final void
output(EntityRef
EntityRef to output.
entity
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

Print out an EntityRef.

public final void
outputElementContent(Element
Element to output.
element
,
XMLStreamWriter
XMLStreamWriter to use.
out
)

This will handle printing out an Element's content only, not including its tag, and attributes.

public void
setFormat(Format
the format to use for subsequent output
newFormat
)

Sets the new format logic for the StAXStreamOutputter.

public void
setStAXStreamProcessor(StAXStreamProcessor
the new XMLOutputProcesor to use for output
processor
)

Sets a new XMLOutputProcessor instance for this StAXStreamOutputter.

public String

Returns:

a string listing the settings for this StAXStreamOutputter instance
toString
()

Overrides java.lang.Object.toString.

Return a string listing of the settings for this StAXStreamOutputter instance.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULTPROCESSORback to summary
private static final StAXStreamOutputter.DefaultStAXStreamProcessor DEFAULTPROCESSOR

This constant StAXStreamProcessor is used for all non-customised StAXStreamOutputters

myFormatback to summary
private Format myFormat
myProcessorback to summary
private StAXStreamProcessor myProcessor

Constructor Detail

StAXStreamOutputterback to summary
public StAXStreamOutputter(Format format, StAXStreamProcessor processor)

This will create an StAXStreamOutputter with the specified format characteristics.

Note

the format object is cloned internally before use. If you want to modify the Format after constructing the StAXStreamOutputter you can modify the Format instance getFormat() returns.

Parameters
format:Format

The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this StAXStreamOutputter. A null input format indicates that StAXStreamOutputter should use the default Format#getRawFormat()

processor:StAXStreamProcessor

The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.

StAXStreamOutputterback to summary
public StAXStreamOutputter()

This will create an StAXStreamOutputter with a default Format and XMLOutputProcessor.

StAXStreamOutputterback to summary
public StAXStreamOutputter(Format format)

This will create an StAXStreamOutputter with the specified format characteristics.

Note

the format object is cloned internally before use.

Parameters
format:Format

The Format instance to use. This instance will be cloned() and as a consequence, changes made to the specified format instance will not be reflected in this StAXStreamOutputter. A null input format indicates that StAXStreamOutputter should use the default Format#getRawFormat()

StAXStreamOutputterback to summary
public StAXStreamOutputter(StAXStreamProcessor processor)

This will create an StAXStreamOutputter with the specified XMLOutputProcessor.

Parameters
processor:StAXStreamProcessor

The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.

Method Detail

cloneback to summary
public StAXStreamOutputter clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this StAXStreamOutputter.

Returns:StAXStreamOutputter

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
getFormatback to summary
public Format getFormat()

Returns the current format in use by the StAXStreamOutputter. Note the Format object returned is not a clone of the one used internally, thus, an StAXStreamOutputter instance is able to have its Format changed by changing the settings on the Format instance returned by this method.

Returns:Format

the current Format instance used by this StAXStreamOutputter.

getStAXStreamback to summary
public StAXStreamProcessor getStAXStream()

Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.

Returns:StAXStreamProcessor

the current XMLOutputProcessor instance.

outputback to summary
public final void output(Document doc, XMLStreamWriter out) throws XMLStreamException

This will print the Document to the given Writer.

Warning

using your own Writer 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.

Parameters
doc:Document

Document to format.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(DocType doctype, XMLStreamWriter out) throws XMLStreamException

Print out the DocType.

Parameters
doctype:DocType

DocType to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(Element element, XMLStreamWriter out) throws XMLStreamException

Print out an Element, including its Attributes, and all contained (child) elements, etc.

Parameters
element:Element

Element to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(List<? extends Content> list, XMLStreamWriter out) throws XMLStreamException

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>".

Parameters
list:List<? extends Content>

List of nodes.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(CDATA cdata, XMLStreamWriter out) throws XMLStreamException

Print out a CDATA node.

Parameters
cdata:CDATA

CDATA to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(Text text, XMLStreamWriter out) throws XMLStreamException

Print out a Text node. Performs the necessary entity escaping and whitespace stripping.

Parameters
text:Text

Text to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(Comment comment, XMLStreamWriter out) throws XMLStreamException

Print out a Comment.

Parameters
comment:Comment

Comment to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(ProcessingInstruction pi, XMLStreamWriter out) throws XMLStreamException

Print out a ProcessingInstruction.

Parameters
pi:ProcessingInstruction

ProcessingInstruction to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputback to summary
public final void output(EntityRef entity, XMLStreamWriter out) throws XMLStreamException

Print out an EntityRef.

Parameters
entity:EntityRef

EntityRef to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
outputElementContentback to summary
public final void outputElementContent(Element element, XMLStreamWriter out) throws XMLStreamException

This will handle printing out an Element's content only, not including its tag, and attributes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".

Parameters
element:Element

Element to output.

out:XMLStreamWriter

XMLStreamWriter to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
setFormatback to summary
public void setFormat(Format newFormat)

Sets the new format logic for the StAXStreamOutputter. Note the Format object is cloned internally before use.

Parameters
newFormat:Format

the format to use for subsequent output

See Also
getFormat()
setStAXStreamProcessorback to summary
public void setStAXStreamProcessor(StAXStreamProcessor processor)

Sets a new XMLOutputProcessor instance for this StAXStreamOutputter. Note the processor object is expected to be thread-safe.

Parameters
processor:StAXStreamProcessor

the new XMLOutputProcesor to use for output

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string listing of the settings for this StAXStreamOutputter instance.

Returns:String

a string listing the settings for this StAXStreamOutputter instance

Annotations
@Override
org.jdom2.output back to summary

private final Class StAXStreamOutputter.DefaultStAXStreamProcessor

extends AbstractStAXStreamProcessor
Class Inheritance

Create a final and static instance of the AbstractStAXStreamProcessor The final part is important because it improves performance.

The JDOM user can change the actual XMLOutputProcessor with the StAXStreamOutputter#setStAXStreamProcessor(StAXStreamProcessor) method.

Author
rolf

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.jdom2.output.support.AbstractStAXStreamProcessor:
printAttributeprintCDATAprintCommentprintContentprintDocTypeprintDocumentprintElementprintEntityRefprintNamespaceprintProcessingInstructionprintTextprocessprocessprocessprocessprocessprocessprocessprocessprocess

Constructor Detail

DefaultStAXStreamProcessorback to summary
private DefaultStAXStreamProcessor()