J avolution v5.5 (J2SE 1.6+)

javolution.xml.stream
Class XMLStreamWriterImpl

java.lang.Object
  extended by javolution.xml.stream.XMLStreamWriterImpl
All Implemented Interfaces:
Reusable, XMLStreamWriter

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.

Version:
4.0, September 4, 2006
Author:
Jean-Marie Dautelle

Constructor Summary
XMLStreamWriterImpl()
          Default constructor.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLStreamWriterImpl

public XMLStreamWriterImpl()
Default constructor.

Method Detail

setOutput

public void setOutput(java.io.OutputStream out)
               throws XMLStreamException
Sets the output stream destination for this XML stream writer (UTF-8 encoding).

Parameters:
out - the output source with utf-8 encoding.
Throws:
XMLStreamException

setOutput

public void setOutput(java.io.OutputStream out,
                      java.lang.String encoding)
               throws XMLStreamException
Sets the output stream destination and encoding for this XML stream writer.

Parameters:
out - the output source.
encoding - the associated encoding.
Throws:
XMLStreamException - if the specified encoding is not supported.

setOutput

public void setOutput(java.io.Writer writer)
               throws XMLStreamException
Sets the writer output destination for this XML stream writer.

Parameters:
writer - the output destination writer.
Throws:
XMLStreamException
See Also:
UTF8StreamWriter, UTF8ByteBufferWriter, AppendableWriter

setRepairingNamespaces

public void setRepairingNamespaces(boolean isRepairingNamespaces)
Requires this writer to create a new prefix when a namespace has none (default false).

Parameters:
isRepairingNamespaces - true if namespaces are repaired; false otherwise.

setRepairingPrefix

public 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").

Parameters:
repairingPrefix - the prefix root.

setIndentation

public void setIndentation(java.lang.String indentation)
Specifies the indentation string; non-null indentation forces the writer to write elements into separate lines (default null).

Parameters:
indentation - the indentation string.

setLineSeparator

public void setLineSeparator(java.lang.String lineSeparator)
Specifies the line separator (default "\n").

Parameters:
lineSeparator - the line separator string.

setAutomaticEmptyElements

public 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).

Parameters:
automaticEmptyElements - true if start element immediately followed by end element results in an empty element beign written; false otherwise.

setNoEmptyElementTag

public void setNoEmptyElementTag(boolean noEmptyElementTag)
Prevent this writer from using empty element tags (default false).

Parameters:
noEmptyElementTag - true if empty element tags are replaced by start/end elements with no content; false otherwise.

reset

public void reset()
Description copied from interface: Reusable
Resets the internal state of this object to its default values.

Specified by:
reset in interface Reusable

writeStartElement

public void writeStartElement(java.lang.CharSequence localName)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a start tag to the output. All writeStartElement methods open a new scope in the internal namespace context. Writing the corresponding EndElement causes the scope to be closed.

Specified by:
writeStartElement in interface XMLStreamWriter
Parameters:
localName - local name of the tag.
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(java.lang.CharSequence namespaceURI,
                              java.lang.CharSequence localName)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a start tag to the output.

Specified by:
writeStartElement in interface XMLStreamWriter
Parameters:
namespaceURI - the namespaceURI of the prefix to use.
localName - local name of the tag.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeStartElement

public void writeStartElement(java.lang.CharSequence prefix,
                              java.lang.CharSequence localName,
                              java.lang.CharSequence namespaceURI)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a start tag to the output.

Specified by:
writeStartElement in interface XMLStreamWriter
Parameters:
prefix - the prefix of the tag.
localName - local name of the tag.
namespaceURI - the uri to bind the prefix to.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeEmptyElement

public void writeEmptyElement(java.lang.CharSequence localName)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an empty element tag to the output.

Specified by:
writeEmptyElement in interface XMLStreamWriter
Parameters:
localName - local name of the tag.
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(java.lang.CharSequence namespaceURI,
                              java.lang.CharSequence localName)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an empty element tag to the output.

