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.XMLStreamExceptionpublic 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.XMLStreamExceptionUTF8StreamWriter,
UTF8ByteBufferWriter,
AppendableWriterpublic 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()
Reusablepublic void writeStartElement(java.lang.CharSequence localName)
throws XMLStreamException
XMLStreamWriterwriteStartElement in interface XMLStreamWriterlocalName - local name of the tag.XMLStreamExceptionpublic void writeStartElement(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName)
throws XMLStreamException
XMLStreamWriterwriteStartElement in interface XMLStreamWriternamespaceURI - 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
XMLStreamWriterwriteStartElement in interface XMLStreamWriterprefix - 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
XMLStreamWriterwriteEmptyElement in interface XMLStreamWriterlocalName - local name of the tag.XMLStreamExceptionpublic void writeEmptyElement(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName)
throws XMLStreamException
XMLStreamWriterwriteEmptyElement in interface XMLStreamWriternamespaceURI - 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
XMLStreamWriterwriteEmptyElement in interface XMLStreamWriterprefix - 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
XMLStreamWriterwriteEndElement in interface XMLStreamWriterXMLStreamExceptionpublic void writeEndDocument()
throws XMLStreamException
XMLStreamWriterwriteEndDocument in interface XMLStreamWriterXMLStreamExceptionpublic void close()
throws XMLStreamException
XMLStreamWriterclose in interface XMLStreamWriterXMLStreamExceptionpublic void flush()
throws XMLStreamException
XMLStreamWriterflush in interface XMLStreamWriterXMLStreamExceptionpublic void writeAttribute(java.lang.CharSequence localName,
java.lang.CharSequence value)
throws XMLStreamException
XMLStreamWriterwriteAttribute in interface XMLStreamWriterlocalName - the local name of the attribute.value - the value of the attribute.XMLStreamExceptionpublic void writeAttribute(java.lang.CharSequence namespaceURI,
java.lang.CharSequence localName,
java.lang.CharSequence value)
throws XMLStreamException
XMLStreamWriterwriteAttribute in interface XMLStreamWriternamespaceURI - 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
XMLStreamWriterwriteAttribute in interface XMLStreamWriterprefix - 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
XMLStreamWriternull this method
will delegate to writeDefaultNamespace.writeNamespace in interface XMLStreamWriterprefix - the prefix to bind this namespace to or nullnamespaceURI - the uri to bind the prefix.XMLStreamExceptionpublic void writeDefaultNamespace(java.lang.CharSequence namespaceURI)
throws XMLStreamException
XMLStreamWriterwriteDefaultNamespace in interface XMLStreamWriternamespaceURI - the uri to bind the default namespace to or
null (to map the prefix to "" URI)XMLStreamExceptionpublic void writeComment(java.lang.CharSequence data)
throws XMLStreamException
XMLStreamWriterwriteComment in interface XMLStreamWriterdata - the data contained in the comment or nullXMLStreamExceptionpublic void writeProcessingInstruction(java.lang.CharSequence target)
throws XMLStreamException
XMLStreamWriterwriteProcessingInstruction in interface XMLStreamWritertarget - the target of the processing instruction.XMLStreamExceptionpublic void writeProcessingInstruction(java.lang.CharSequence target,
java.lang.CharSequence data)
throws XMLStreamException
XMLStreamWriterwriteProcessingInstruction in interface XMLStreamWritertarget - the target of the processing instruction.data - the data contained in the processing instruction.XMLStreamExceptionpublic void writeCData(java.lang.CharSequence data)
throws XMLStreamException
XMLStreamWriterwriteCData in interface XMLStreamWriterdata - the data contained in the CData Section.XMLStreamExceptionpublic void writeDTD(java.lang.CharSequence dtd)
throws XMLStreamException
XMLStreamWriterwriteDTD in interface XMLStreamWriterdtd - the DTD to be written.XMLStreamExceptionpublic void writeEntityRef(java.lang.CharSequence name)
throws XMLStreamException
XMLStreamWriterwriteEntityRef in interface XMLStreamWritername - the name of the entity.XMLStreamExceptionpublic void writeStartDocument()
throws XMLStreamException
XMLStreamWriterXMLOutputFactory.writeStartDocument in interface XMLStreamWriterXMLStreamExceptionpublic void writeStartDocument(java.lang.CharSequence version)
throws XMLStreamException
XMLStreamWriterXMLOutputFactory.writeStartDocument in interface XMLStreamWriterversion - the version of the xml document or null.XMLStreamExceptionpublic void writeStartDocument(java.lang.CharSequence encoding,
java.lang.CharSequence version)
throws XMLStreamException
XMLStreamWriterXMLOutputFactory.writeStartDocument in interface XMLStreamWriterencoding - the encoding of the xml declaration or null.version - the version of the xml document or null.XMLStreamExceptionpublic void writeCharacters(java.lang.CharSequence text)
throws XMLStreamException
XMLStreamWriterwriteCharacters in interface XMLStreamWritertext - the value to write or null.XMLStreamExceptionpublic void writeCharacters(char[] text,
int start,
int length)
throws XMLStreamException
XMLStreamWriterwriteCharacters in interface XMLStreamWritertext - the value to writestart - the starting position in the array.length - the number of characters to write.XMLStreamExceptionpublic java.lang.CharSequence getPrefix(java.lang.CharSequence uri)
throws XMLStreamException
XMLStreamWritergetPrefix in interface XMLStreamWriteruri - namespace URInullXMLStreamExceptionpublic void setPrefix(java.lang.CharSequence prefix,
java.lang.CharSequence uri)
throws XMLStreamException
XMLStreamWritersetPrefix in interface XMLStreamWriterprefix - the prefix to bind to the uri.uri - the uri to bind to the prefix or nullXMLStreamExceptionpublic void setDefaultNamespace(java.lang.CharSequence uri)
throws XMLStreamException
XMLStreamWritersetDefaultNamespace in interface XMLStreamWriteruri - the uri to bind to the default namespace or null.XMLStreamExceptionpublic java.lang.Object getProperty(java.lang.String name)
throws java.lang.IllegalArgumentException
XMLStreamWritergetProperty in interface XMLStreamWritername - the name of the property.java.lang.IllegalArgumentException - if the property is not supported.Copyright © 2005 - 2007 Javolution.