public abstract class BaseXMLEventWriter
extends java.lang.Object
implements javax.xml.stream.XMLEventWriter
XMLEventWriter
implementations. This implemenation
buffers Attribute and Namespace events as specified in the specification,
maintains a stack of NamespaceContext instances based on the events it
receives, and repairs any missing namespaces. Subclasses should implement the
sendEvent(XMLEvent)
method to receive the processed events and
perform additional processing.Modifier and Type | Field and Description |
---|---|
protected java.util.Map |
attrBuff
LinkedHashMap of attribute events sent surrounding the last
StartElement.
|
protected boolean |
closed
Whether this writer has been closed or not.
|
protected javax.xml.stream.XMLEventFactory |
factory
XMLEventFactory used to construct XMLEvent instances.
|
protected javax.xml.stream.events.StartElement |
lastStart
Reference to the last StartElement sent.
|
protected java.util.Map |
nsBuff
LinkedHashMap of namespace events sent surrounding the last
StartElement.
|
protected java.util.List |
nsStack
list of
SimpleNamespaceContext s. |
Modifier | Constructor and Description |
---|---|
protected |
BaseXMLEventWriter() |
protected |
BaseXMLEventWriter(javax.xml.stream.XMLEventFactory eventFactory,
javax.xml.namespace.NamespaceContext nsCtx) |
Modifier and Type | Method and Description |
---|---|
void |
add(javax.xml.stream.events.XMLEvent event) |
void |
add(javax.xml.stream.XMLEventReader reader) |
protected void |
cacheAttribute(javax.xml.stream.events.Attribute attr)
Adds the specified
Attribute to the attribute cache. |
protected void |
cacheNamespace(javax.xml.stream.events.Namespace ns)
Adds the provided
Namespace event to the namespace cache. |
void |
close() |
void |
flush() |
javax.xml.namespace.NamespaceContext |
getNamespaceContext() |
java.lang.String |
getPrefix(java.lang.String nsURI) |
protected SimpleNamespaceContext |
peekNamespaceStack()
Returns the active
SimpleNamespaceContext from the top of the
stack. |
protected SimpleNamespaceContext |
popNamespaceStack()
Removes the active
SimpleNamespaceContext from the top of the
stack. |
protected SimpleNamespaceContext |
pushNamespaceStack()
Creates a new
SimpleNamespaceContext and adds it to the top of
the stack. |
protected abstract void |
sendEvent(javax.xml.stream.events.XMLEvent event)
Called by the methods of this class to write the event to the stream.
|
void |
setDefaultNamespace(java.lang.String nsURI) |
void |
setNamespaceContext(javax.xml.namespace.NamespaceContext root) |
void |
setPrefix(java.lang.String prefix,
java.lang.String nsURI) |
protected javax.xml.stream.XMLEventFactory factory
protected java.util.List nsStack
SimpleNamespaceContext
s.protected javax.xml.stream.events.StartElement lastStart
protected java.util.Map attrBuff
protected java.util.Map nsBuff
protected boolean closed
protected BaseXMLEventWriter()
protected BaseXMLEventWriter(javax.xml.stream.XMLEventFactory eventFactory, javax.xml.namespace.NamespaceContext nsCtx)
public void flush() throws javax.xml.stream.XMLStreamException
flush
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void close() throws javax.xml.stream.XMLStreamException
close
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void add(javax.xml.stream.events.XMLEvent event) throws javax.xml.stream.XMLStreamException
add
in interface javax.xml.stream.util.XMLEventConsumer
add
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void add(javax.xml.stream.XMLEventReader reader) throws javax.xml.stream.XMLStreamException
add
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public java.lang.String getPrefix(java.lang.String nsURI) throws javax.xml.stream.XMLStreamException
getPrefix
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void setPrefix(java.lang.String prefix, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException
setPrefix
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void setDefaultNamespace(java.lang.String nsURI) throws javax.xml.stream.XMLStreamException
setDefaultNamespace
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public void setNamespaceContext(javax.xml.namespace.NamespaceContext root) throws javax.xml.stream.XMLStreamException
setNamespaceContext
in interface javax.xml.stream.XMLEventWriter
javax.xml.stream.XMLStreamException
public javax.xml.namespace.NamespaceContext getNamespaceContext()
getNamespaceContext
in interface javax.xml.stream.XMLEventWriter
protected SimpleNamespaceContext popNamespaceStack()
SimpleNamespaceContext
from the top of the
stack.SimpleNamespaceContext
removed from the namespace
stack.protected SimpleNamespaceContext peekNamespaceStack()
SimpleNamespaceContext
from the top of the
stack.SimpleNamespaceContext
from the top of the
stack.protected SimpleNamespaceContext pushNamespaceStack()
SimpleNamespaceContext
and adds it to the top of
the stack.SimpleNamespaceContext
.protected void cacheAttribute(javax.xml.stream.events.Attribute attr)
Attribute
to the attribute cache.attr
- The attribute to cache.protected void cacheNamespace(javax.xml.stream.events.Namespace ns)
Namespace
event to the namespace cache. The
current namespace context will not be affected.ns
- The namespace to add to the cache.protected abstract void sendEvent(javax.xml.stream.events.XMLEvent event) throws javax.xml.stream.XMLStreamException
event
- The event to write.javax.xml.stream.XMLStreamException
- If an error occurs processing the event.