Specified by:
writeEmptyElement in interface XMLStreamWriter
Parameters:
namespaceURI - the uri to bind the tag to.
localName - local name of the tag.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeEmptyElement

public void writeEmptyElement(java.lang.CharSequence prefix,
                              java.lang.CharSequence localName,
                              java.lang.CharSequence namespaceURI)
                       throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an empty element tag to the output.

Specified by:
writeEmptyElement in interface XMLStreamWriter
Parameters:
prefix - the prefix of the tag.
localName - local name of the tag.
namespaceURI - the uri to bind the tag to.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeEndElement

public void writeEndElement()
                     throws XMLStreamException
Description copied from interface: XMLStreamWriter
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.

Specified by:
writeEndElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEndDocument

public void writeEndDocument()
                      throws XMLStreamException
Description copied from interface: XMLStreamWriter
Closes any start tags and writes corresponding end tags.

Specified by:
writeEndDocument in interface XMLStreamWriter
Throws:
XMLStreamException

close

public void close()
           throws XMLStreamException
Description copied from interface: XMLStreamWriter
Close this writer and free any resources associated with the writer. This must not close the underlying output stream.

Specified by:
close in interface XMLStreamWriter
Throws:
XMLStreamException

flush

public void flush()
           throws XMLStreamException
Description copied from interface: XMLStreamWriter
Write any cached data to the underlying output mechanism.

Specified by:
flush in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(java.lang.CharSequence localName,
                           java.lang.CharSequence value)
                    throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an attribute to the output stream without a prefix.

Specified by:
writeAttribute in interface XMLStreamWriter
Parameters:
localName - the local name of the attribute.
value - the value of the attribute.
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(java.lang.CharSequence namespaceURI,
                           java.lang.CharSequence localName,
                           java.lang.CharSequence value)
                    throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an attribute to the output stream.

Specified by:
writeAttribute in interface XMLStreamWriter
Parameters:
namespaceURI - the uri of the prefix for this attribute.
localName - the local name of the attribute.
value - the value of the attribute.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeAttribute

public void writeAttribute(java.lang.CharSequence prefix,
                           java.lang.CharSequence namespaceURI,
                           java.lang.CharSequence localName,
                           java.lang.CharSequence value)
                    throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an attribute to the output stream.

Specified by:
writeAttribute in interface XMLStreamWriter
Parameters:
prefix - the prefix for this attribute.
namespaceURI - the uri of the prefix for this attribute
localName - the local name of the attribute.
value - the value of the attribute.
Throws:
XMLStreamException - if the namespace URI has not been bound to a prefix and this writer does not repair namespaces.

writeNamespace

public void writeNamespace(java.lang.CharSequence prefix,
                           java.lang.CharSequence namespaceURI)
                    throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a namespace to the output stream. If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace.

Specified by:
writeNamespace in interface XMLStreamWriter
Parameters:
prefix - the prefix to bind this namespace to or null
namespaceURI - the uri to bind the prefix.
Throws:
XMLStreamException

writeDefaultNamespace

public void writeDefaultNamespace(java.lang.CharSequence namespaceURI)
                           throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes the default namespace to the stream.

Specified by:
writeDefaultNamespace in interface XMLStreamWriter
Parameters:
namespaceURI - the uri to bind the default namespace to or null (to map the prefix to "" URI)
Throws:
XMLStreamException

writeComment

public void writeComment(java.lang.CharSequence data)
                  throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an xml comment with the data enclosed.

Specified by:
writeComment in interface XMLStreamWriter
Parameters:
data - the data contained in the comment or null
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(java.lang.CharSequence target)
                                throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a processing instruction.

Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Parameters:
target - the target of the processing instruction.
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(java.lang.CharSequence target,
                                       java.lang.CharSequence data)
                                throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a processing instruction

Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Parameters:
target - the target of the processing instruction.
data - the data contained in the processing instruction.
Throws:
XMLStreamException

writeCData

