Top Description Inners Constructors Methods
org.jdom2.output.support

public abstract Class AbstractStAXEventProcessor

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

This class provides a concrete implementation of 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.

Author
Rolf Lear
Since
JDOM2
See Also
StAXEventOutputter, StAXEventProcessor

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
printCDATA(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final CDATA
CDATA to write.
cdata
)

This will handle printing of a CDATA.

protected void
printComment(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final Comment
Comment to write.
comment
)

This will handle printing of a Comment.

protected void
printContent(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final Walker
Walker of Content to write.
walker
)

This will handle printing of a List of Content.

protected void
printDocType(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final DocType
DocType to write.
docType
)

This will handle printing of a DocType.

protected void
printDocument(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final Document
Document to write.
doc
)

This will handle printing of a Document.

protected void
printElement(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final NamespaceStack
the NamespaceStack
nstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final Element
Element to write.
element
)

This will handle printing of an Element.

protected void
printEntityRef(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final EntityRef
EntotyRef to write.
entity
)

This will handle printing of an EntityRef.

protected void
printProcessingInstruction(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final ProcessingInstruction
ProcessingInstruction to write.
pi
)

This will handle printing of a ProcessingInstruction.

protected void
printText(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final FormatStack
the FormatStack
fstack
,
final XMLEventFactory
The XMLEventFactory for creating XMLEvents
eventfactory
,
final Text
Text to write.
text
)

This will handle printing of a Text.

public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final Document
Document to format.
doc
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

This will print the Document to the given XMLEventConsumer.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final DocType
DocType to output.
doctype
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

Print out the DocType.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final Element
Element to output.
element
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

This will handle printing out a list of nodes.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final CDATA
CDATA to output.
cdata
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

Print out a CDATA node.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final Text
Text to output.
text
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

Print out a Text node.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final Comment
Comment to output.
comment
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

Print out a Comment.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final ProcessingInstruction
ProcessingInstruction to output.
pi
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

Print out a ProcessingInstruction.
public void
process(final XMLEventConsumer
XMLEventConsumer to use.
out
,
final Format
Format instance specifying output style
format
,
final XMLEventFactory
XMLEventFactory for creating XMLEvent instances.
eventfactory
,
final EntityRef
EntityRef to output.
entity
)

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Constructor Detail

AbstractStAXEventProcessorback to summary
public AbstractStAXEventProcessor()

Method Detail

printCDATAback to summary
protected void printCDATA(final XMLEventConsumer out, final FormatStack fstack, final XMLEventFactory eventfactory, final CDATA cdata) throws XMLStreamException

This will handle printing of a CDATA.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

cdata:CDATA

CDATA to write.

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

This will handle printing of a Comment.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

comment:Comment

Comment to write.

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

This will handle printing of a List of Content.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

walker:Walker

Walker of Content to write.

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

This will handle printing of a DocType.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

docType:DocType

DocType to write.

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

This will handle printing of a Document.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

doc:Document

Document to write.

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

This will handle printing of an Element.

This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

nstack:NamespaceStack

the NamespaceStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

element:Element

Element to write.

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

This will handle printing of an EntityRef.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

entity:EntityRef

EntotyRef to write.

Exceptions
XMLStreamException:
if the destination XMLEventConsumer fails
printProcessingInstructionback to summary
protected void printProcessingInstruction(final XMLEventConsumer out, final FormatStack fstack, final XMLEventFactory eventfactory, final ProcessingInstruction pi) throws XMLStreamException

This will handle printing of a ProcessingInstruction.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

pi:ProcessingInstruction

ProcessingInstruction to write.

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

This will handle printing of a Text.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

fstack:FormatStack

the FormatStack

eventfactory:XMLEventFactory

The XMLEventFactory for creating XMLEvents

text:Text

Text to write.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

This will print the Document to the given XMLEventConsumer.

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.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

doc:Document

Document to format.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Print out the DocType.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

doctype:DocType

DocType to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

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

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

element:Element

Element to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

Doc from org.jdom2.output.support.StAXEventProcessor.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:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

list:List<? extends Content>

List of nodes.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Print out a CDATA node.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

cdata:CDATA

CDATA to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

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

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

text:Text

Text to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Print out a Comment.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

comment:Comment

Comment to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Print out a ProcessingInstruction.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

pi:ProcessingInstruction

ProcessingInstruction to output.

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

Implements org.jdom2.output.support.StAXEventProcessor.process.

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

Print out a EntityRef.

Parameters
out:XMLEventConsumer

XMLEventConsumer to use.

format:Format

Format instance specifying output style

eventfactory:XMLEventFactory

XMLEventFactory for creating XMLEvent instances.

entity:EntityRef

EntityRef to output.

Annotations
@Override
Exceptions
XMLStreamException:
if there's any problem writing.
org.jdom2.output.support back to summary

private final Class AbstractStAXEventProcessor.AttIterator

extends Object
implements Iterator<Attribute>
Class Inheritance
  • java.lang.Object
  • org.jdom2.output.support.AbstractStAXEventProcessor.AttIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private final XMLEventFactory
private final Iterator<Attribute>

Constructor Summary

AccessConstructor and Description
public
AttIterator(final Iterator<Attribute> source, final XMLEventFactory fac, final boolean specifiedAttributesOnly)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Attribute
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
private Iterator<Attribute>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

facback to summary
private final XMLEventFactory fac
sourceback to summary
private final Iterator<Attribute> source

Constructor Detail

AttIteratorback to summary
public AttIterator(final Iterator<Attribute> source, final XMLEventFactory fac, final boolean specifiedAttributesOnly)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Attribute next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Attribute

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
specifiedback to summary
private Iterator<Attribute> specified(Iterator<Attribute> src)
org.jdom2.output.support back to summary

private final Class AbstractStAXEventProcessor.NSIterator

extends Object
implements Iterator<Namespace>
Class Inheritance
  • java.lang.Object
  • org.jdom2.output.support.AbstractStAXEventProcessor.NSIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private final XMLEventFactory
private final Iterator<Namespace>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Namespace
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

facback to summary
private final XMLEventFactory fac
sourceback to summary
private final Iterator<Namespace> source

Constructor Detail

NSIteratorback to summary
public NSIterator(Iterator<Namespace> source, XMLEventFactory fac)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Namespace next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Namespace

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override