Package javanet.staxutils
Class BaseXMLEventWriter
java.lang.Object
javanet.staxutils.BaseXMLEventWriter
- All Implemented Interfaces:
XMLEventConsumer,XMLEventWriter
- Direct Known Subclasses:
StreamEventWriter,XMLStreamEventWriter
Base class for
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.- Version:
- $Revision: 1.9 $
- Author:
- Christian Niles
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MapLinkedHashMap of attribute events sent surrounding the last StartElement.protected booleanWhether this writer has been closed or not.protected XMLEventFactoryXMLEventFactory used to construct XMLEvent instances.protected StartElementReference to the last StartElement sent.protected MapLinkedHashMap of namespace events sent surrounding the last StartElement.protected Listlist ofSimpleNamespaceContexts. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedBaseXMLEventWriter(XMLEventFactory eventFactory, NamespaceContext nsCtx) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidadd(XMLEventReader reader) protected voidcacheAttribute(Attribute attr) Adds the specifiedAttributeto the attribute cache.protected voidAdds the providedNamespaceevent to the namespace cache.voidclose()voidflush()protected SimpleNamespaceContextReturns the activeSimpleNamespaceContextfrom the top of the stack.protected SimpleNamespaceContextRemoves the activeSimpleNamespaceContextfrom the top of the stack.protected SimpleNamespaceContextCreates a newSimpleNamespaceContextand adds it to the top of the stack.protected abstract voidCalled by the methods of this class to write the event to the stream.voidsetDefaultNamespace(String nsURI) voidvoid
-
Field Details
-
factory
XMLEventFactory used to construct XMLEvent instances. -
nsStack
list ofSimpleNamespaceContexts. -
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
LinkedHashMap of attribute events sent surrounding the last StartElement. By using LinkedHashMap, the attributes will stay in the order they were defined. -
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 closedWhether this writer has been closed or not.
-
-
Constructor Details
-
BaseXMLEventWriter
protected BaseXMLEventWriter() -
BaseXMLEventWriter
-
-
Method Details
-
flush
- Specified by:
flushin interfaceXMLEventWriter- Throws:
XMLStreamException
-
close
- Specified by:
closein interfaceXMLEventWriter- Throws:
XMLStreamException
-
add
- Specified by:
addin interfaceXMLEventConsumer- Specified by:
addin interfaceXMLEventWriter- Throws:
XMLStreamException
-
add
- Specified by:
addin interfaceXMLEventWriter- Throws:
XMLStreamException
-
getPrefix
- Specified by:
getPrefixin interfaceXMLEventWriter- Throws:
XMLStreamException
-
setPrefix
- Specified by:
setPrefixin interfaceXMLEventWriter- Throws:
XMLStreamException
-
setDefaultNamespace
- Specified by:
setDefaultNamespacein interfaceXMLEventWriter- Throws:
XMLStreamException
-
setNamespaceContext
- Specified by:
setNamespaceContextin interfaceXMLEventWriter- Throws:
XMLStreamException
-
getNamespaceContext
- Specified by:
getNamespaceContextin interfaceXMLEventWriter
-
popNamespaceStack
Removes the activeSimpleNamespaceContextfrom the top of the stack.- Returns:
- The
SimpleNamespaceContextremoved from the namespace stack.
-
peekNamespaceStack
Returns the activeSimpleNamespaceContextfrom the top of the stack.- Returns:
- The active
SimpleNamespaceContextfrom the top of the stack.
-
pushNamespaceStack
Creates a newSimpleNamespaceContextand adds it to the top of the stack.- Returns:
- The new
SimpleNamespaceContext.
-
cacheAttribute
Adds the specifiedAttributeto the attribute cache.- Parameters:
attr- The attribute to cache.
-
cacheNamespace
Adds the providedNamespaceevent to the namespace cache. The current namespace context will not be affected.- Parameters:
ns- The namespace to add to the cache.
-
sendEvent
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.
-