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 ofStAXStreamProcessorfor 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
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(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 voidprintAttribute(XMLStreamWriter out, FormatStack fstack, Attribute attribute)This will handle printing of an.Attributeprotected voidprintCDATA(XMLStreamWriter out, FormatStack fstack, CDATA cdata)This will handle printing of aCDATA.protected voidprintComment(XMLStreamWriter out, FormatStack fstack, Comment comment)This will handle printing of aComment.protected voidprintContent(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Walker walker)This will handle printing of a List ofContent.protected voidprintDocType(XMLStreamWriter out, FormatStack fstack, DocType docType)This will handle printing of aDocType.protected voidprintDocument(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Document doc)This will handle printing of aDocument.protected voidprintElement(XMLStreamWriter out, FormatStack fstack, NamespaceStack nstack, Element element)This will handle printing of anElement.protected voidprintEntityRef(XMLStreamWriter out, FormatStack fstack, EntityRef entity)This will handle printing of anEntityRef.protected voidprintNamespace(XMLStreamWriter out, FormatStack fstack, Namespace ns)This will handle printing of any neededdeclarations.Namespaceprotected voidprintProcessingInstruction(XMLStreamWriter out, FormatStack fstack, ProcessingInstruction pi)This will handle printing of aProcessingInstruction.protected voidprintText(XMLStreamWriter out, FormatStack fstack, Text text)This will handle printing of aText.voidprocess(XMLStreamWriter out, Format format, List<? extends Content> list)This will handle printing out a list of nodes.voidprocess(XMLStreamWriter out, Format format, CDATA cdata)Print out anode.CDATAvoidprocess(XMLStreamWriter out, Format format, Comment comment)Print out a.Commentvoidprocess(XMLStreamWriter out, Format format, DocType doctype)Print out the.DocTypevoidprocess(XMLStreamWriter out, Format format, Document doc)This will print theto the given XMLStreamWriter.Documentvoidprocess(XMLStreamWriter out, Format format, Element element)voidprocess(XMLStreamWriter out, Format format, EntityRef entity)Print out a.EntityRefvoidprocess(XMLStreamWriter out, Format format, ProcessingInstruction pi)Print out a.ProcessingInstructionvoidprocess(XMLStreamWriter out, Format format, Text text)Print out anode.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:StAXStreamProcessorThis will print theto the given XMLStreamWriter.DocumentWarning: 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:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output styledoc-Documentto 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:StAXStreamProcessorPrint out the.DocType- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output styledoctype-DocTypeto 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:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output styleelement-Elementto 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:StAXStreamProcessorThis 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 interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output stylelist-Listof 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:StAXStreamProcessorPrint out anode.CDATA- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output stylecdata-CDATAto 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:StAXStreamProcessorPrint out anode. Perfoms the necessary entity escaping and whitespace stripping.Text- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output styletext-Textto 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:StAXStreamProcessorPrint out a.Comment- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output stylecomment-Commentto 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:StAXStreamProcessorPrint out a.ProcessingInstruction- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output stylepi-ProcessingInstructionto 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:StAXStreamProcessorPrint out a.EntityRef- Specified by:
processin interfaceStAXStreamProcessor- Parameters:
out-XMLStreamWriterto use.format-Formatinstance specifying output styleentity-EntityRefto 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-XMLStreamWriterto use.fstack- the FormatStacknstack- the NamespaceStackdoc-Documentto 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-XMLStreamWriterto use.fstack- the FormatStackdocType-DocTypeto 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-XMLStreamWriterto use.fstack- the FormatStackpi-ProcessingInstructionto 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-XMLStreamWriterto use.fstack- the FormatStackcomment-Commentto 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-XMLStreamWriterto use.fstack- the FormatStackentity-EntotyRefto 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-XMLStreamWriterto use.fstack- the FormatStackcdata-CDATAto 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-XMLStreamWriterto use.fstack- the FormatStacktext-Textto 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-XMLStreamWriterto use.fstack- the FormatStacknstack- the NamespaceStackelement-Elementto 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-XMLStreamWriterto use.fstack- the FormatStacknstack- the NamespaceStackwalker-WalkerofContentto 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 neededdeclarations.Namespace- Parameters:
out-XMLStreamWriterto use.fstack- The current FormatStackns-Namespaceto 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-XMLStreamWriterto use.fstack- The current FormatStackattribute-Attributeto output- Throws:
XMLStreamException- if the output fails
-
-