Package javanet.staxutils
Class BaseXMLEventWriter
- java.lang.Object
-
- javanet.staxutils.BaseXMLEventWriter
-
- All Implemented Interfaces:
XMLEventConsumer
,XMLEventWriter
- Direct Known Subclasses:
StreamEventWriter
,XMLStreamEventWriter
public abstract class BaseXMLEventWriter extends Object implements XMLEventWriter
Base class forXMLEventWriter
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 thesendEvent(XMLEvent)
method to receive the processed events and perform additional processing.- Version:
- $Revision: 1.9 $
- Author:
- Christian Niles
-
-
Field Summary
Fields Modifier and Type Field Description protected Map
attrBuff
LinkedHashMap of attribute events sent surrounding the last StartElement.protected boolean
closed
Whether this writer has been closed or not.protected XMLEventFactory
factory
XMLEventFactory used to construct XMLEvent instances.protected StartElement
lastStart
Reference to the last StartElement sent.protected Map
nsBuff
LinkedHashMap of namespace events sent surrounding the last StartElement.protected List
nsStack
list ofSimpleNamespaceContext
s.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseXMLEventWriter()
protected
BaseXMLEventWriter(XMLEventFactory eventFactory, NamespaceContext nsCtx)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(XMLEvent event)
void
add(XMLEventReader reader)
protected void
cacheAttribute(Attribute attr)
Adds the specifiedAttribute
to the attribute cache.protected void
cacheNamespace(Namespace ns)
Adds the providedNamespace
event to the namespace cache.void
close()
void
flush()
NamespaceContext
getNamespaceContext()
String
getPrefix(String nsURI)
protected SimpleNamespaceContext
peekNamespaceStack()
Returns the activeSimpleNamespaceContext
from the top of the stack.protected SimpleNamespaceContext
popNamespaceStack()
Removes the activeSimpleNamespaceContext
from the top of the stack.protected SimpleNamespaceContext
pushNamespaceStack()
Creates a newSimpleNamespaceContext
and adds it to the top of the stack.protected abstract void
sendEvent(XMLEvent event)
Called by the methods of this class to write the event to the stream.void
setDefaultNamespace(String nsURI)
void
setNamespaceContext(NamespaceContext root)
void
setPrefix(String prefix, String nsURI)
-
-
-
Field Detail
-
factory
protected XMLEventFactory factory
XMLEventFactory used to construct XMLEvent instances.
-
nsStack
protected List nsStack
list ofSimpleNamespaceContext
s.
-
lastStart
protected StartElement lastStart
Reference to the last StartElement sent. This will be null if no StartElement has been sent, or after a non Attribute/Namespace event is received.
-
attrBuff
protected Map attrBuff
LinkedHashMap of attribute events sent surrounding the last StartElement. By using LinkedHashMap, the attributes will stay in the order they were defined.
-
nsBuff
protected Map nsBuff
LinkedHashMap of namespace events sent surrounding the last StartElement. By using LinkedHashMap, the namespaces will stay in the order they were defined.
-
closed
protected boolean closed
Whether this writer has been closed or not.
-
-
Constructor Detail
-
BaseXMLEventWriter
protected BaseXMLEventWriter()
-
BaseXMLEventWriter
protected BaseXMLEventWriter(XMLEventFactory eventFactory, NamespaceContext nsCtx)
-
-
Method Detail
-
flush
public void flush() throws XMLStreamException
- Specified by:
flush
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
close
public void close() throws XMLStreamException
- Specified by:
close
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
add
public void add(XMLEvent event) throws XMLStreamException
- Specified by:
add
in interfaceXMLEventConsumer
- Specified by:
add
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
add
public void add(XMLEventReader reader) throws XMLStreamException
- Specified by:
add
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
getPrefix
public String getPrefix(String nsURI) throws XMLStreamException
- Specified by:
getPrefix
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
setPrefix
public void setPrefix(String prefix, String nsURI) throws XMLStreamException
- Specified by:
setPrefix
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
setDefaultNamespace
public void setDefaultNamespace(String nsURI) throws XMLStreamException
- Specified by:
setDefaultNamespace
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
setNamespaceContext
public void setNamespaceContext(NamespaceContext root) throws XMLStreamException
- Specified by:
setNamespaceContext
in interfaceXMLEventWriter
- Throws:
XMLStreamException
-
getNamespaceContext
public NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContext
in interfaceXMLEventWriter
-
popNamespaceStack
protected SimpleNamespaceContext popNamespaceStack()
Removes the activeSimpleNamespaceContext
from the top of the stack.- Returns:
- The
SimpleNamespaceContext
removed from the namespace stack.
-
peekNamespaceStack
protected SimpleNamespaceContext peekNamespaceStack()
Returns the activeSimpleNamespaceContext
from the top of the stack.- Returns:
- The active
SimpleNamespaceContext
from the top of the stack.
-
pushNamespaceStack
protected SimpleNamespaceContext pushNamespaceStack()
Creates a newSimpleNamespaceContext
and adds it to the top of the stack.- Returns:
- The new
SimpleNamespaceContext
.
-
cacheAttribute
protected void cacheAttribute(Attribute attr)
Adds the specifiedAttribute
to the attribute cache.- Parameters:
attr
- The attribute to cache.
-
cacheNamespace
protected void cacheNamespace(Namespace ns)
Adds the providedNamespace
event to the namespace cache. The current namespace context will not be affected.- Parameters:
ns
- The namespace to add to the cache.
-
sendEvent
protected abstract void sendEvent(XMLEvent event) throws XMLStreamException
Called by the methods of this class to write the event to the stream.- Parameters:
event
- The event to write.- Throws:
XMLStreamException
- If an error occurs processing the event.
-
-