Top Description Inners Fields Constructors Methods
org.jdom2.output

public final Class StAXStreamReader

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
javax.xml.stream.XMLStreamReader, org.jdom2.Document, org.jdom2.output.support.AbstractStAXStreamReaderProcessor, .StAXStreamReaderProcessor

Represents a JDOM document as a StAX XMLStreamReader that can be read from.

The StAXStreamReader 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:

There is only one output(Document) method that exposes a JDOM Document as a StAX Stream.

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

Author
Rolf Lear
Since
JDOM 2.1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StAXStreamReader.DefaultStAXAsStreamProcessor

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

Field Summary

Modifier and TypeField and Description
private static final StAXStreamReader.DefaultStAXAsStreamProcessor
DEFAULTPROCESSOR

This constant XMLOutputProcessor is used for all non-customised XMLOutputters

private Format
private StAXStreamReaderProcessor

Constructor Summary

AccessConstructor and Description
public
StAXStreamReader(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 XMLOutputter. A null input format indicates that XMLOutputter should use the default Format#getRawFormat()
format
,
StAXStreamReaderProcessor
The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
processor
)

This will create an XMLOutputter with the specified format characteristics.

public
StAXStreamReader()

This will create an XMLOutputter with a default Format and StAXStreamReaderProcessor.

public
StAXStreamReader(StAXStreamReader
the XMLOutputter to clone
that
)

This will create an XMLOutputter with the same customisations set in the given XMLOutputter instance.

public
StAXStreamReader(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 XMLOutputter. A null input format indicates that XMLOutputter should use the default Format#getRawFormat()
format
)

This will create an XMLOutputter with the specified format characteristics.

public
StAXStreamReader(StAXStreamReaderProcessor
The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
processor
)

This will create an XMLOutputter with the specified XMLOutputProcessor.

Method Summary

Modifier and TypeMethod and Description
public StAXStreamReader
clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this XMLOutputter.
public Format

Returns:

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

Returns the current format in use by the XMLOutputter.

public StAXStreamReaderProcessor

Returns:

the current XMLOutputProcessor instance.
getStAXAsStreamProcessor
()

Returns the current XMLOutputProcessor instance in use by the StAXStreamReader.

public final XMLStreamReader

Returns:

The XMLStreamReader representing the input Document.
output
(Document
Document to format.
doc
)

This will expose the Document as a StAX XMLStreamReader.

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

Sets the new format logic for the XMLOutputter.

public void
setStAXAsStreamProcessor(StAXStreamReaderProcessor
the new XMLOutputProcesor to use for output
processor
)

Sets a new StAXStreamReaderProcessor instance for this StAXStreamReader.

public String

Returns:

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

Overrides java.lang.Object.toString.

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

Field Detail

DEFAULTPROCESSORback to summary
private static final StAXStreamReader.DefaultStAXAsStreamProcessor DEFAULTPROCESSOR

This constant XMLOutputProcessor is used for all non-customised XMLOutputters

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

Constructor Detail

StAXStreamReaderback to summary
public StAXStreamReader(Format format, StAXStreamReaderProcessor processor)

This will create an XMLOutputter with the specified format characteristics.

Note

the format object is cloned internally before use. If you want to modify the Format after constructing the XMLOutputter 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 XMLOutputter. A null input format indicates that XMLOutputter should use the default Format#getRawFormat()

processor:StAXStreamReaderProcessor

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

StAXStreamReaderback to summary
public StAXStreamReader()

This will create an XMLOutputter with a default Format and StAXStreamReaderProcessor.

StAXStreamReaderback to summary
public StAXStreamReader(StAXStreamReader that)

This will create an XMLOutputter with the same customisations set in the given XMLOutputter instance. Note that XMLOutputter two = one.clone(); would work equally well.

Parameters
that:StAXStreamReader

the XMLOutputter to clone

StAXStreamReaderback to summary
public StAXStreamReader(Format format)

This will create an XMLOutputter 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 XMLOutputter. A null input format indicates that XMLOutputter should use the default Format#getRawFormat()

StAXStreamReaderback to summary
public StAXStreamReader(StAXStreamReaderProcessor processor)

This will create an XMLOutputter with the specified XMLOutputProcessor.

Parameters
processor:StAXStreamReaderProcessor

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

Method Detail

cloneback to summary
public StAXStreamReader clone()

Overrides java.lang.Object.clone.

Returns a cloned copy of this XMLOutputter.

Returns:StAXStreamReader

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 XMLOutputter. Note the Format object returned is not a clone of the one used internally, thus, an XMLOutputter 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 XMLOutputter.

getStAXAsStreamProcessorback to summary
public StAXStreamReaderProcessor getStAXAsStreamProcessor()

Returns the current XMLOutputProcessor instance in use by the StAXStreamReader.

Returns:StAXStreamReaderProcessor

the current XMLOutputProcessor instance.

outputback to summary
public final XMLStreamReader output(Document doc)

This will expose the Document as a StAX XMLStreamReader.

Parameters
doc:Document

Document to format.

Returns:XMLStreamReader

The XMLStreamReader representing the input Document.

Exceptions
NullPointerException:
if the specified content is null.
setFormatback to summary
public void setFormat(Format newFormat)

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

Parameters
newFormat:Format

the format to use for subsequent output

See Also
getFormat()
setStAXAsStreamProcessorback to summary
public void setStAXAsStreamProcessor(StAXStreamReaderProcessor processor)

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

Parameters
processor:StAXStreamReaderProcessor

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 XMLOutputter instance.

Returns:String

a string listing the settings for this XMLOutputter instance

Annotations
@Override
org.jdom2.output back to summary

private final Class StAXStreamReader.DefaultStAXAsStreamProcessor

extends AbstractStAXStreamReaderProcessor
Class Inheritance

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

The JDOM user can change the actual XMLOutputProcessor with the StAXStreamReader#setStAXAsStreamProcessor(StAXStreamReaderProcessor) method.

Author
rolf

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.jdom2.output.support.AbstractStAXStreamReaderProcessor:
buildReader

Constructor Detail

DefaultStAXAsStreamProcessorback to summary
private DefaultStAXAsStreamProcessor()