Top Description Constructors Methods
org.jdom2.output.support

public abstract Class AbstractStAXStreamProcessor

extends AbstractOutputProcessor
implements StAXStreamProcessor
Class Inheritance
All Implemented Interfaces
org.jdom2.output.support.StAXStreamProcessor
Known Direct Subclasses
org.jdom2.output.StAXStreamOutputter.DefaultStAXStreamProcessor
Imports
java.io.StringWriter, java.util.ArrayList, .Collections, .List, javax.xml.stream.XMLStreamException, .XMLStreamWriter, org.jdom2.Attribute, .CDATA, .Comment, .Content, .JDOMConstants, .Content.CType, .DocType, .Document, .Element, .EntityRef, .Namespace, .ProcessingInstruction, .Text, .Verifier, org.jdom2.output.Format, .Format.TextMode, .StAXStreamOutputter, org.jdom2.util.NamespaceStack

This class provides a concrete implementation of StAXStreamProcessor for supporting the StAXStreamOutputter.

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 and FormatStack that are managed in the printElement(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) and printContent(XMLStreamWriter, FormatStack, NamespaceStack, Walker) methods, but the FormatStack is pushed through to all print* Methods.

An interesting read for people using this class: Apache Axiom notes on setPrefix().

Author
Rolf Lear
Since
JDOM2
See Also
StAXStreamOutputter, StAXStreamProcessor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
printAttribute(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
The current FormatStack
fstack
,
final Attribute
Attribute to output
attribute
)

This will handle printing of an Attribute.

protected void
printCDATA(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final CDATA
CDATA to write.
cdata
)

This will handle printing of a CDATA.

protected void
printComment(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final Comment
Comment to write.
comment
)

This will handle printing of a Comment.

protected void
printContent(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Walker
Walker of Content to write.
walker
)

This will handle printing of a List of Content.

protected void
printDocType(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final DocType
DocType to write.
docType
)

This will handle printing of a DocType.

protected void
printDocument(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Document
Document to write.
doc
)

This will handle printing of a Document.

protected void
printElement(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final Element
Element to write.
element
)

This will handle printing of an Element.

protected void
printEntityRef(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final EntityRef
EntotyRef to write.
entity
)

This will handle printing of an EntityRef.

protected void
printNamespace(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
The current FormatStack
fstack
,
final Namespace
Namespace to print definition of
ns
)

This will handle printing of any needed Namespace declarations.

protected void
printProcessingInstruction(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final ProcessingInstruction
ProcessingInstruction to write.
pi
)

This will handle printing of a ProcessingInstruction.

protected void
printText(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final FormatStack
the FormatStack
fstack
,
final Text
Text to write.
text
)

This will handle printing of a Text.

public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final Document
Document to format.
doc
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

This will print the Document to the given XMLStreamWriter.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final DocType
DocType to output.
doctype
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out the DocType.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final Element
Element to output.
element
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out an Element, including its Attributes, and all contained (child) elements, etc.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final List<? extends Content>
List of nodes.
list
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

This will handle printing out a list of nodes.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final CDATA
CDATA to output.
cdata
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out a CDATA node.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final Text
Text to output.
text
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out a Text node.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final Comment
Comment to output.
comment
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out a Comment.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final ProcessingInstruction
ProcessingInstruction to output.
pi
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out a ProcessingInstruction.
public void
process(final XMLStreamWriter
XMLStreamWriter to use.
out
,
final Format
Format instance specifying output style
format
,
final EntityRef
EntityRef to output.
entity
)

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Print out a EntityRef.
Inherited from org.jdom2.output.support.AbstractOutputProcessor:
buildWalker

Constructor Detail

AbstractStAXStreamProcessorback to summary
public AbstractStAXStreamProcessor()

Method Detail

printAttributeback to summary
protected void printAttribute(final XMLStreamWriter out, final FormatStack fstack, final Attribute attribute) throws XMLStreamException

