javanet.staxutils.io
Class StAXStreamWriter

java.lang.Object
  extended by javanet.staxutils.io.StAXStreamWriter
All Implemented Interfaces:
XMLStreamWriter

public class StAXStreamWriter
extends Object
implements XMLStreamWriter

An XMLStreamWriter implementation that writes to a character stream.

Version:
$Revision: 1.1 $
Author:
Christian Niles

Constructor Summary
StAXStreamWriter(OutputStream stream)
          Constructs a StAXStreamWriter that writes to the provided OutputStream using the platform default encoding.
StAXStreamWriter(OutputStream stream, String encoding)
          Constructs a StAXStreamWriter that writes to the provided OutputStream using the specified encoding.
StAXStreamWriter(Writer writer)
          Constructs a StAXStreamWriter that writes to the provided Writer.
StAXStreamWriter(Writer writer, NamespaceContext rootContext)
          Constructs a StAXStreamWriter that writes to the provided Writer.
 
Method Summary
 void close()
           
protected  void closeElementContext()
          Closes the current ElementContext, writing any cached content and making it read-only.
 void flush()
           
 String getCurrentPath()
          Returns the current position of the writer as a path of QName strings.
 NamespaceContext getNamespaceContext()
           
 String getPrefix(String uri)
           
 Object getProperty(String name)
           
 void setDefaultNamespace(String uri)
           
 void setNamespaceContext(NamespaceContext context)
           
 void setPrefix(String prefix, String uri)
           
 void writeAttribute(QName name, String value)
           
 void writeAttribute(String localName, String value)
           
 void writeAttribute(String namespaceURI, String localName, String value)
           
 void writeAttribute(String prefix, String namespaceURI, String localName, String value)
           
 void writeCData(String data)
           
 void writeCharacters(char[] text, int start, int len)
           
 void writeCharacters(String text)
           
 void writeComment(String data)
           
 void writeDefaultNamespace(String namespaceURI)
           
 void writeDTD(String dtd)
           
 void writeEmptyElement(String localName)
           
 void writeEmptyElement(String namespaceURI, String localName)
           
 void writeEmptyElement(String prefix, String localName, String namespaceURI)
           
 void writeEndDocument()
           
 void writeEndElement()
           
 void writeEntityRef(String name)
           
 void writeNamespace(String prefix, String namespaceURI)
           
 void writeProcessingInstruction(String target)
           
 void writeProcessingInstruction(String target, String data)
           
 void writeStartDocument()
           
 void writeStartDocument(String version)
           
 void writeStartDocument(String encoding, String version)
           
 void writeStartElement(String localName)
           
 void writeStartElement(String namespaceURI, String localName)
           
 void writeStartElement(String prefix, String localName, String namespaceURI)
           
 void writeStartElement(String prefix, String localName, String namespaceURI, boolean isEmpty)
          Core start tag output method called by all other writeXXXElement methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StAXStreamWriter

public StAXStreamWriter(OutputStream stream)
Constructs a StAXStreamWriter that writes to the provided OutputStream using the platform default encoding.

Parameters:
stream - The destination stream.

StAXStreamWriter

public StAXStreamWriter(OutputStream stream,
                        String encoding)
                 throws UnsupportedEncodingException
Constructs a StAXStreamWriter that writes to the provided OutputStream using the specified encoding.

Parameters:
stream - The destination stream.
encoding - The output encoding.
Throws:
UnsupportedEncodingException - If the encoding isn't supported.

StAXStreamWriter

public StAXStreamWriter(Writer writer)
Constructs a StAXStreamWriter that writes to the provided Writer.

Parameters:
writer - The destination Writer instance.

StAXStreamWriter

public StAXStreamWriter(Writer writer,
                        NamespaceContext rootContext)
Constructs a StAXStreamWriter that writes to the provided Writer.

Parameters:
writer - The destination Writer instance.
rootContext - The root namespace context.
Method Detail

close

public void close()
           throws XMLStreamException
Specified by:
close in interface XMLStreamWriter
Throws:
XMLStreamException

flush

public void flush()
           throws XMLStreamException
Specified by:
flush in interface XMLStreamWriter
Throws:
XMLStreamException

getPrefix

