public final class XMLStreamWriterImpl extends java.lang.Object implements XMLStreamWriter, Reusable
This class represents a reusable
implementation of XMLStreamWriter
.
The writeCharacters
methods will escape & , < and
>. For attribute values, the writeAttribute
methods will
escape the above characters plus " and control characters.
Constructor and Description |
---|
XMLStreamWriterImpl()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this writer and free any resources associated with the writer.
|
void |
flush()
Write any cached data to the underlying output mechanism.
|
java.lang.CharSequence |
getPrefix(java.lang.CharSequence uri)
Gets the prefix the specified uri is bound to.
|
java.lang.Object |
getProperty(java.lang.String name)
Gets the value of a feature/property from the underlying implementation.
|
void |
reset()
Resets the internal state of this object to its default values.
|
void |
setAutomaticEmptyElements(boolean automaticEmptyElements)
Requires this writer to automatically output empty elements when a
start element is immediately followed by matching end element
(default
false ). |
void |
setDefaultNamespace(java.lang.CharSequence uri)
Binds a URI to the default namespace.
|
void |
setIndentation(java.lang.String indentation)
Specifies the indentation string; non-null indentation
forces the writer to write elements into separate lines
(default
null ). |
void |
setLineSeparator(java.lang.String lineSeparator)
Specifies the line separator (default
"\n" ). |
void |
setNoEmptyElementTag(boolean noEmptyElementTag)
Prevent this writer from using empty element tags
(default
false ). |
void |
setOutput(java.io.OutputStream out)
Sets the output stream destination for this XML stream writer
(UTF-8 encoding).
|
void |
setOutput(java.io.OutputStream out,
java.lang.String encoding)
Sets the output stream destination and encoding for this XML stream
writer.
|
void |
setOutput(java.io.Writer writer)
Sets the writer output destination for this XML stream writer.
|
void |
setPrefix(java.lang.CharSequence prefix,
java.lang.CharSequence uri)
Sets the prefix the uri is bound to.
|
void |
setRepairingNamespaces(boolean isRepairingNamespaces)
Requires this writer to create a new prefix when a namespace has none
(default
false ). |
void |
setRepairingPrefix(java.lang.String repairingPrefix)
Specifies the prefix to be append by a trailing part
(a sequence number) in order to make it unique to be usable as
a temporary non-colliding prefix when repairing namespaces
(default
"ns" ). |
void |
writeAttribute(java.lang.CharSequence localName,
java.lang.CharSequence value)
Writes an attribute to the output stream without a prefix.
|
void |
writeAttribute(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName,
java.lang.CharSequence value)
Writes an attribute to the output stream.
|
void |
writeAttribute(java.lang.CharSequence prefix,
java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName,
java.lang.CharSequence value)
Writes an attribute to the output stream.
|
void |
writeCData(java.lang.CharSequence data)
Writes a CData section.
|
void |
writeCharacters(char[] text,
int start,
int length)
Writes text to the output.
|
void |
writeCharacters(java.lang.CharSequence text)
Writes text to the output.
|
void |
writeComment(java.lang.CharSequence data)
Writes an xml comment with the data enclosed.
|
void |
writeDefaultNamespace(java.lang.CharSequence namespaceURI)
Writes the default namespace to the stream.
|
void |
writeDTD(java.lang.CharSequence dtd)
Writes a DTD section (representing the entire doctypedecl
production from the XML 1.0 specification).
|
void |
writeEmptyElement(java.lang.CharSequence localName)
Writes an empty element tag to the output.
|
void |
writeEmptyElement(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName)
Writes an empty element tag to the output.
|
void |
writeEmptyElement(java.lang.CharSequence prefix,
java.lang.CharSequence localName,
java.lang.CharSequence namespaceURI)
Writes an empty element tag to the output.
|
void |
writeEndDocument()
Closes any start tags and writes corresponding end tags.
|
void |
writeEndElement()
Writes an end tag to the output relying on the internal state of the
writer to determine the prefix and local name of the event.
|
void |
writeEntityRef(java.lang.CharSequence name)
Writes an entity reference
|
void |
writeNamespace(java.lang.CharSequence prefix,
java.lang.CharSequence namespaceURI)
Writes a namespace to the output stream.
|
void |
writeProcessingInstruction(java.lang.CharSequence target)
Writes a processing instruction.
|
void |
writeProcessingInstruction(java.lang.CharSequence target,
java.lang.CharSequence data)
Writes a processing instruction
|
void |
writeStartDocument()
Writes the XML Declaration.
|
void |
writeStartDocument(java.lang.CharSequence version)
Writes the XML Declaration.
|
void |
writeStartDocument(java.lang.CharSequence encoding,
java.lang.CharSequence version)
Writes the XML Declaration.
|
void |
writeStartElement(java.lang.CharSequence localName)
Writes a start tag to the output.
|
void |
writeStartElement(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName)
Writes a start tag to the output.
|
void |
writeStartElement(java.lang.CharSequence prefix,
java.lang.CharSequence localName,
java.lang.CharSequence namespaceURI)
Writes a start tag to the output.
|
public void setOutput(java.io.OutputStream out) throws XMLStreamException
out
- the output source with utf-8 encoding.XMLStreamException
public void setOutput(java.io.OutputStream out, java.lang.String encoding) throws XMLStreamException
out
- the output source.encoding
- the associated encoding.XMLStreamException
- if the specified encoding is not supported.public void setOutput(java.io.Writer writer) throws XMLStreamException
writer
- the output destination writer.XMLStreamException
UTF8StreamWriter
,
UTF8ByteBufferWriter
,
AppendableWriter
public void setRepairingNamespaces(boolean isRepairingNamespaces)
false
).isRepairingNamespaces
- true
if namespaces
are repaired; false
otherwise.public void setRepairingPrefix(java.lang.String repairingPrefix)
"ns"
).repairingPrefix
- the prefix root.public void setIndentation(java.lang.String indentation)
null
).indentation
- the indentation string.public void setLineSeparator(java.lang.String lineSeparator)
"\n"
).lineSeparator
- the line separator string.public void setAutomaticEmptyElements(boolean automaticEmptyElements)
false
).automaticEmptyElements
- true
if start element
immediately followed by end element results in an empty element
beign written; false
otherwise.public void setNoEmptyElementTag(boolean noEmptyElementTag)
false
).noEmptyElementTag
- true
if empty element tags
are replaced by start/end elements with no content;
false
otherwise.public void reset()
Reusable
public void writeStartElement(java.lang.CharSequence localName) throws XMLStreamException
XMLStreamWriter
writeStartElement
in interface XMLStreamWriter
localName
- local name of the tag.XMLStreamException
public void writeStartElement(java.lang.CharSequence namespaceURI, java.lang.CharSequence localName) throws XMLStreamException
XMLStreamWriter
writeStartElement
in interface XMLStreamWriter
namespaceURI
- the namespaceURI of the prefix to use.localName
- local name of the tag.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeStartElement(java.lang.CharSequence prefix, java.lang.CharSequence localName, java.lang.CharSequence namespaceURI) throws XMLStreamException
XMLStreamWriter
writeStartElement
in interface XMLStreamWriter
prefix
- the prefix of the tag.localName
- local name of the tag.namespaceURI
- the uri to bind the prefix to.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeEmptyElement(java.lang.CharSequence localName) throws XMLStreamException
XMLStreamWriter
writeEmptyElement
in interface XMLStreamWriter
localName
- local name of the tag.XMLStreamException
public void writeEmptyElement(java.lang.CharSequence namespaceURI, java.lang.CharSequence localName) throws XMLStreamException
XMLStreamWriter
writeEmptyElement
in interface XMLStreamWriter
namespaceURI
- the uri to bind the tag to.localName
- local name of the tag.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeEmptyElement(java.lang.CharSequence prefix, java.lang.CharSequence localName, java.lang.CharSequence namespaceURI) throws XMLStreamException
XMLStreamWriter
writeEmptyElement
in interface XMLStreamWriter
prefix
- the prefix of the tag.localName
- local name of the tag.namespaceURI
- the uri to bind the tag to.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeEndElement() throws XMLStreamException
XMLStreamWriter
writeEndElement
in interface XMLStreamWriter
XMLStreamException
public void writeEndDocument() throws XMLStreamException
XMLStreamWriter
writeEndDocument
in interface XMLStreamWriter
XMLStreamException
public void close() throws XMLStreamException
XMLStreamWriter
close
in interface XMLStreamWriter
XMLStreamException
public void flush() throws XMLStreamException
XMLStreamWriter
flush
in interface XMLStreamWriter
XMLStreamException
public void writeAttribute(java.lang.CharSequence localName, java.lang.CharSequence value) throws XMLStreamException
XMLStreamWriter
writeAttribute
in interface XMLStreamWriter
localName
- the local name of the attribute.value
- the value of the attribute.XMLStreamException
public void writeAttribute(java.lang.CharSequence namespaceURI, java.lang.CharSequence localName, java.lang.CharSequence value) throws XMLStreamException
XMLStreamWriter
writeAttribute
in interface XMLStreamWriter
namespaceURI
- the uri of the prefix for this attribute.localName
- the local name of the attribute.value
- the value of the attribute.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeAttribute(java.lang.CharSequence prefix, java.lang.CharSequence namespaceURI, java.lang.CharSequence localName, java.lang.CharSequence value) throws XMLStreamException
XMLStreamWriter
writeAttribute
in interface XMLStreamWriter
prefix
- the prefix for this attribute.namespaceURI
- the uri of the prefix for this attributelocalName
- the local name of the attribute.value
- the value of the attribute.XMLStreamException
- if the namespace URI has not been bound
to a prefix and this writer does not repair namespaces
.public void writeNamespace(java.lang.CharSequence prefix, java.lang.CharSequence namespaceURI) throws XMLStreamException
XMLStreamWriter
null
this method
will delegate to writeDefaultNamespace.writeNamespace
in interface XMLStreamWriter
prefix
- the prefix to bind this namespace to or null
namespaceURI
- the uri to bind the prefix.XMLStreamException
public void writeDefaultNamespace(java.lang.CharSequence namespaceURI) throws XMLStreamException
XMLStreamWriter
writeDefaultNamespace
in interface XMLStreamWriter
namespaceURI
- the uri to bind the default namespace to or
null
(to map the prefix to ""
URI)XMLStreamException
public void writeComment(java.lang.CharSequence data) throws XMLStreamException
XMLStreamWriter
writeComment
in interface XMLStreamWriter
data
- the data contained in the comment or null
XMLStreamException
public void writeProcessingInstruction(java.lang.CharSequence target) throws XMLStreamException
XMLStreamWriter
writeProcessingInstruction
in interface XMLStreamWriter
target
- the target of the processing instruction.XMLStreamException
public void writeProcessingInstruction(java.lang.CharSequence target, java.lang.CharSequence data) throws XMLStreamException
XMLStreamWriter
writeProcessingInstruction
in interface XMLStreamWriter
target
- the target of the processing instruction.data
- the data contained in the processing instruction.XMLStreamException
public void writeCData(java.lang.CharSequence data) throws XMLStreamException
XMLStreamWriter
writeCData
in interface XMLStreamWriter
data
- the data contained in the CData Section.XMLStreamException
public void writeDTD(java.lang.CharSequence dtd) throws XMLStreamException
XMLStreamWriter
writeDTD
in interface XMLStreamWriter
dtd
- the DTD to be written.XMLStreamException
public void writeEntityRef(java.lang.CharSequence name) throws XMLStreamException
XMLStreamWriter
writeEntityRef
in interface XMLStreamWriter
name
- the name of the entity.XMLStreamException
public void writeStartDocument() throws XMLStreamException
XMLStreamWriter
XMLOutputFactory
.writeStartDocument
in interface XMLStreamWriter
XMLStreamException
public void writeStartDocument(java.lang.CharSequence version) throws XMLStreamException
XMLStreamWriter
XMLOutputFactory
.writeStartDocument
in interface XMLStreamWriter
version
- the version of the xml document or null
.XMLStreamException
public void writeStartDocument(java.lang.CharSequence encoding, java.lang.CharSequence version) throws XMLStreamException
XMLStreamWriter
XMLOutputFactory
.writeStartDocument
in interface XMLStreamWriter
encoding
- the encoding of the xml declaration or null
.version
- the version of the xml document or null
.XMLStreamException
public void writeCharacters(java.lang.CharSequence text) throws XMLStreamException
XMLStreamWriter
writeCharacters
in interface XMLStreamWriter
text
- the value to write or null
.XMLStreamException
public void writeCharacters(char[] text, int start, int length) throws XMLStreamException
XMLStreamWriter
writeCharacters
in interface XMLStreamWriter
text
- the value to writestart
- the starting position in the array.length
- the number of characters to write.XMLStreamException
public java.lang.CharSequence getPrefix(java.lang.CharSequence uri) throws XMLStreamException
XMLStreamWriter
getPrefix
in interface XMLStreamWriter
uri
- namespace URInull
XMLStreamException
public void setPrefix(java.lang.CharSequence prefix, java.lang.CharSequence uri) throws XMLStreamException
XMLStreamWriter
setPrefix
in interface XMLStreamWriter
prefix
- the prefix to bind to the uri.uri
- the uri to bind to the prefix or null
XMLStreamException
public void setDefaultNamespace(java.lang.CharSequence uri) throws XMLStreamException
XMLStreamWriter
setDefaultNamespace
in interface XMLStreamWriter
uri
- the uri to bind to the default namespace or null
.XMLStreamException
public java.lang.Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException
XMLStreamWriter
getProperty
in interface XMLStreamWriter
name
- the name of the property.java.lang.IllegalArgumentException
- if the property is not supported.Copyright © 2005 - 2007 Javolution.