Class AbstractStAXEventProcessor
- All Implemented Interfaces:
StAXEventProcessor
StAXEventProcessor
for supporting the StAXEventOutputter
.
Overview
This class is marked abstract even though all methods are fully implemented.
The process*(...)
methods are public because they match the
StAXEventProcessor interface but the remaining methods are all protected.
People who want to create a custom StAXEventProcessor for StAXEventOutputter 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
and FormatStack
that are
managed in the
printElement(XMLEventConsumer, FormatStack, NamespaceStack, XMLEventFactory, 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(XMLEventConsumer, FormatStack, NamespaceStack, XMLEventFactory, Element)
and
printContent(XMLEventConsumer, FormatStack, NamespaceStack, XMLEventFactory, Walker)
methods, but
the FormatStack is pushed through to all print* Methods.
- Since:
- JDOM2
- Author:
- Rolf Lear
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
printCDATA
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, CDATA cdata) This will handle printing of aCDATA
.protected void
printComment
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, Comment comment) This will handle printing of aComment
.protected void
printContent
(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Walker walker) This will handle printing of a List ofContent
.protected void
printDocType
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, DocType docType) This will handle printing of aDocType
.protected void
printDocument
(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Document doc) This will handle printing of aDocument
.protected void
printElement
(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Element element) This will handle printing of anElement
.protected void
printEntityRef
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, EntityRef entity) This will handle printing of anEntityRef
.protected void
printProcessingInstruction
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, ProcessingInstruction pi) This will handle printing of aProcessingInstruction
.protected void
printText
(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, Text text) This will handle printing of aText
.void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, List<? extends Content> list) This will handle printing out a list of nodes.void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, CDATA cdata) Print out a
node.CDATA
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Comment comment) Print out a
.Comment
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, DocType doctype) Print out the
.DocType
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Document doc) This will print the
to the given XMLEventConsumer.Document
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Element element) void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, EntityRef entity) Print out a
.EntityRef
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, ProcessingInstruction pi) Print out a
.ProcessingInstruction
void
process
(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Text text) Print out a
node.Text
Methods inherited from class org.jdom2.output.support.AbstractOutputProcessor
buildWalker
-
Constructor Details
-
AbstractStAXEventProcessor
public AbstractStAXEventProcessor()
-
-
Method Details
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Document doc) throws XMLStreamException Description copied from interface:StAXEventProcessor
This will print the
to the given XMLEventConsumer.Document
Warning: using your own XMLEventConsumer 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 interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.doc
-Document
to format.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, DocType doctype) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out the
.DocType
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.doctype
-DocType
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Element element) throws XMLStreamException Description copied from interface:StAXEventProcessor
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.element
-Element
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, List<? extends Content> list) throws XMLStreamException Description copied from interface:StAXEventProcessor
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 interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.list
-List
of nodes.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, CDATA cdata) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out a
node.CDATA
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.cdata
-CDATA
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Text text) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out a
node. Performs the necessary entity escaping and whitespace stripping.Text
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.text
-Text
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, Comment comment) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out a
.Comment
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.comment
-Comment
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, ProcessingInstruction pi) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out a
.ProcessingInstruction
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.pi
-ProcessingInstruction
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
process
public void process(XMLEventConsumer out, Format format, XMLEventFactory eventfactory, EntityRef entity) throws XMLStreamException Description copied from interface:StAXEventProcessor
Print out a
.EntityRef
- Specified by:
process
in interfaceStAXEventProcessor
- Parameters:
out
-XMLEventConsumer
to use.format
-Format
instance specifying output styleeventfactory
-XMLEventFactory
for creating XMLEvent instances.entity
-EntityRef
to output.- Throws:
XMLStreamException
- if there's any problem writing.
-
printDocument
protected void printDocument(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Document doc) throws XMLStreamException This will handle printing of aDocument
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStacknstack
- the NamespaceStackeventfactory
- The XMLEventFactory for creating XMLEventsdoc
-Document
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printDocType
protected void printDocType(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, DocType docType) throws XMLStreamException This will handle printing of aDocType
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventsdocType
-DocType
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printProcessingInstruction
protected void printProcessingInstruction(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, ProcessingInstruction pi) throws XMLStreamException This will handle printing of aProcessingInstruction
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventspi
-ProcessingInstruction
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printComment
protected void printComment(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, Comment comment) throws XMLStreamException This will handle printing of aComment
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventscomment
-Comment
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printEntityRef
protected void printEntityRef(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, EntityRef entity) throws XMLStreamException This will handle printing of anEntityRef
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventsentity
-EntotyRef
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printCDATA
protected void printCDATA(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, CDATA cdata) throws XMLStreamException This will handle printing of aCDATA
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventscdata
-CDATA
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printText
protected void printText(XMLEventConsumer out, FormatStack fstack, XMLEventFactory eventfactory, Text text) throws XMLStreamException This will handle printing of aText
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStackeventfactory
- The XMLEventFactory for creating XMLEventstext
-Text
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printElement
protected void printElement(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Element element) throws XMLStreamException This will handle printing of anElement
.This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.
- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStacknstack
- the NamespaceStackeventfactory
- The XMLEventFactory for creating XMLEventselement
-Element
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-
printContent
protected void printContent(XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, XMLEventFactory eventfactory, Walker walker) throws XMLStreamException This will handle printing of a List ofContent
.- Parameters:
out
-XMLEventConsumer
to use.fstack
- the FormatStacknstack
- the NamespaceStackeventfactory
- The XMLEventFactory for creating XMLEventswalker
-Walker
ofContent
to write.- Throws:
XMLStreamException
- if the destination XMLEventConsumer fails
-