public void writeCData(java.lang.CharSequence data)
                throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a CData section.

Specified by:
writeCData in interface XMLStreamWriter
Parameters:
data - the data contained in the CData Section.
Throws:
XMLStreamException

writeDTD

public void writeDTD(java.lang.CharSequence dtd)
              throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes a DTD section (representing the entire doctypedecl production from the XML 1.0 specification).

Specified by:
writeDTD in interface XMLStreamWriter
Parameters:
dtd - the DTD to be written.
Throws:
XMLStreamException

writeEntityRef

public void writeEntityRef(java.lang.CharSequence name)
                    throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes an entity reference

Specified by:
writeEntityRef in interface XMLStreamWriter
Parameters:
name - the name of the entity.
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument()
                        throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes the XML Declaration. Defaults the XML version to 1.0 and the encoding (if any) to the one specified when the instance is created using XMLOutputFactory.

Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(java.lang.CharSequence version)
                        throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes the XML Declaration. Default the encoding (if any) to the one specified when the instance is created using XMLOutputFactory.

Specified by:
writeStartDocument in interface XMLStreamWriter
Parameters:
version - the version of the xml document or null.
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(java.lang.CharSequence encoding,
                               java.lang.CharSequence version)
                        throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes the XML Declaration. Note that the encoding parameter does not set the actual encoding of the underlying output. That must be set when the instance when the instance is created using XMLOutputFactory.

Specified by:
writeStartDocument in interface XMLStreamWriter
Parameters:
encoding - the encoding of the xml declaration or null.
version - the version of the xml document or null.
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(java.lang.CharSequence text)
                     throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes text to the output.

Specified by:
writeCharacters in interface XMLStreamWriter
Parameters:
text - the value to write or null.
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(char[] text,
                            int start,
                            int length)
                     throws XMLStreamException
Description copied from interface: XMLStreamWriter
Writes text to the output.

Specified by:
writeCharacters in interface XMLStreamWriter
Parameters:
text - the value to write
start - the starting position in the array.
length - the number of characters to write.
Throws:
XMLStreamException

getPrefix

public java.lang.CharSequence getPrefix(java.lang.CharSequence uri)
                                 throws XMLStreamException
Description copied from interface: XMLStreamWriter
Gets the prefix the specified uri is bound to.

Specified by:
getPrefix in interface XMLStreamWriter
Parameters:
uri - namespace URI
Returns:
the prefix for the URI or null
Throws:
XMLStreamException

setPrefix

public void setPrefix(java.lang.CharSequence prefix,
                      java.lang.CharSequence uri)
               throws XMLStreamException
Description copied from interface: XMLStreamWriter
Sets the prefix the uri is bound to. This prefix is bound in the scope of the current START_ELEMENT / END_ELEMENT pair. If this method is called before a START_ELEMENT has been written the prefix is bound in the root scope.

Specified by:
setPrefix in interface XMLStreamWriter
Parameters:
prefix - the prefix to bind to the uri.
uri - the uri to bind to the prefix or null
Throws:
XMLStreamException

setDefaultNamespace

public void setDefaultNamespace(java.lang.CharSequence uri)
                         throws XMLStreamException
Description copied from interface: XMLStreamWriter
Binds a URI to the default namespace. This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair. If this method is called before a START_ELEMENT has been written the uri is bound in the root scope.

Specified by:
setDefaultNamespace in interface XMLStreamWriter
Parameters:
uri - the uri to bind to the default namespace or null.
Throws:
XMLStreamException

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws java.lang.IllegalArgumentException
Description copied from interface: XMLStreamWriter
Gets the value of a feature/property from the underlying implementation.

Specified by:
getProperty in interface XMLStreamWriter
Parameters:
name - the name of the property.
Returns:
the value of the property.
Throws:
java.lang.IllegalArgumentException - if the property is not supported.

J avolution v5.5 (J2SE 1.6+)

Copyright © 2005 - 2009 Javolution.