Class StAXEventOutputter
- All Implemented Interfaces:
Cloneable
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:
- For pretty-print output, use
.Format.getPrettyFormat()
- For whitespace-normalised output, use
.Format.getCompactFormat()
- For unmodified-format output, use
.Format.getRawFormat()
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
. To omit printing of the
encoding in the declaration use Format.setOmitDeclaration(boolean)
.
Format.setOmitEncoding(boolean)
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.
- Since:
- JDOM2
- Author:
- Rolf Lear
-
Constructor Summary
ConstructorsConstructorDescriptionStAXEventOutputter
(XMLEventFactory eventfactory) This will create anStAXStreamOutputter
with the specified XMLOutputProcessor.StAXEventOutputter
(Format format) This will create anStAXStreamOutputter
with the specified format characteristics.StAXEventOutputter
(Format format, StAXEventProcessor processor, XMLEventFactory eventfactory) This will create anStAXStreamOutputter
with the specified format characteristics.StAXEventOutputter
(StAXEventProcessor processor) This will create anStAXStreamOutputter
with the specified XMLOutputProcessor. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a cloned copy of this StAXStreamOutputter.Returns the current format in use by the StAXStreamOutputter.Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.final void
output
(List<? extends Content> list, XMLEventConsumer out) This will handle printing out a list of nodes.final void
output
(CDATA cdata, XMLEventConsumer out) Print out a
node.CDATA
final void
output
(Comment comment, XMLEventConsumer out) Print out a
.Comment
final void
output
(DocType doctype, XMLEventConsumer out) Print out the
.DocType
final void
output
(Document doc, XMLEventConsumer out) This will print theDocument
to the given Writer.final void
output
(Element element, XMLEventConsumer out) final void
output
(EntityRef entity, XMLEventConsumer out) Print out an
.EntityRef
final void
output
(ProcessingInstruction pi, XMLEventConsumer out) Print out a
.ProcessingInstruction
final void
output
(Text text, XMLEventConsumer out) Print out a
node.Text
final void
outputElementContent
(Element element, XMLEventConsumer out) This will handle printing out an
's content only, not including its tag, and attributes.Element
void
setEventFactory
(XMLEventFactory myEventFactory) void
Sets the new format logic for the StAXStreamOutputter.void
setStAXEventProcessor
(StAXEventProcessor processor) Sets a new XMLOutputProcessor instance for this StAXStreamOutputter.toString()
Return a string listing of the settings for this StAXStreamOutputter instance.
-
Constructor Details
-
StAXEventOutputter
public StAXEventOutputter(Format format, StAXEventProcessor processor, XMLEventFactory eventfactory) This will create anStAXStreamOutputter
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
- 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 defaultFormat.getRawFormat()
processor
- The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.eventfactory
- The factory to use to create XMLEvent instances.
-
StAXEventOutputter
public StAXEventOutputter() -
StAXEventOutputter
This will create anStAXStreamOutputter
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 StAXStreamOutputter. A null input format indicates that StAXStreamOutputter should use the defaultFormat.getRawFormat()
-
StAXEventOutputter
This will create anStAXStreamOutputter
with the specified XMLOutputProcessor.- Parameters:
processor
- The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.
-
StAXEventOutputter
This will create anStAXStreamOutputter
with the specified XMLOutputProcessor.- Parameters:
eventfactory
- The XMLEventFactory to use to create XMLEvent instances.
-
-
Method Details
-
setFormat
Sets the new format logic for the StAXStreamOutputter. Note the Format object is cloned internally before use.- Parameters:
newFormat
- the format to use for subsequent output- See Also:
-
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:
- the current Format instance used by this StAXStreamOutputter.
-
getStAXStream
Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.- Returns:
- the current XMLOutputProcessor instance.
-
setStAXEventProcessor
Sets a new XMLOutputProcessor instance for this StAXStreamOutputter. Note the processor object is expected to be thread-safe.- Parameters:
processor
- the new XMLOutputProcesor to use for output
-
getEventFactory
- Returns:
- the current XMLEventFactory used by this StAXEventOutputter
-
setEventFactory
- Parameters:
myEventFactory
- the XMLEventFactory to use for subsequent output.
-
output
This will print theDocument
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
to format.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out the
.DocType
- Parameters:
doctype
-DocType
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
- Parameters:
element
-Element
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
outputElementContent
public final void outputElementContent(Element element, XMLEventConsumer out) throws XMLStreamException This will handle printing out an
'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>".Element
- Parameters:
element
-Element
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
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
of nodes.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out a
node.CDATA
- Parameters:
cdata
-CDATA
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out a
node. Performs the necessary entity escaping and whitespace stripping.Text
- Parameters:
text
-Text
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out a
.Comment
- Parameters:
comment
-Comment
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out a
.ProcessingInstruction
- Parameters:
pi
-ProcessingInstruction
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
output
Print out an
.EntityRef
- Parameters:
entity
-EntityRef
to output.out
-XMLEventConsumer
to use.- Throws:
XMLStreamException
- - if there's any problem writing.NullPointerException
- if the specified content is null.
-
clone
Returns a cloned copy of this StAXStreamOutputter. -
toString
Return a string listing of the settings for this StAXStreamOutputter instance.
-