com.generationjava.io.xml
Class PrettyPrinterXmlWriter

java.lang.Object
  extended by com.generationjava.io.xml.DelegatingXmlWriter
      extended by com.generationjava.io.xml.PrettyPrinterXmlWriter
All Implemented Interfaces:
XmlWriter

public class PrettyPrinterXmlWriter
extends DelegatingXmlWriter

Handles indentation on the fly.


Constructor Summary
PrettyPrinterXmlWriter(XmlWriter xmlWriter)
          Create an PrettyPrinterXmlWriter on top of an existing XmlWriter.
 
Method Summary
 XmlWriter endEntity()
          End the current entity.
 XmlWriter setIndent(String indent)
          Specify the string to prepend to a line for each level of indent.
 XmlWriter setNewline(String newline)
          Specify the string used to terminate each line when pretty printing.
 XmlWriter writeCData(String cdata)
          Write out a chunk of CDATA.
 XmlWriter writeComment(String comment)
          Write out a chunk of comment.
 XmlWriter writeEmptyEntity(String name)
          A helper method.
 XmlWriter writeEntity(String name)
          Begin to write out an entity.
 XmlWriter writeEntityWithText(String name, Object text)
          A helper method.
 XmlWriter writeText(Object text)
          Output body text.
 XmlWriter writeXmlVersion()
          Makes it easy to output the xml version if such a thing is desired.
 XmlWriter writeXmlVersion(String version, String encoding)
           
 XmlWriter writeXmlVersion(String version, String encoding, String standalone)
          Output the version, encoding and standalone nature of an xml file.
 
Methods inherited from class com.generationjava.io.xml.DelegatingXmlWriter
close, getWriter, writeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrettyPrinterXmlWriter

public PrettyPrinterXmlWriter(XmlWriter xmlWriter)
Create an PrettyPrinterXmlWriter on top of an existing XmlWriter.

Method Detail

setIndent

public XmlWriter setIndent(String indent)
Specify the string to prepend to a line for each level of indent. It is 2 spaces (" ") by default. Some may prefer a single tab ("\t") or a different number of spaces. Specifying an empty string will turn off indentation when pretty printing.

Parameters:
String - representing one level of indentation while pretty printing.

setNewline

public XmlWriter setNewline(String newline)
Specify the string used to terminate each line when pretty printing. It is a single newline ("\n") by default. Users who need to read generated XML documents in Windows editors like Notepad may wish to set this to a carriage return/newline sequence ("\r\n"). Specifying an empty string will turn off generation of line breaks when pretty printing.

Parameters:
String - representing the newline sequence when pretty printing.

writeXmlVersion

public XmlWriter writeXmlVersion()
                          throws IOException
Description copied from class: DelegatingXmlWriter
Makes it easy to output the xml version if such a thing is desired. While it usually is desired, it is less surprising not to handle it.

Specified by:
writeXmlVersion in interface XmlWriter
Overrides:
writeXmlVersion in class DelegatingXmlWriter
Throws:
IOException

writeXmlVersion

public XmlWriter writeXmlVersion(String version,
                                 String encoding)
                          throws IOException
Specified by:
writeXmlVersion in interface XmlWriter
Overrides:
writeXmlVersion in class DelegatingXmlWriter
Throws:
IOException
See Also:
DelegatingXmlWriter.writeXmlVersion(String, String, String)

writeXmlVersion

public XmlWriter writeXmlVersion(String version,
                                 String encoding,
                                 String standalone)
                          throws IOException
Description copied from class: DelegatingXmlWriter
Output the version, encoding and standalone nature of an xml file.

Specified by:
writeXmlVersion in interface XmlWriter
Overrides:
writeXmlVersion in class DelegatingXmlWriter
Throws:
IOException

writeEntity

public XmlWriter writeEntity(String name)
                      throws IOException
Description copied from class: DelegatingXmlWriter
Begin to write out an entity. Unlike the helper tags, this tag will need to be ended with the endEntity method.

Specified by:
writeEntity in interface XmlWriter
Overrides:
writeEntity in class DelegatingXmlWriter
Parameters:
name - String name of tag
Throws:
IOException

endEntity

public XmlWriter endEntity()
                    throws IOException
End the current entity. This will throw an exception if it is called when there is not a currently open entity.

Specified by:
endEntity in interface XmlWriter
Overrides:
endEntity in class DelegatingXmlWriter
Throws:
IOException

writeText

public XmlWriter writeText(Object text)
                    throws IOException
Output body text. Any xml characters are escaped.

Specified by:
writeText in interface XmlWriter
Overrides:
writeText in class DelegatingXmlWriter
Throws:
IOException

writeCData

public XmlWriter writeCData(String cdata)
                     throws IOException
Write out a chunk of CDATA. This helper method surrounds the passed in data with the CDATA tag.

Specified by:
writeCData in interface XmlWriter
Overrides:
writeCData in class DelegatingXmlWriter
Parameters:
String - of CDATA text.
Throws:
IOException

writeComment

public XmlWriter writeComment(String comment)
                       throws IOException
Write out a chunk of comment. This helper method surrounds the passed in data with the xml comment tag.

Specified by:
writeComment in interface XmlWriter
Overrides:
writeComment in class DelegatingXmlWriter
Parameters:
String - of text to comment.
Throws:
IOException

writeEntityWithText

public XmlWriter writeEntityWithText(String name,
                                     Object text)
                              throws IOException
A helper method. It writes out an entity which contains only text.

Specified by:
writeEntityWithText in interface XmlWriter
Overrides:
writeEntityWithText in class DelegatingXmlWriter
Parameters:
name - String name of tag
text - String of text to go inside the tag
Throws:
IOException

writeEmptyEntity

public XmlWriter writeEmptyEntity(String name)
                           throws IOException
A helper method. It writes out empty entities.

Specified by:
writeEmptyEntity in interface XmlWriter
Overrides:
writeEmptyEntity in class DelegatingXmlWriter
Parameters:
name - String name of tag
Throws:
IOException


Copyright © 2000-2007 OSJava. All Rights Reserved.