Top Description Inners Fields Constructors Methods
org.jdom2.output

public final Class StAXEventOutputter

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

Outputs a JDOM document as a StAX XMLEventConsumer 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 XMLEventConsumer 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 StAXEventProcessor with the setStAXEventProcessor(StAXEventProcessor) method or an appropriate constructor. A fully-enabled Abstract class AbstractStAXEventProcessor 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
StAXEventOutputter.DefaultStAXEventProcessor

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

Field Summary

Modifier and TypeField and Description
private static final XMLEventFactory
DEFAULTEVENTFACTORY

This constant StAXEventProcessor is used for all non-customised StAXStreamOutputters

private static final StAXEventOutputter.DefaultStAXEventProcessor
DEFAULTPROCESSOR

This constant StAXEventProcessor is used for all non-customised StAXStreamOutputters

private XMLEventFactory
private Format
private StAXEventProcessor

Constructor Summary

AccessConstructor and Description
public
StAXEventOutputter(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
,
StAXEventProcessor
The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.
processor
,
XMLEventFactory
The factory to use to create XMLEvent instances.
eventfactory
)

This will create an StAXStreamOutputter with the specified format characteristics.

public
StAXEventOutputter()

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

public
StAXEventOutputter(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
StAXEventOutputter(StAXEventProcessor
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.

public
StAXEventOutputter(XMLEventFactory
The XMLEventFactory to use to create XMLEvent instances.
eventfactory
)

This will create an StAXStreamOutputter with the specified XMLOutputProcessor.

Method Summary

Modifier and TypeMethod and Description
public StAXEventOutputter
clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this StAXStreamOutputter.
public XMLEventFactory

Returns:

the current XMLEventFactory used by this StAXEventOutputter
getEventFactory
()

public Format

Returns:

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

Returns the current format in use by the StAXStreamOutputter.

public StAXEventProcessor

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
,
XMLEventConsumer
XMLEventConsumer to use.
out
)

This will print the Document to the given Writer.

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

Print out the DocType.

public final void
output(Element
Element to output.
element
,
XMLEventConsumer
XMLEventConsumer 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
,
XMLEventConsumer
XMLEventConsumer to use.
out
)

This will handle printing out a list of nodes.

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

Print out a CDATA node.

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

Print out a Text node.

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

Print out a Comment.

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

Print out a ProcessingInstruction.

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

Print out an EntityRef.

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

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

public void
setEventFactory(XMLEventFactory
the XMLEventFactory to use for subsequent output.
myEventFactory
)

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

Sets the new format logic for the StAXStreamOutputter.

public void
setStAXEventProcessor(StAXEventProcessor
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

DEFAULTEVENTFACTORYback to summary
private static final XMLEventFactory DEFAULTEVENTFACTORY

This constant StAXEventProcessor is used for all non-customised StAXStreamOutputters

DEFAULTPROCESSORback to summary
private static final StAXEventOutputter.DefaultStAXEventProcessor DEFAULTPROCESSOR

This constant StAXEventProcessor is used for all non-customised StAXStreamOutputters

myEventFactoryback to summary
private XMLEventFactory myEventFactory
myFormatback to summary
private Format myFormat
myProcessorback to summary
private StAXEventProcessor myProcessor

Constructor Detail

StAXEventOutputterback to summary
public StAXEventOutputter(Format format, StAXEventProcessor processor, XMLEventFactory eventfactory)

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:StAXEventProcessor

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

eventfactory:XMLEventFactory

The factory to use to create XMLEvent instances.

StAXEventOutputterback to summary
public StAXEventOutputter()

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

StAXEventOutputterback to summary
public StAXEventOutputter(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()

StAXEventOutputterback to summary
public StAXEventOutputter(StAXEventProcessor processor)

This will create an StAXStreamOutputter with the specified XMLOutputProcessor.

Parameters
processor:StAXEventProcessor

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

StAXEventOutputterback to summary
public StAXEventOutputter(XMLEventFactory eventfactory)

This will create an StAXStreamOutputter with the specified XMLOutputProcessor.

Parameters
eventfactory:XMLEventFactory

The XMLEventFactory to use to create XMLEvent instances.

Method Detail

cloneback to summary
public StAXEventOutputter clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this StAXStreamOutputter.

Returns:StAXEventOutputter

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
getEventFactoryback to summary
public XMLEventFactory getEventFactory()
Returns:XMLEventFactory

the current XMLEventFactory used by this StAXEventOutputter

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 StAXEventProcessor getStAXStream()

Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.

Returns:StAXEventProcessor

the current XMLOutputProcessor instance.

outputback to summary
public final void output(Document doc, XMLEventConsumer 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:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

Print out the DocType.

Parameters
doctype:DocType

DocType to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

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

Parameters
element:Element

Element to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer 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:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

Print out a CDATA node.

Parameters
cdata:CDATA

CDATA to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

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

Parameters
text:Text

Text to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

Print out a Comment.

Parameters
comment:Comment

Comment to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

Print out a ProcessingInstruction.

Parameters
pi:ProcessingInstruction

ProcessingInstruction to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer out) throws XMLStreamException

Print out an EntityRef.

Parameters
entity:EntityRef

EntityRef to output.

out:XMLEventConsumer

XMLEventConsumer 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, XMLEventConsumer 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:XMLEventConsumer

XMLEventConsumer to use.

Exceptions
XMLStreamException:
- if there's any problem writing.
NullPointerException:
if the specified content is null.
setEventFactoryback to summary
public void setEventFactory(XMLEventFactory myEventFactory)
Parameters
myEventFactory:XMLEventFactory

the XMLEventFactory to use for subsequent output.

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()
setStAXEventProcessorback to summary
public void setStAXEventProcessor(StAXEventProcessor processor)

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

Parameters
processor:StAXEventProcessor

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 StAXEventOutputter.DefaultStAXEventProcessor

extends AbstractStAXEventProcessor
Class Inheritance

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

The JDOM user can change the actual XMLOutputProcessor with the StAXEventOutputter#setStAXEventProcessor(StAXEventProcessor) method.

Author
rolf

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.jdom2.output.support.AbstractStAXEventProcessor:
printCDATAprintCommentprintContentprintDocTypeprintDocumentprintElementprintEntityRefprintProcessingInstructionprintTextprocessprocessprocessprocessprocessprocessprocessprocessprocess

Constructor Detail

DefaultStAXEventProcessorback to summary
private DefaultStAXEventProcessor()