Class AbstractStAXEventProcessor
- java.lang.Object
-
- org.jdom2.output.support.AbstractOutputProcessor
-
- org.jdom2.output.support.AbstractStAXEventProcessor
-
- All Implemented Interfaces:
StAXEventProcessor
public abstract class AbstractStAXEventProcessor extends AbstractOutputProcessor implements StAXEventProcessor
This class provides a concrete implementation ofStAXEventProcessorfor supporting theStAXEventOutputter.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
Formatclass 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
NamespaceStackandFormatStackthat are managed in theprintElement(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)andprintContent(XMLEventConsumer, FormatStack, NamespaceStack, XMLEventFactory, Walker)methods, but the FormatStack is pushed through to all print* Methods.- Since:
- JDOM2
- Author:
- Rolf Lear
- See Also:
StAXEventOutputter,StAXEventProcessor
-
-
Constructor Summary
Constructors Constructor Description AbstractStAXEventProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidprintCDATA(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, CDATA cdata)This will handle printing of aCDATA.protected voidprintComment(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, Comment comment)This will handle printing of aComment.protected voidprintContent(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Walker walker)This will handle printing of a List ofContent.protected voidprintDocType(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, DocType docType)This will handle printing of aDocType.protected voidprintDocument(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Document doc)This will handle printing of aDocument.protected voidprintElement(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Element element)This will handle printing of anElement.protected voidprintEntityRef(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, EntityRef entity)This will handle printing of anEntityRef.protected voidprintProcessingInstruction(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, ProcessingInstruction pi)This will handle printing of aProcessingInstruction.protected voidprintText(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, Text text)This will handle printing of aText.voidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, java.util.List<? extends Content> list)This will handle printing out a list of nodes.voidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, CDATA cdata)Print out anode.CDATAvoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Comment comment)Print out a.Commentvoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, DocType doctype)Print out the.DocTypevoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Document doc)This will print theto the given XMLEventConsumer.Documentvoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Element element)voidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, EntityRef entity)Print out a.EntityRefvoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, ProcessingInstruction pi)Print out a.ProcessingInstructionvoidprocess(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Text text)Print out anode.Text-
Methods inherited from class org.jdom2.output.support.AbstractOutputProcessor
buildWalker
-
-
-
-
Method Detail
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Document doc) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorThis will print theto the given XMLEventConsumer.DocumentWarning: 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:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.doc-Documentto format.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, DocType doctype) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out the.DocType- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.doctype-DocTypeto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Element element) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessor- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.element-Elementto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, java.util.List<? extends Content> list) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorThis 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:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.list-Listof nodes.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, CDATA cdata) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out anode.CDATA- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.cdata-CDATAto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Text text) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out anode. Performs the necessary entity escaping and whitespace stripping.Text- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.text-Textto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, Comment comment) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out a.Comment- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.comment-Commentto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, ProcessingInstruction pi) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out a.ProcessingInstruction- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.pi-ProcessingInstructionto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
process
public void process(javax.xml.stream.util.XMLEventConsumer out, Format format, javax.xml.stream.XMLEventFactory eventfactory, EntityRef entity) throws javax.xml.stream.XMLStreamExceptionDescription copied from interface:StAXEventProcessorPrint out a.EntityRef- Specified by:
processin interfaceStAXEventProcessor- Parameters:
out-XMLEventConsumerto use.format-Formatinstance specifying output styleeventfactory-XMLEventFactoryfor creating XMLEvent instances.entity-EntityRefto output.- Throws:
javax.xml.stream.XMLStreamException- if there's any problem writing.
-
printDocument
protected void printDocument(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Document doc) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aDocument.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStacknstack- the NamespaceStackeventfactory- The XMLEventFactory for creating XMLEventsdoc-Documentto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printDocType
protected void printDocType(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, DocType docType) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aDocType.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventsdocType-DocTypeto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printProcessingInstruction
protected void printProcessingInstruction(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, ProcessingInstruction pi) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aProcessingInstruction.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventspi-ProcessingInstructionto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printComment
protected void printComment(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, Comment comment) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aComment.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventscomment-Commentto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printEntityRef
protected void printEntityRef(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, EntityRef entity) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of anEntityRef.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventsentity-EntotyRefto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printCDATA
protected void printCDATA(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, CDATA cdata) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aCDATA.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventscdata-CDATAto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printText
protected void printText(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, javax.xml.stream.XMLEventFactory eventfactory, Text text) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of aText.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStackeventfactory- The XMLEventFactory for creating XMLEventstext-Textto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printElement
protected void printElement(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Element element) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of anElement.This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.
- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStacknstack- the NamespaceStackeventfactory- The XMLEventFactory for creating XMLEventselement-Elementto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
printContent
protected void printContent(javax.xml.stream.util.XMLEventConsumer out, FormatStack fstack, NamespaceStack nstack, javax.xml.stream.XMLEventFactory eventfactory, Walker walker) throws javax.xml.stream.XMLStreamExceptionThis will handle printing of a List ofContent.- Parameters:
out-XMLEventConsumerto use.fstack- the FormatStacknstack- the NamespaceStackeventfactory- The XMLEventFactory for creating XMLEventswalker-WalkerofContentto write.- Throws:
javax.xml.stream.XMLStreamException- if the destination XMLEventConsumer fails
-
-