Top Description Fields Constructors Methods
org.codehaus.stax2.ri.dom

public abstract Class DOMWrappingWriter

extends Object
implements XMLStreamWriter2
Class Inheritance
All Implemented Interfaces
org.codehaus.stax2.XMLStreamWriter2, org.codehaus.stax2.validation.Validatable, org.codehaus.stax2.typed.TypedXMLStreamWriter, javax.xml.stream.XMLStreamWriter
Imports
java.math.BigDecimal, .BigInteger, java.text.MessageFormat, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.*, org.w3c.dom.*, org.codehaus.stax2.XMLStreamLocation2, .XMLStreamReader2, .XMLStreamWriter2, org.codehaus.stax2.ri.typed.SimpleValueEncoder, org.codehaus.stax2.typed.Base64Variant, .Base64Variants, org.codehaus.stax2.validation.*

This is an adapter class that partially implements XMLStreamWriter as a facade on top of a DOM document or Node, allowing one to basically construct DOM trees via Stax API. It is meant to serve as basis for a full implementation.

Note that the implementation is only to be used with javax.xml.transform.dom.DOMResult. It can however be used for both full documents, and single element root fragments, depending on what node is passed as the argument.

One more implementation note: much code is identical to one used by org.codehaus.stax2.ri.Stax2WriterAdapter. Alas it is hard to reuse it without cut'n pasting.

Author
Tatu Saloranta
Since
3.0

Field Summary

Modifier and TypeField and Description
pack-priv static final String
pack-priv static final String
protected final Document
mDocument

We need a reference to the document hosting nodes to be able to create new nodes

protected String
mEncoding

This member variable is to keep information about encoding that seems to be used for the document (or fragment) to output, if known.

protected final boolean
protected NamespaceContext
mNsContext

If we are being given info about existing bindings, it'll come as a NamespaceContext.

protected final boolean
protected SimpleValueEncoder
mValueEncoder

Encoding of typed values is used the standard encoder included in RI.

Constructor Summary

AccessConstructor and Description
protected
DOMWrappingWriter(Node treeRoot, boolean nsAware, boolean nsRepairing)

Method Summary

Modifier and TypeMethod and Description
protected abstract void
public void
close()

Implements javax.xml.stream.XMLStreamWriter.close.

Close this writer and free any resources associated with the writer.
public void
closeCompletely()

Implements org.codehaus.stax2.XMLStreamWriter2.closeCompletely.

Method similar to javax.xml.stream.XMLStreamWriter#close(), except that this method also does close the underlying output destination (stream) if it has not yet been closed.
public void
copyEventFromReader(XMLStreamReader2
Reader to use for accessing event to copy
r
,
boolean
If true, writer is not allowed to change the state of the reader (so that all the data associated with the current event has to be preserved); if false, writer is allowed to use methods that may cause some data to be discarded. Setting this to false may improve the performance, since it may allow full no-copy streaming of data, especially textual contents.
preserveEventData
)

Implements org.codehaus.stax2.XMLStreamWriter2.copyEventFromReader.

Method that essentially copies event that the specified reader has just read.
public void
flush()

Implements javax.xml.stream.XMLStreamWriter.flush.

Write any cached data to the underlying output mechanism.
public String
getEncoding()

Implements org.codehaus.stax2.XMLStreamWriter2.getEncoding.

Method that can be called to get information about encoding that this writer is using (or at least claims is using).
public XMLStreamLocation2
getLocation()

Implements org.codehaus.stax2.XMLStreamWriter2.getLocation.

Method that should return current output location, if the writer keeps track of it; null if it does not.
public abstract NamespaceContext
getNamespaceContext()

Redeclares javax.xml.stream.XMLStreamWriter.getNamespaceContext.

Returns the current namespace context.
public abstract String
getPrefix(String
the uri the prefix is bound to
uri
)

Redeclares javax.xml.stream.XMLStreamWriter.getPrefix.

