Class AbstractStAXStreamProcessor
- java.lang.Object
-
- org.jdom.output.support.AbstractOutputProcessor
-
- org.jdom.output.support.AbstractStAXStreamProcessor
-
- All Implemented Interfaces:
StAXStreamProcessor
public abstract class AbstractStAXStreamProcessor extends AbstractOutputProcessor implements StAXStreamProcessor
This class provides a concrete implementation ofStAXStreamProcessor
for supporting theStAXStreamOutputter
.Overview
This class is marked abstract even though all methods are fully implemented. The
process*(...)
methods are public because they match the StAXStreamProcessor interface but the remaining methods are all protected.People who want to create a custom StAXStreamProcessor for StAXStreamOutputter are able to extend this class and modify any functionality they want. Before sub-classing this you should first check to see if the
Format
class can get you the results you want.Subclasses of this should have reentrant methods. This is easiest to accomplish simply by not allowing any instance fields. If your sub-class has an instance field/variable, then it's probably broken.
The Stacks
One significant feature of this implementation is that it creates and maintains both a
NamespaceStack
andFormatStack
that are managed in theprintElement(XMLStreamWriter, FormatStack, NamespaceStack, Element)
method. The stacks are pushed and popped in that method only. They significantly improve the performance and readability of the code.The NamespaceStack is only sent through to the
printElement(XMLStreamWriter, FormatStack, NamespaceStack, Element)
andprintContent(XMLStreamWriter, FormatStack, NamespaceStack, Walker)
methods, but the FormatStack is pushed through to all print* Methods.- Since:
- JDOM2
- See Also:
StAXStreamOutputter
,StAXStreamProcessor
-
-
Constructor Summary
Constructors Constructor Description AbstractStAXStreamProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
printAttribute(XMLStreamWriter out, FormatStack fstack, Attribute attribute)
This will handle printing of an
.Attribute
protected void
printCDATA(XMLStreamWriter out, FormatStack fstack, CDATA cdata)
This will handle printing of aCDATA
.protected void
printComment(XMLStreamWriter out, FormatStack fstack, Comment comment)
This will handle printing of aComment
.protected void
printContent(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Walker walker)
This will handle printing of a List ofContent
.protected void
printDocType(XMLStreamWriter out, FormatStack fstack, DocType docType)
This will handle printing of aDocType
.protected void
printDocument(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Document doc)
This will handle printing of aDocument
.protected void
printElement(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Element element)
This will handle printing of anElement
.protected void
printEntityRef(XMLStreamWriter out, FormatStack fstack, EntityRef entity)
This will handle printing of anEntityRef
.protected void
printNamespace(XMLStreamWriter out, FormatStack fstack, Namespace ns)
This will handle printing of any needed
declarations.Namespace
protected void
printProcessingInstruction(XMLStreamWriter out, FormatStack fstack, ProcessingInstruction pi)
This will handle printing of aProcessingInstruction
.protected void
printText(XMLStreamWriter out, FormatStack fstack, Text text)
This will handle printing of aText
.void
process(XMLStreamWriter out, Format format, List<? extends Content> list)
This will handle printing out a list of nodes.void
process(XMLStreamWriter out, Format format, CDATA cdata)
Print out a
node.CDATA
void
process(XMLStreamWriter out, Format format, Comment comment)
Print out a
.Comment
void
process(XMLStreamWriter out, Format format, DocType doctype)
Print out the
.DocType
void
process(XMLStreamWriter out, Format format, Document doc)
This will print the
to the given XMLStreamWriter.Document
void
process(XMLStreamWriter out, Format format, Element element)
void
process(XMLStreamWriter out, Format format, EntityRef entity)
Print out a
.EntityRef
void
process(XMLStreamWriter out, Format format, ProcessingInstruction pi)
Print out a
.ProcessingInstruction
void
process(XMLStreamWriter out, Format format, Text text)
Print out a
node.Text
-
Methods inherited from class org.jdom.output.support.AbstractOutputProcessor
buildWalker
-
-
-
-
Method Detail
-
process
public void process(XMLStreamWriter out, Format format, Document doc) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
This will print the
to the given XMLStreamWriter.Document
Warning: using your own XMLStreamWriter 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.
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output styledoc
-Document
to format.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, DocType doctype) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out the
.DocType
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output styledoctype
-DocType
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, Element element) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output styleelement
-Element
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, List<? extends Content> list) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
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>".- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output stylelist
-List
of nodes.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, CDATA cdata) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out a
node.CDATA
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output stylecdata
-CDATA
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, Text text) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out a
node. Perfoms the necessary entity escaping and whitespace stripping.Text
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output styletext
-Text
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, Comment comment) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out a
.Comment
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output stylecomment
-Comment
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, ProcessingInstruction pi) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out a
.ProcessingInstruction
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output stylepi
-ProcessingInstruction
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLStreamWriter out, Format format, EntityRef entity) throws XMLStreamException
Description copied from interface:StAXStreamProcessor
Print out a
.EntityRef
- Specified by:
process
in interfaceStAXStreamProcessor
- Parameters:
out
-XMLStreamWriter
to use.format
-Format
instance specifying output styleentity
-EntityRef
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
printDocument
protected void printDocument(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Document doc) throws XMLStreamException
This will handle printing of aDocument
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStacknstack
- the NamespaceStackdoc
-Document
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printDocType
protected void printDocType(XMLStreamWriter out, FormatStack fstack, DocType docType) throws XMLStreamException
This will handle printing of aDocType
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStackdocType
-DocType
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printProcessingInstruction
protected void printProcessingInstruction(XMLStreamWriter out, FormatStack fstack, ProcessingInstruction pi) throws XMLStreamException
This will handle printing of aProcessingInstruction
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStackpi
-ProcessingInstruction
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printComment
protected void printComment(XMLStreamWriter out, FormatStack fstack, Comment comment) throws XMLStreamException
This will handle printing of aComment
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStackcomment
-Comment
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printEntityRef
protected void printEntityRef(XMLStreamWriter out, FormatStack fstack, EntityRef entity) throws XMLStreamException
This will handle printing of anEntityRef
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStackentity
-EntotyRef
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printCDATA
protected void printCDATA(XMLStreamWriter out, FormatStack fstack, CDATA cdata) throws XMLStreamException
This will handle printing of aCDATA
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStackcdata
-CDATA
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printText
protected void printText(XMLStreamWriter out, FormatStack fstack, Text text) throws XMLStreamException
This will handle printing of aText
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStacktext
-Text
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printElement
protected void printElement(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Element element) throws XMLStreamException
This will handle printing of anElement
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStacknstack
- the NamespaceStackelement
-Element
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printContent
protected void printContent(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Walker walker) throws XMLStreamException
This will handle printing of a List ofContent
.- Parameters:
out
-XMLStreamWriter
to use.fstack
- the FormatStacknstack
- the NamespaceStackwalker
-Walker
ofContent
to write.- Throws:
XMLStreamException
- if the destination XMLStreamWriter fails
-
printNamespace
protected void printNamespace(XMLStreamWriter out, FormatStack fstack, Namespace ns) throws XMLStreamException
This will handle printing of any needed
declarations.Namespace
- Parameters:
out
-XMLStreamWriter
to use.fstack
- The current FormatStackns
-Namespace
to print definition of- Throws:
XMLStreamException
- if the output fails
-
printAttribute
protected void printAttribute(XMLStreamWriter out, FormatStack fstack, Attribute attribute) throws XMLStreamException
This will handle printing of an
.Attribute
- Parameters:
out
-XMLStreamWriter
to use.fstack
- The current FormatStackattribute
-Attribute
to output- Throws:
XMLStreamException
- if the output fails
-
-