public String getPrefix(String uri)
                 throws XMLStreamException
Specified by:
getPrefix in interface XMLStreamWriter
Throws:
XMLStreamException

getProperty

public Object getProperty(String name)
                   throws IllegalArgumentException
Specified by:
getProperty in interface XMLStreamWriter
Throws:
IllegalArgumentException

writeStartDocument

public void writeStartDocument()
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(String version)
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartDocument

public void writeStartDocument(String encoding,
                               String version)
                        throws XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeEndDocument

public void writeEndDocument()
                      throws XMLStreamException
Specified by:
writeEndDocument in interface XMLStreamWriter
Throws:
XMLStreamException

writeCData

public void writeCData(String data)
                throws XMLStreamException
Specified by:
writeCData in interface XMLStreamWriter
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(char[] text,
                            int start,
                            int len)
                     throws XMLStreamException
Specified by:
writeCharacters in interface XMLStreamWriter
Throws:
XMLStreamException

writeCharacters

public void writeCharacters(String text)
                     throws XMLStreamException
Specified by:
writeCharacters in interface XMLStreamWriter
Throws:
XMLStreamException

writeComment

public void writeComment(String data)
                  throws XMLStreamException
Specified by:
writeComment in interface XMLStreamWriter
Throws:
XMLStreamException

writeDTD

public void writeDTD(String dtd)
              throws XMLStreamException
Specified by:
writeDTD in interface XMLStreamWriter
Throws:
XMLStreamException

writeEntityRef

public void writeEntityRef(String name)
                    throws XMLStreamException
Specified by:
writeEntityRef in interface XMLStreamWriter
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(String target,
                                       String data)
                                throws XMLStreamException
Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Throws:
XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(String target)
                                throws XMLStreamException
Specified by:
writeProcessingInstruction in interface XMLStreamWriter
Throws:
XMLStreamException

getNamespaceContext

public NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface XMLStreamWriter

setNamespaceContext

public void setNamespaceContext(NamespaceContext context)
                         throws XMLStreamException
Specified by:
setNamespaceContext in interface XMLStreamWriter
Throws:
XMLStreamException

setDefaultNamespace

public void setDefaultNamespace(String uri)
                         throws XMLStreamException
Specified by:
setDefaultNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

setPrefix

public void setPrefix(String prefix,
                      String uri)
               throws XMLStreamException
Specified by:
setPrefix in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String prefix,
                              String localName,
                              String namespaceURI,
                              boolean isEmpty)
                       throws XMLStreamException
Core start tag output method called by all other writeXXXElement methods.

Parameters:
prefix - The tag prefix.
localName - The tag local name.
namespaceURI - The namespace URI of the prefix.
isEmpty - Whether the tag is empty.
Throws:
XMLStreamException - If an error occurs writing the tag to the stream.

writeStartElement

public void writeStartElement(String prefix,
                              String localName,
                              String namespaceURI)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String namespaceURI,
                              String localName)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String localName)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String prefix,
                              String localName,
                              String namespaceURI)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String namespaceURI,
                              String localName)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String localName)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(QName name,
                           String value)
                    throws XMLStreamException
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String prefix,
                           String namespaceURI,
                           String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String namespaceURI,
                           String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String localName,
                           String value)
                    throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Throws:
XMLStreamException

writeDefaultNamespace

public void writeDefaultNamespace(String namespaceURI)
                           throws XMLStreamException
Specified by:
writeDefaultNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

writeNamespace

public void writeNamespace(String prefix,
                           String namespaceURI)
                    throws XMLStreamException
Specified by:
writeNamespace in interface XMLStreamWriter
Throws:
XMLStreamException

writeEndElement

public void writeEndElement()
                     throws XMLStreamException
Specified by:
writeEndElement in interface XMLStreamWriter
Throws:
XMLStreamException

getCurrentPath

public String getCurrentPath()
Returns the current position of the writer as a path of QName strings.

Returns:
The current position of the writer.

closeElementContext

protected void closeElementContext()
                            throws XMLStreamException
Closes the current ElementContext, writing any cached content and making it read-only. If the current context is empty, it will be popped and replaced with its parent context. If no context is open, this method has no effects.

Throws:
XMLStreamException - If an error occurs flushing any element content.