public final class StAXEventOutputter
extends java.lang.Object
implements java.lang.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:
Format.getPrettyFormat()
.
Format.getCompactFormat()
.
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.
Constructor and Description |
---|
StAXEventOutputter()
|
StAXEventOutputter(Format format)
This will create an
StAXStreamOutputter with the specified format
characteristics. |
StAXEventOutputter(Format format,
StAXEventProcessor processor,
javax.xml.stream.XMLEventFactory eventfactory)
This will create an
StAXStreamOutputter with the specified format
characteristics. |
StAXEventOutputter(StAXEventProcessor processor)
This will create an
StAXStreamOutputter with the specified
XMLOutputProcessor. |
StAXEventOutputter(javax.xml.stream.XMLEventFactory eventfactory)
This will create an
StAXStreamOutputter with the specified
XMLOutputProcessor. |
Modifier and Type | Method and Description |
---|---|
StAXEventOutputter |
clone()
Returns a cloned copy of this StAXStreamOutputter.
|
javax.xml.stream.XMLEventFactory |
getEventFactory() |
Format |
getFormat()
Returns the current format in use by the StAXStreamOutputter.
|
StAXEventProcessor |
getStAXStream()
Returns the current XMLOutputProcessor instance in use by the
StAXStreamOutputter.
|
void |
output(CDATA cdata,
javax.xml.stream.util.XMLEventConsumer out)
Print out a
node. |
void |
output(Comment comment,
javax.xml.stream.util.XMLEventConsumer out)
Print out a
. |
void |
output(DocType doctype,
javax.xml.stream.util.XMLEventConsumer out)
Print out the
. |
void |
output(Document doc,
javax.xml.stream.util.XMLEventConsumer out)
This will print the
Document to the given Writer. |
void |
output(Element element,
javax.xml.stream.util.XMLEventConsumer out)
|
void |
output(EntityRef entity,
javax.xml.stream.util.XMLEventConsumer out)
Print out an
. |
void |
output(java.util.List<? extends Content> list,
javax.xml.stream.util.XMLEventConsumer out)
This will handle printing out a list of nodes.
|
void |
output(ProcessingInstruction pi,
javax.xml.stream.util.XMLEventConsumer out)
Print out a
. |
void |
output(Text text,
javax.xml.stream.util.XMLEventConsumer out)
Print out a
node. |
void |
outputElementContent(Element element,
javax.xml.stream.util.XMLEventConsumer out)
This will handle printing out an
's content only, not including its tag, and attributes. |
void |
setEventFactory(javax.xml.stream.XMLEventFactory myEventFactory) |
void |
setFormat(Format newFormat)
Sets the new format logic for the StAXStreamOutputter.
|
void |
setStAXEventProcessor(StAXEventProcessor processor)
Sets a new XMLOutputProcessor instance for this StAXStreamOutputter.
|
java.lang.String |
toString()
Return a string listing of the settings for this StAXStreamOutputter instance.
|
public StAXEventOutputter(Format format, StAXEventProcessor processor, javax.xml.stream.XMLEventFactory eventfactory)
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.
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
- The XMLOutputProcessor to delegate output to. If null the
StAXStreamOutputter will use the default XMLOutputProcessor.eventfactory
- The factory to use to create XMLEvent instances.public StAXEventOutputter()
public StAXEventOutputter(Format format)
StAXStreamOutputter
with the specified format
characteristics.
Note: the format object is cloned internally before use.
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()
public StAXEventOutputter(StAXEventProcessor processor)
StAXStreamOutputter
with the specified
XMLOutputProcessor.processor
- The XMLOutputProcessor to delegate output to. If null the
StAXStreamOutputter will use the default XMLOutputProcessor.public StAXEventOutputter(javax.xml.stream.XMLEventFactory eventfactory)
StAXStreamOutputter
with the specified
XMLOutputProcessor.eventfactory
- The XMLEventFactory to use to create XMLEvent instances.public void setFormat(Format newFormat)
newFormat
- the format to use for subsequent outputgetFormat()
public Format getFormat()
public StAXEventProcessor getStAXStream()
public void setStAXEventProcessor(StAXEventProcessor processor)
processor
- the new XMLOutputProcesor to use for outputpublic javax.xml.stream.XMLEventFactory getEventFactory()
public void setEventFactory(javax.xml.stream.XMLEventFactory myEventFactory)
myEventFactory
- the XMLEventFactory to use for subsequent output.public final void output(Document doc, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
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.
doc
- Document
to format.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(DocType doctype, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
DocType
.doctype
- DocType
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(Element element, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
element
- Element
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void outputElementContent(Element element, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
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>".element
- Element
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(java.util.List<? extends Content> list, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
list
- List
of nodes.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(CDATA cdata, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
CDATA
node.cdata
- CDATA
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(Text text, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
Text
node. Performs the necessary entity
escaping and whitespace stripping.text
- Text
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(Comment comment, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
Comment
.comment
- Comment
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(ProcessingInstruction pi, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
ProcessingInstruction
.pi
- ProcessingInstruction
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public final void output(EntityRef entity, javax.xml.stream.util.XMLEventConsumer out) throws javax.xml.stream.XMLStreamException
EntityRef
.entity
- EntityRef
to output.out
- XMLEventConsumer
to use.javax.xml.stream.XMLStreamException
- - if there's any problem writing.java.lang.NullPointerException
- if the specified content is null.public StAXEventOutputter clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2021 Jason Hunter, Brett McLaughlin. All Rights Reserved.