Gets the prefix the uri is bound to.
public abstract Object
getProperty(String
The name of the property, may not be null
name
)

Redeclares javax.xml.stream.XMLStreamWriter.getProperty.

Get the value of a feature/property from the underlying implementation
protected SimpleValueEncoder
public abstract boolean
isPropertySupported(String name)

Redeclares org.codehaus.stax2.XMLStreamWriter2.isPropertySupported.

Method similar to javax.xml.stream.XMLOutputFactory#isPropertySupported, used to determine whether a property is supported by the Writer instance.
protected void
protected String
serializeQNameValue(QName name)

Method called to serialize given qualified name into valid String serialization, taking into account existing namespace bindings.

public abstract void
setDefaultNamespace(String
the uri to bind to the default namespace, may be null
uri
)

Redeclares javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair.
public void
setNamespaceContext(NamespaceContext
the namespace context to use for this writer, may not be null
context
)

Implements javax.xml.stream.XMLStreamWriter.setNamespaceContext.

Sets the current namespace context for prefix and uri bindings.
public abstract void
setPrefix(String
the prefix to bind to the uri, may not be null
prefix
,
String
the uri to bind to the prefix, may be null
uri
)

Redeclares javax.xml.stream.XMLStreamWriter.setPrefix.

Sets the prefix the uri is bound to.
public abstract boolean
setProperty(String
Name of the property to set
name
,
Object
Value to set property to.
value
)

Redeclares org.codehaus.stax2.XMLStreamWriter2.setProperty.

Method that can be used to set per-writer properties; a subset of properties one can set via matching org.codehaus.stax2.XMLOutputFactory2 instance.
public ValidationProblemHandler
setValidationProblemHandler(ValidationProblemHandler
Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
h
)

Implements org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Method that application can call to define a custom handler for validation problems encountered during validation process.
public XMLValidator
stopValidatingAgainst(XMLValidationSchema schema)

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output against a schema, for which validateAgainst was called earlier.
public XMLValidator
stopValidatingAgainst(XMLValidator validator)

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output using specified validator.
protected static void
protected static void
public XMLValidator
validateAgainst(XMLValidationSchema schema)

