org.apache.rat.report.xml.writer.impl.base
Class XmlWriter

java.lang.Object
  extended by org.apache.rat.report.xml.writer.impl.base.XmlWriter
All Implemented Interfaces:
IXmlWriter

public final class XmlWriter
extends Object
implements IXmlWriter

Lightweight IXmlWriter implementation.

Requires a wrapper to be used safely in a multithreaded environment.

Not intended to be subclassed. Please copy and hack!


Constructor Summary
XmlWriter(Writer writer)
           
 
Method Summary
 IXmlWriter attribute(CharSequence name, CharSequence value)
          Writes an attribute of an element.
 IXmlWriter closeDocument()
          Closes all pending elements.
 IXmlWriter closeElement()
          Closes the last element written.
 IXmlWriter content(CharSequence content)
          Writes content.
 IXmlWriter openElement(CharSequence elementName)
          Writes the start of an element.
 IXmlWriter startDocument()
          Starts a document by writing a prolog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlWriter

public XmlWriter(Writer writer)
Method Detail

startDocument

public IXmlWriter startDocument()
                         throws IOException
Starts a document by writing a prolog. Calling this method is optional. When writing a document fragment, it should not be called.

Specified by:
startDocument in interface IXmlWriter
Returns:
this object
Throws:
OperationNotAllowedException - if called after the first element has been written or once a prolog has already been written
IOException

openElement

public IXmlWriter openElement(CharSequence elementName)
                       throws IOException
Writes the start of an element.

Specified by:
openElement in interface IXmlWriter
Parameters:
elementName - the name of the element, not null
Returns:
this object
Throws:
InvalidXmlException - if the name is not valid for an xml element
OperationNotAllowedException - if called after the first element has been closed
IOException

attribute

public IXmlWriter attribute(CharSequence name,
                            CharSequence value)
                     throws IOException
Writes an attribute of an element. Note that this is only allowed directly after openElement(CharSequence) or attribute(java.lang.CharSequence, java.lang.CharSequence).

Specified by:
attribute in interface IXmlWriter
Parameters:
name - the attribute name, not null
value - the attribute value, not null
Returns:
this object
Throws:
InvalidXmlException - if the name is not valid for an xml attribute or if a value for the attribute has already been written
OperationNotAllowedException - if called after content(CharSequence) or closeElement() or before any call to openElement(CharSequence)
IOException

content

public IXmlWriter content(CharSequence content)
                   throws IOException
Writes content. Calling this method will automatically Note that this method does not use CDATA.

Specified by:
content in interface IXmlWriter
Parameters:
content - the content to write
Returns:
this object
Throws:
OperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence) or after the first element has been closed
IOException

closeElement

public IXmlWriter closeElement()
                        throws IOException
Closes the last element written.

Specified by:
closeElement in interface IXmlWriter
Returns:
this object
Throws:
OperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence) or after the first element has been closed
IOException

closeDocument

public IXmlWriter closeDocument()
                         throws IOException
Closes all pending elements. When appropriate, resources are also flushed and closed. No exception is raised when called upon a document whose root element has already been closed.

Specified by:
closeDocument in interface IXmlWriter
Returns:
this object
Throws:
OperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence)
IOException


Copyright © 2006–2014 Apache Software Foundation. All rights reserved.