Package com.fasterxml.aalto.dom
Class DOMWriterImpl
java.lang.Object
org.codehaus.stax2.ri.dom.DOMWrappingWriter
com.fasterxml.aalto.dom.DOMWriterImpl
- All Implemented Interfaces:
XMLStreamWriter,org.codehaus.stax2.typed.TypedXMLStreamWriter,org.codehaus.stax2.validation.Validatable,org.codehaus.stax2.XMLStreamWriter2
public final class DOMWriterImpl
extends org.codehaus.stax2.ri.dom.DOMWrappingWriter
This is an adapter class that allows building a DOM tree using
XMLStreamWriter interface.
Note that the implementation is only to be used for use with
javax.xml.transform.dom.DOMResult.
Some notes regarding missing/incomplete functionality:
- Namespace-repairing mode not implemented
- Validation functionality not implemented
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected int[]for NsRepairing modeprotected final WriterConfigprotected DOMOutputElementThis element is the current context element, under which all other nodes are added, until matching end element is output.protected DOMOutputElementThis element is non-null right after a call to eitherwriteStartElementandwriteEmptyElement, and can be used to add attributes and namespace declarations.protected StringMap that contains URI-to-prefix entries that point out suggested prefixes for URIs.Fields inherited from class org.codehaus.stax2.ri.dom.DOMWrappingWriter
mDocument, mEncoding, mNsAware, mNsContext, mNsRepairing, mValueEncoder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendLeaf(Node n) static DOMWriterImplcreateFrom(WriterConfig cfg, DOMResult dst) protected voidcreateStartElem(String nsURI, String prefix, String localName, boolean isEmpty) Method called by all start element write methods.protected final StringfindElemPrefix(String nsURI, DOMOutputElement elem) Method called to find an existing prefix for the given namespace, if any exists in the scope.protected final StringfindOrCreateAttrPrefix(String suggPrefix, String nsURI, DOMOutputElement elem) Method called to somehow find a prefix for given namespace, to be used for a new start element; either use an existing one, or generate a new one.protected final StringgenerateElemPrefix(String suggPrefix, String nsURI, DOMOutputElement elem) Method called afterfindElemPrefix(java.lang.String, com.fasterxml.aalto.dom.DOMOutputElement)has returned null, to create and bind a namespace mapping for specified namespace.getProperty(String name) booleanisPropertySupported(String name) protected voidoutputAttribute(String nsURI, String prefix, String localName, String value) voidvoidbooleansetProperty(String name, Object value) private final StringvalidateElemPrefix(String prefix, String nsURI, DOMOutputElement elem) voidwriteAttribute(String localName, String value) voidwriteAttribute(String nsURI, String localName, String value) voidwriteAttribute(String prefix, String nsURI, String localName, String value) voidwriteDefaultNamespace(String nsURI) voidvoidwriteEmptyElement(String localName) voidwriteEmptyElement(String nsURI, String localName) voidwriteEmptyElement(String prefix, String localName, String nsURI) voidvoidvoidwriteNamespace(String prefix, String nsURI) voidwriteStartElement(String localName) voidwriteStartElement(String nsURI, String localName) voidwriteStartElement(String prefix, String localName, String nsURI) Methods inherited from class org.codehaus.stax2.ri.dom.DOMWrappingWriter
close, closeCompletely, copyEventFromReader, flush, getEncoding, getLocation, getValueEncoder, reportUnsupported, serializeQNameValue, setNamespaceContext, setValidationProblemHandler, stopValidatingAgainst, stopValidatingAgainst, throwOutputError, throwOutputError, validateAgainst, writeBinary, writeBinary, writeBinaryAttribute, writeBinaryAttribute, writeBoolean, writeBooleanAttribute, writeCData, writeCData, writeCharacters, writeCharacters, writeComment, writeDecimal, writeDecimalAttribute, writeDouble, writeDoubleArray, writeDoubleArrayAttribute, writeDoubleAttribute, writeDTD, writeEntityRef, writeFloat, writeFloatArray, writeFloatArrayAttribute, writeFloatAttribute, writeFullEndElement, writeInt, writeIntArray, writeIntArrayAttribute, writeIntAttribute, writeInteger, writeIntegerAttribute, writeLong, writeLongArray, writeLongArrayAttribute, writeLongAttribute, writeProcessingInstruction, writeProcessingInstruction, writeQName, writeQNameAttribute, writeRaw, writeRaw, writeRaw, writeSpace, writeSpace, writeStartDocument, writeStartDocument, writeStartDocument, writeStartDocument
-
Field Details
-
_config
-
_currElem
This element is the current context element, under which all other nodes are added, until matching end element is output. Null outside of the main element tree.Note: explicit empty element (written using
writeEmptyElement) will never become current element. -
_openElement
This element is non-null right after a call to eitherwriteStartElementandwriteEmptyElement, and can be used to add attributes and namespace declarations.Note: while this is often the same as
_currElem, it's not always. Specifically, an empty element (written explicitly usingwriteEmptyElement) will become open element but NOT current element. Conversely, regular elements will remain current element when non elements are written (text, comments, PI), but not the open element. -
_autoNsSeq
protected int[] _autoNsSeqfor NsRepairing mode -
_suggestedDefNs
-
_automaticNsPrefix
-
_suggestedPrefixes
Map that contains URI-to-prefix entries that point out suggested prefixes for URIs. These are populated by calls tosetPrefix(java.lang.String, java.lang.String), and they are only used as hints for binding; if there are conflicts, repairing writer can just use some other prefix.
-
-
Constructor Details
-
DOMWriterImpl
- Throws:
XMLStreamException
-
-
Method Details
-
createFrom
- Throws:
XMLStreamException
-
getNamespaceContext
- Specified by:
getNamespaceContextin interfaceXMLStreamWriter- Specified by:
getNamespaceContextin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
getPrefix
- Specified by:
getPrefixin interfaceXMLStreamWriter- Specified by:
getPrefixin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
getProperty
- Specified by:
getPropertyin interfaceXMLStreamWriter- Specified by:
getPropertyin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
setDefaultNamespace
- Specified by:
setDefaultNamespacein interfaceXMLStreamWriter- Specified by:
setDefaultNamespacein classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
setPrefix
- Specified by:
setPrefixin interfaceXMLStreamWriter- Specified by:
setPrefixin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeAttribute
- Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeAttribute
- Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String nsURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeDefaultNamespace
- Specified by:
writeDefaultNamespacein interfaceXMLStreamWriter- Specified by:
writeDefaultNamespacein classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
writeEmptyElement
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeEmptyElement
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String prefix, String localName, String nsURI) throws XMLStreamException - Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
writeEndDocument
public void writeEndDocument()- Specified by:
writeEndDocumentin interfaceXMLStreamWriter- Specified by:
writeEndDocumentin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
writeEndElement
public void writeEndElement() -
writeNamespace
- Throws:
XMLStreamException
-
writeStartElement
- Throws:
XMLStreamException
-
writeStartElement
- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(String prefix, String localName, String nsURI) throws XMLStreamException - Throws:
XMLStreamException
-
isPropertySupported
- Specified by:
isPropertySupportedin interfaceorg.codehaus.stax2.XMLStreamWriter2- Specified by:
isPropertySupportedin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
setProperty
- Specified by:
setPropertyin interfaceorg.codehaus.stax2.XMLStreamWriter2- Specified by:
setPropertyin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter
-
writeDTD
public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws XMLStreamException - Specified by:
writeDTDin interfaceorg.codehaus.stax2.XMLStreamWriter2- Specified by:
writeDTDin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
XMLStreamException
-
appendLeaf
- Specified by:
appendLeafin classorg.codehaus.stax2.ri.dom.DOMWrappingWriter- Throws:
IllegalStateException
-
createStartElem
protected void createStartElem(String nsURI, String prefix, String localName, boolean isEmpty) throws XMLStreamException Method called by all start element write methods.- Parameters:
nsURI- Namespace URI to use: null and empty String denote 'no namespace'- Throws:
XMLStreamException
-
outputAttribute
protected void outputAttribute(String nsURI, String prefix, String localName, String value) throws XMLStreamException - Throws:
XMLStreamException
-
validateElemPrefix
private final String validateElemPrefix(String prefix, String nsURI, DOMOutputElement elem) throws XMLStreamException - Throws:
XMLStreamException
-
findElemPrefix
protected final String findElemPrefix(String nsURI, DOMOutputElement elem) throws XMLStreamException Method called to find an existing prefix for the given namespace, if any exists in the scope. If one is found, it's returned (including "" for the current default namespace); if not, null is returned.- Parameters:
nsURI- URI of namespace for which we need a prefix- Throws:
XMLStreamException
-
generateElemPrefix
protected final String generateElemPrefix(String suggPrefix, String nsURI, DOMOutputElement elem) throws XMLStreamException Method called afterfindElemPrefix(java.lang.String, com.fasterxml.aalto.dom.DOMOutputElement)has returned null, to create and bind a namespace mapping for specified namespace.- Throws:
XMLStreamException
-
findOrCreateAttrPrefix
protected final String findOrCreateAttrPrefix(String suggPrefix, String nsURI, DOMOutputElement elem) throws XMLStreamException Method called to somehow find a prefix for given namespace, to be used for a new start element; either use an existing one, or generate a new one. If a new mapping needs to be generated, it will also be automatically bound, and necessary namespace declaration output.- Parameters:
suggPrefix- Suggested prefix to bind, if any; may be null to indicate "no preference"nsURI- URI of namespace for which we need a prefixelem- Currently open start element, on which the attribute will be added.- Throws:
XMLStreamException
-