Implements org.codehaus.stax2.validation.Validatable.validateAgainst.

Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to stopValidatingAgainst.
public abstract void
writeAttribute(String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Redeclares javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream without a prefix.
public abstract void
writeAttribute(String
the uri of the prefix for this attribute
nsURI
,
String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Redeclares javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public abstract void
writeAttribute(String
the prefix for this attribute
prefix
,
String
the uri of the prefix for this attribute
nsURI
,
String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Redeclares javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public void
writeBinary(byte[]
The array from which to write the bytes.
value
,
int
The index in the array from which writing starts.
from
,
int
The number of bytes to write.
length
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBinary.

Write binary content as base64 encoded characters to the output.

public void
public void
writeBinaryAttribute(String
The attribute's prefix.
prefix
,
String
The attribute's URI.
nsURI
,
String
The attribute's local name.
localName
,
byte[]
The array from which to write the bytes.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBinaryAttribute.

Write a byte array attribute.

public void
public void
writeBoolean(boolean
The boolean value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBoolean.

Write a boolean value to the output as textual element content.
public void
writeBooleanAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
boolean
The boolean value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBooleanAttribute.

Write a boolean value to the output as attribute value.
public void
writeCData(String
the data contained in the CData Section, may not be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeCData.

Writes a CData section
public void
writeCData(char[] text, int start, int len)

Implements org.codehaus.stax2.XMLStreamWriter2.writeCData.

public void
writeCharacters(char[]
the value to write
text
,
int
the starting position in the array
start
,
int
the number of characters to write
len
)

Implements javax.xml.stream.XMLStreamWriter.writeCharacters.

Write text to the output
public void
writeCharacters(String
the value to write
text
)

Implements javax.xml.stream.XMLStreamWriter.writeCharacters.

Write text to the output
public void
writeComment(String
the data contained in the comment, may be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeComment.

Writes an xml comment with the data enclosed
public void
writeDecimal(BigDecimal value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeDecimal.

Write a decimal value to the output as textual element content.
public void
public abstract void
writeDefaultNamespace(String
the uri to bind the default namespace to
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Writes the default namespace to the stream
public void
writeDouble(double value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeDouble.

Write a double value to the output as textual element content.
public void
public void
public void
public void
writeDTD(String
the DTD to be written
dtd
)

Implements javax.xml.stream.XMLStreamWriter.writeDTD.

Write a DTD section.
public abstract void
writeDTD(String rootName, String systemId, String publicId, String internalSubset)

Redeclares org.codehaus.stax2.XMLStreamWriter2.writeDTD.

public abstract void
writeEmptyElement(String
local name of the tag, may not be null
localName
)

Redeclares javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public abstract void
writeEmptyElement(String
the uri to bind the tag to, may not be null
nsURI
,
String
local name of the tag, may not be null
localName
)

Redeclares javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public abstract void
writeEmptyElement(String
the prefix of the tag, may not be null
prefix
,
String
local name of the tag, may not be null
localName
,
String
the uri to bind the tag to, may not be null
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public abstract void
writeEndDocument()

Redeclares javax.xml.stream.XMLStreamWriter.writeEndDocument.

Closes any start tags and writes corresponding end tags.
public void
writeEntityRef(String
the name of the entity
name
)

Implements javax.xml.stream.XMLStreamWriter.writeEntityRef.

Writes an entity reference
public void
writeFloat(float value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeFloat.

Write a float value to the output as textual element content.
public void
public void
public void
public void
writeFullEndElement()

Implements org.codehaus.stax2.XMLStreamWriter2.writeFullEndElement.

Method similar to writeEndElement, but that will always write the full end element, instead of empty element.
public void
writeInt(int value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeInt.

Write an int value to the output as textual element content.
public void
writeIntArray(int[]
The array from which to write the ints.
value
,
int
The index in the array from which writing starts.
from
,
int
The number of ints to write.
length
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntArray.

Write int array to the output.

public void
writeIntArrayAttribute(String
The attribute's prefix.
prefix
,
String
The attribute's URI.
nsURI
,
String
The attribute's local name.
localName
,
int[]
The array from which to write the ints.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntArrayAttribute.

Write int array attribute.

public void
writeIntAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
int
The integer value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntAttribute.

Write an integer value to the output as attribute value.
public void
public void
public void
writeLong(long value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeLong.

Write a long value to the output as textual element content.
public void
public void
public void
writeLongAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
long
The long value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeLongAttribute.

Write an long value to the output as attribute value.
public void
writeProcessingInstruction(String
the target of the processing instruction, may not be null
target
)

Implements javax.xml.stream.XMLStreamWriter.writeProcessingInstruction.

Writes a processing instruction
public void
writeProcessingInstruction(String
the target of the processing instruction, may not be null
target
,
String
the data contained in the processing instruction, may not be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeProcessingInstruction.

Writes a processing instruction
public void
public void
public void
writeRaw(String text)

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeRaw(String text, int start, int offset)

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeRaw(char[] text, int offset, int length)

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeSpace(char[] text, int start, int len)

Implements org.codehaus.stax2.XMLStreamWriter2.writeSpace.

Method that can be called to write whitespace-only content.
public void
writeSpace(String text)

Implements org.codehaus.stax2.XMLStreamWriter2.writeSpace.

Method that can be called to write whitespace-only content.
public void
public void
writeStartDocument(String
version of the xml document
version
)

Implements javax.xml.stream.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.
public void
writeStartDocument(String
encoding of the xml declaration
encoding
,
String
version of the xml document
version
)

Implements javax.xml.stream.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait