com.flat502.rox.utils
Class XmlPrettyPrinter

java.lang.Object
  extended by com.flat502.rox.utils.XmlPrettyPrinter
All Implemented Interfaces:
XmlPrinter

public class XmlPrettyPrinter
extends java.lang.Object
implements XmlPrinter

An implementation of XmlPrinter that produces XML formatted for readability.

This implementation uses line breaks and indentation to format XML in a way that is more easily consumed by mere mortals. As a result this implementation produces somewhat inefficient XML.


Constructor Summary
XmlPrettyPrinter(java.io.OutputStream out)
           
XmlPrettyPrinter(java.io.PrintStream out)
           
 
Method Summary
 void closeTag(java.lang.String name)
          Invoked when a tag is closed.
 void finishDocument()
          Invoked as the final call to an instance of this interface.
static void main(java.lang.String[] args)
           
 void openTag(java.lang.String name)
          Invoked when a tag is opened.
 void writeHeader(java.lang.String version, java.nio.charset.Charset charSet)
          Invoked as the first method on an instance of this interface.
 void writeValue(java.lang.String value)
          Invoked when a value is being output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlPrettyPrinter

public XmlPrettyPrinter(java.io.OutputStream out)

XmlPrettyPrinter

public XmlPrettyPrinter(java.io.PrintStream out)
Method Detail

writeHeader

public void writeHeader(java.lang.String version,
                        java.nio.charset.Charset charSet)
Description copied from interface: XmlPrinter
Invoked as the first method on an instance of this interface.

Implementations should produce an appropriate XML header, ideally including the information provided.

Implementations are not required to act on this call until XmlPrinter.finishDocument() is invoked.

Specified by:
writeHeader in interface XmlPrinter
Parameters:
version - The XML version this document should comply with.
charSet - The character encoding this document is being encoded with.

openTag

public void openTag(java.lang.String name)
Description copied from interface: XmlPrinter
Invoked when a tag is opened.

Implementations are not required to act on this call until XmlPrinter.finishDocument() is invoked.

Specified by:
openTag in interface XmlPrinter
Parameters:
name - The name of the tag being opened.

writeValue

public void writeValue(java.lang.String value)
Description copied from interface: XmlPrinter
Invoked when a value is being output.

Implementations are not required to act on this call until XmlPrinter.finishDocument() is invoked.

Specified by:
writeValue in interface XmlPrinter
Parameters:
value - The value associated with the most recently opened tag.

closeTag

public void closeTag(java.lang.String name)
Description copied from interface: XmlPrinter
Invoked when a tag is closed.

Implementations are not required to act on this call until XmlPrinter.finishDocument() is invoked.

Specified by:
closeTag in interface XmlPrinter
Parameters:
name - The name of the tag being closed.

finishDocument

public void finishDocument()
Description copied from interface: XmlPrinter
Invoked as the final call to an instance of this interface.

This gives implementations a chance to flush any cached information.

Specified by:
finishDocument in interface XmlPrinter

main

public static void main(java.lang.String[] args)