Class StAXStreamReader
- java.lang.Object
-
- org.jdom2.output.StAXStreamReader
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class StAXStreamReader extends java.lang.Object implements java.lang.Cloneable
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:
- For pretty-print output, use
.Format.getPrettyFormat()
- For whitespace-normalised output, use
.Format.getCompactFormat()
- For unmodified-format output, use
.Format.getRawFormat()
There is only one
method that exposes a JDOM Document as a StAX Stream.output(Document)
If changing the
Format
settings are insufficient for your output needs you can customise this StAXStreamReader further by setting a differentStAXStreamReaderProcessor
with thesetStAXAsStreamProcessor(StAXStreamReaderProcessor)
method or an appropriate constructor. A fully-enabled Abstract classAbstractStAXStreamReaderProcessor
is available to be further extended to your needs if all you want to do is tweak some details.- Since:
- JDOM 2.1.0
- Author:
- Rolf Lear
-
-
Constructor Summary
Constructors Constructor Description StAXStreamReader()
StAXStreamReader(Format format)
This will create anXMLOutputter
with the specified format characteristics.StAXStreamReader(Format format, StAXStreamReaderProcessor processor)
This will create anXMLOutputter
with the specified format characteristics.StAXStreamReader(StAXStreamReader that)
This will create anXMLOutputter
with the same customisations set in the givenXMLOutputter
instance.StAXStreamReader(StAXStreamReaderProcessor processor)
This will create anXMLOutputter
with the specified XMLOutputProcessor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StAXStreamReader
clone()
Returns a cloned copy of this XMLOutputter.Format
getFormat()
Returns the current format in use by the XMLOutputter.StAXStreamReaderProcessor
getStAXAsStreamProcessor()
Returns the current XMLOutputProcessor instance in use by the StAXStreamReader.javax.xml.stream.XMLStreamReader
output(Document doc)
This will expose the
as a StAX XMLStreamReader.Document
void
setFormat(Format newFormat)
Sets the new format logic for the XMLOutputter.void
setStAXAsStreamProcessor(StAXStreamReaderProcessor processor)
Sets a new StAXStreamReaderProcessor instance for this StAXStreamReader.java.lang.String
toString()
Return a string listing of the settings for this XMLOutputter instance.
-
-
-
Constructor Detail
-
StAXStreamReader
public StAXStreamReader(Format format, StAXStreamReaderProcessor processor)
This will create anXMLOutputter
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
- 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 defaultFormat.getRawFormat()
processor
- The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
-
StAXStreamReader
public StAXStreamReader()
-
StAXStreamReader
public StAXStreamReader(StAXStreamReader that)
This will create anXMLOutputter
with the same customisations set in the givenXMLOutputter
instance. Note thatXMLOutputter two = one.clone();
would work equally well.- Parameters:
that
- the XMLOutputter to clone
-
StAXStreamReader
public StAXStreamReader(Format format)
This will create anXMLOutputter
with the specified format characteristics.Note: the format object is cloned internally before use.
- Parameters:
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 defaultFormat.getRawFormat()
-
StAXStreamReader
public StAXStreamReader(StAXStreamReaderProcessor processor)
This will create anXMLOutputter
with the specified XMLOutputProcessor.- Parameters:
processor
- The XMLOutputProcessor to delegate output to. If null the XMLOutputter will use the default XMLOutputProcessor.
-
-
Method Detail
-
setFormat
public void setFormat(Format newFormat)
Sets the new format logic for the XMLOutputter. Note the Format object is cloned internally before use.- Parameters:
newFormat
- the format to use for subsequent output- See Also:
getFormat()
-
getFormat
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:
- the current Format instance used by this XMLOutputter.
-
getStAXAsStreamProcessor
public StAXStreamReaderProcessor getStAXAsStreamProcessor()
Returns the current XMLOutputProcessor instance in use by the StAXStreamReader.- Returns:
- the current XMLOutputProcessor instance.
-
setStAXAsStreamProcessor
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
- the new XMLOutputProcesor to use for output
-
output
public final javax.xml.stream.XMLStreamReader output(Document doc)
This will expose the
as a StAX XMLStreamReader.Document
- Parameters:
doc
-Document
to format.- Returns:
- The XMLStreamReader representing the input Document.
- Throws:
java.lang.NullPointerException
- if the specified content is null.
-
clone
public StAXStreamReader clone()
Returns a cloned copy of this XMLOutputter.- Overrides:
clone
in classjava.lang.Object
-
toString
public java.lang.String toString()
Return a string listing of the settings for this XMLOutputter instance.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string listing the settings for this XMLOutputter instance
-
-