Class StAXStreamOutputter
- java.lang.Object
-
- org.jdom2.output.StAXStreamOutputter
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class StAXStreamOutputter extends java.lang.Object implements java.lang.CloneableOutputs a JDOM document as a StAX XMLStreamWriter 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:
- 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 XMLStreamWriter before returning, and none of them willclose()the destination.To omit output of the declaration use
. To omit printing of the encoding in the declaration useFormat.setOmitDeclaration(boolean).Format.setOmitEncoding(boolean)If changing the
Formatsettings are insufficient for your output needs you can customise this StAXStreamOutputter further by setting a differentStAXStreamProcessorwith thesetStAXStreamProcessor(StAXStreamProcessor)method or an appropriate constructor. A fully-enabled Abstract classAbstractStAXStreamProcessoris 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
Constructors Constructor Description StAXStreamOutputter()StAXStreamOutputter(Format format)This will create anStAXStreamOutputterwith the specified format characteristics.StAXStreamOutputter(Format format, StAXStreamProcessor processor)This will create anStAXStreamOutputterwith the specified format characteristics.StAXStreamOutputter(StAXStreamProcessor processor)This will create anStAXStreamOutputterwith the specified XMLOutputProcessor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StAXStreamOutputterclone()Returns a cloned copy of this StAXStreamOutputter.FormatgetFormat()Returns the current format in use by the StAXStreamOutputter.StAXStreamProcessorgetStAXStream()Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.voidoutput(java.util.List<? extends Content> list, javax.xml.stream.XMLStreamWriter out)This will handle printing out a list of nodes.voidoutput(CDATA cdata, javax.xml.stream.XMLStreamWriter out)Print out anode.CDATAvoidoutput(Comment comment, javax.xml.stream.XMLStreamWriter out)Print out a.Commentvoidoutput(DocType doctype, javax.xml.stream.XMLStreamWriter out)Print out the.DocTypevoidoutput(Document doc, javax.xml.stream.XMLStreamWriter out)This will print theDocumentto the given Writer.voidoutput(Element element, javax.xml.stream.XMLStreamWriter out)voidoutput(EntityRef entity, javax.xml.stream.XMLStreamWriter out)Print out an.EntityRefvoidoutput(ProcessingInstruction pi, javax.xml.stream.XMLStreamWriter out)Print out a.ProcessingInstructionvoidoutput(Text text, javax.xml.stream.XMLStreamWriter out)Print out anode.TextvoidoutputElementContent(Element element, javax.xml.stream.XMLStreamWriter out)This will handle printing out an's content only, not including its tag, and attributes.ElementvoidsetFormat(Format newFormat)Sets the new format logic for the StAXStreamOutputter.voidsetStAXStreamProcessor(StAXStreamProcessor processor)Sets a new XMLOutputProcessor instance for this StAXStreamOutputter.java.lang.StringtoString()Return a string listing of the settings for this StAXStreamOutputter instance.
-
-
-
Constructor Detail
-
StAXStreamOutputter
public StAXStreamOutputter(Format format, StAXStreamProcessor processor)
This will create anStAXStreamOutputterwith 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.
-
StAXStreamOutputter
public StAXStreamOutputter()
-
StAXStreamOutputter
public StAXStreamOutputter(Format format)
This will create anStAXStreamOutputterwith 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()
-
StAXStreamOutputter
public StAXStreamOutputter(StAXStreamProcessor processor)
This will create anStAXStreamOutputterwith the specified XMLOutputProcessor.- Parameters:
processor- The XMLOutputProcessor to delegate output to. If null the StAXStreamOutputter will use the default XMLOutputProcessor.
-
-
Method Detail
-
setFormat
public void setFormat(Format newFormat)
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()
-
getFormat
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 it's Format changed by changing the settings on the Format instance returned by this method.- Returns:
- the current Format instance used by this StAXStreamOutputter.
-
getStAXStream
public StAXStreamProcessor getStAXStream()
Returns the current XMLOutputProcessor instance in use by the StAXStreamOutputter.- Returns:
- the current XMLOutputProcessor instance.
-
setStAXStreamProcessor
public void setStAXStreamProcessor(StAXStreamProcessor processor)
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
-
output
public final void output(Document doc, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
This will print theDocumentto 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-Documentto format.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(DocType doctype, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out the.DocType- Parameters:
doctype-DocTypeto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(Element element, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
- Parameters:
element-Elementto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
outputElementContent
public final void outputElementContent(Element element, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.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-Elementto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(java.util.List<? extends Content> list, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.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-Listof nodes.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(CDATA cdata, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out anode.CDATA- Parameters:
cdata-CDATAto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(Text text, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out anode. Perfoms the necessary entity escaping and whitespace stripping.Text- Parameters:
text-Textto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(Comment comment, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out a.Comment- Parameters:
comment-Commentto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(ProcessingInstruction pi, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out a.ProcessingInstruction- Parameters:
pi-ProcessingInstructionto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
output
public final void output(EntityRef entity, javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException
Print out an.EntityRef- Parameters:
entity-EntityRefto output.out-XMLStreamWriterto use.- Throws:
javax.xml.stream.XMLStreamException- - if there's any problem writing.java.lang.NullPointerException- if the specified content is null.
-
clone
public StAXStreamOutputter clone()
Returns a cloned copy of this StAXStreamOutputter.- Overrides:
clonein classjava.lang.Object
-
toString
public java.lang.String toString()
Return a string listing of the settings for this StAXStreamOutputter instance.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string listing the settings for this StAXStreamOutputter instance
-
-