Package com.day.cq.commons
Class SimpleXml
- java.lang.Object
 - 
- com.day.cq.commons.SimpleXml
 
 
- 
public class SimpleXml extends java.lang.ObjectTheSimpleXmlclass facilitates the creation of an XML document. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description classSimpleXml.ElementTheSimpleXml.Elementreperesents an XML element. 
- 
Constructor Summary
Constructors Constructor Description SimpleXml(java.io.PrintWriter w)Creates aSimpleXmlinstance using the specified print writer for the output of the XML document. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleXmlclose()Closes the most recent open element.voidcloseDocument()Closes the XML document after closing all open elements.java.io.PrintWritergetWriter()Returns the print writer used for the output of the XML document.SimpleXmlomitXmlDeclaration(boolean omit)Defines whether the XML declaration should be omitted.SimpleXmlopen()Opens the XML document.SimpleXml.Elementopen(java.lang.String name)Opens and returns a new XML element with the specified name.SimpleXml.Elementopen(java.lang.String localName, java.lang.String name)Opens and returns a new XML element with the specified name.SimpleXml.Elementopen(java.lang.String name, java.lang.String content, boolean cdata)Opens and returns a new XML element with the specified name and content.SimpleXml.Elementopen(java.lang.String uri, java.lang.String localName, java.lang.String name)Opens and returns a new XML element with the specified name.SimpleXmlopenDocument()Opens the XML document.SimpleXmlsetDocumentLocator(org.xml.sax.Locator locator)Sets the document locator of the output.SimpleXmlsetEncoding(java.lang.String encoding)Sets the character encoding of the output.SimpleXmlsetIndent(boolean indent)Defines whether the output should use indetation.SimpleXmltidyUp()Closes all currently open elements. 
 - 
 
- 
- 
Constructor Detail
- 
SimpleXml
public SimpleXml(java.io.PrintWriter w) throws java.io.IOExceptionCreates aSimpleXmlinstance using the specified print writer for the output of the XML document.- Parameters:
 w- The writer to send the XML document to- Throws:
 java.io.IOException- If initialization fails
 
 - 
 
- 
Method Detail
- 
getWriter
public java.io.PrintWriter getWriter()
Returns the print writer used for the output of the XML document.- Returns:
 - The print writer
 
 
- 
setIndent
public SimpleXml setIndent(boolean indent)
Defines whether the output should use indetation. Default istrue.- Parameters:
 indent-trueif the output should use indentation,falseotherwise- Returns:
 - The XML writer
 
 
- 
setEncoding
public SimpleXml setEncoding(java.lang.String encoding)
Sets the character encoding of the output. Default isUTF-8.- Parameters:
 encoding- The character encoding- Returns:
 - The XML writer
 
 
- 
omitXmlDeclaration
public SimpleXml omitXmlDeclaration(boolean omit)
Defines whether the XML declaration should be omitted. Default isfalse.- Parameters:
 omit-trueif the XML declaration should be omitted,falseotherwise- Returns:
 - The XML writer
 
 
- 
setDocumentLocator
public SimpleXml setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator of the output.- Parameters:
 locator- The document locator- Returns:
 - The XML writer
 
 
- 
open
public SimpleXml open() throws java.io.IOException
Opens the XML document. This method is a shorthand foropenDocument().- Returns:
 - The XML writer
 - Throws:
 java.io.IOException- If output fails
 
- 
openDocument
public SimpleXml openDocument() throws java.io.IOException
Opens the XML document.- Returns:
 - The XML writer
 - Throws:
 java.io.IOException- If output fails
 
- 
open
public SimpleXml.Element open(java.lang.String name) throws java.io.IOException
Opens and returns a new XML element with the specified name.- Parameters:
 name- The name of the XML element- Returns:
 - The XML element
 - Throws:
 java.io.IOException- If output fails
 
- 
open
public SimpleXml.Element open(java.lang.String localName, java.lang.String name) throws java.io.IOException
Opens and returns a new XML element with the specified name.- Parameters:
 localName- The local name of the XML elementname- The name of the XML element- Returns:
 - The XML element
 - Throws:
 java.io.IOException- If output fails
 
- 
open
public SimpleXml.Element open(java.lang.String uri, java.lang.String localName, java.lang.String name) throws java.io.IOException
Opens and returns a new XML element with the specified name.- Parameters:
 uri- The URI of the XML elementlocalName- The local name of the XML elementname- The name of the XML element- Returns:
 - The XML element
 - Throws:
 java.io.IOException- If output fails
 
- 
open
public SimpleXml.Element open(java.lang.String name, java.lang.String content, boolean cdata) throws java.io.IOException
Opens and returns a new XML element with the specified name and content.- Parameters:
 name- The name of the XML elementcontent- The content of the XML elementcdata-trueif content should be in a CDATA block,falseotherwise- Returns:
 - The XML element
 - Throws:
 java.io.IOException- If output fails
 
- 
closeDocument
public void closeDocument() throws java.io.IOExceptionCloses the XML document after closing all open elements.- Throws:
 java.io.IOException- If output fails
 
- 
close
public SimpleXml close() throws java.io.IOException
Closes the most recent open element.- Returns:
 - The XML writer
 - Throws:
 java.io.IOException- If output fails
 
- 
tidyUp
public SimpleXml tidyUp() throws java.io.IOException
Closes all currently open elements.- Returns:
 - The XML writer
 - Throws:
 java.io.IOException- If output fails
 
 - 
 
 -