This will handle printing of an Attribute.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

The current FormatStack

attribute:Attribute

Attribute to output

Exceptions
XMLStreamException:
if the output fails
printCDATAback to summary
protected void printCDATA(final XMLStreamWriter out, final FormatStack fstack, final CDATA cdata) throws XMLStreamException

This will handle printing of a CDATA.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

cdata:CDATA

CDATA to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printCommentback to summary
protected void printComment(final XMLStreamWriter out, final FormatStack fstack, final Comment comment) throws XMLStreamException

This will handle printing of a Comment.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

comment:Comment

Comment to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printContentback to summary
protected void printContent(final XMLStreamWriter out, final FormatStack fstack, final NamespaceStack nstack, final Walker walker) throws XMLStreamException

This will handle printing of a List of Content.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

walker:Walker

Walker of Content to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printDocTypeback to summary
protected void printDocType(final XMLStreamWriter out, final FormatStack fstack, final DocType docType) throws XMLStreamException

This will handle printing of a DocType.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

docType:DocType

DocType to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printDocumentback to summary
protected void printDocument(final XMLStreamWriter out, final FormatStack fstack, final NamespaceStack nstack, final Document doc) throws XMLStreamException

This will handle printing of a Document.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

doc:Document

Document to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printElementback to summary
protected void printElement(final XMLStreamWriter out, final FormatStack fstack, final NamespaceStack nstack, final Element element) throws XMLStreamException

This will handle printing of an Element.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

element:Element

Element to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printEntityRefback to summary
protected void printEntityRef(final XMLStreamWriter out, final FormatStack fstack, final EntityRef entity) throws XMLStreamException

This will handle printing of an EntityRef.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

entity:EntityRef

EntotyRef to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printNamespaceback to summary
protected void printNamespace(final XMLStreamWriter out, final FormatStack fstack, final Namespace ns) throws XMLStreamException

This will handle printing of any needed Namespace declarations.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

The current FormatStack

ns:Namespace

Namespace to print definition of

Exceptions
XMLStreamException:
if the output fails
printProcessingInstructionback to summary
protected void printProcessingInstruction(final XMLStreamWriter out, final FormatStack fstack, final ProcessingInstruction pi) throws XMLStreamException

This will handle printing of a ProcessingInstruction.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

pi:ProcessingInstruction

ProcessingInstruction to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
printTextback to summary
protected void printText(final XMLStreamWriter out, final FormatStack fstack, final Text text) throws XMLStreamException

This will handle printing of a Text.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

fstack:FormatStack

the FormatStack

text:Text

Text to write.

Exceptions
XMLStreamException:
if the destination XMLStreamWriter fails
processback to summary
public void process(final XMLStreamWriter out, final Format format, final Document doc) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

This will print the Document to the given XMLStreamWriter.

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.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

doc:Document

Document to format.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final DocType doctype) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out the DocType.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

doctype:DocType

DocType to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final Element element) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out an Element, including its Attributes, and all contained (child) elements, etc.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

element:Element

Element to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final List<? extends Content> list) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

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
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

list:List<? extends Content>

List of nodes.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final CDATA cdata) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out a CDATA node.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

cdata:CDATA

CDATA to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final Text text) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out a Text node. Performs the necessary entity escaping and whitespace stripping.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

text:Text

Text to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final Comment comment) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out a Comment.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

comment:Comment

Comment to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final ProcessingInstruction pi) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out a ProcessingInstruction.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

pi:ProcessingInstruction

ProcessingInstruction to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
processback to summary
public void process(final XMLStreamWriter out, final Format format, final EntityRef entity) throws XMLStreamException

Implements org.jdom2.output.support.StAXStreamProcessor.process.

Doc from org.jdom2.output.support.StAXStreamProcessor.process.

Print out a EntityRef.

Parameters
out:XMLStreamWriter

XMLStreamWriter to use.

format:Format

Format instance specifying output style

entity:EntityRef

EntityRef to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.