Package com.day.cq.commons
Class SimpleXml
- java.lang.Object
-
- com.day.cq.commons.SimpleXml
-
public class SimpleXml extends java.lang.Object
TheSimpleXml
class facilitates the creation of an XML document.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SimpleXml.Element
TheSimpleXml.Element
reperesents an XML element.
-
Constructor Summary
Constructors Constructor Description SimpleXml(java.io.PrintWriter w)
Creates aSimpleXml
instance 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 SimpleXml
close()
Closes the most recent open element.void
closeDocument()
Closes the XML document after closing all open elements.java.io.PrintWriter
getWriter()
Returns the print writer used for the output of the XML document.SimpleXml
omitXmlDeclaration(boolean omit)
Defines whether the XML declaration should be omitted.SimpleXml
open()
Opens the XML document.SimpleXml.Element
open(java.lang.String name)
Opens and returns a new XML element with the specified name.SimpleXml.Element
open(java.lang.String localName, java.lang.String name)
Opens and returns a new XML element with the specified name.SimpleXml.Element
open(java.lang.String name, java.lang.String content, boolean cdata)
Opens and returns a new XML element with the specified name and content.SimpleXml.Element
open(java.lang.String uri, java.lang.String localName, java.lang.String name)
Opens and returns a new XML element with the specified name.SimpleXml
openDocument()
Opens the XML document.SimpleXml
setDocumentLocator(org.xml.sax.Locator locator)
Sets the document locator of the output.SimpleXml
setEncoding(java.lang.String encoding)
Sets the character encoding of the output.SimpleXml
setIndent(boolean indent)
Defines whether the output should use indetation.SimpleXml
tidyUp()
Closes all currently open elements.
-
-
-
Constructor Detail
-
SimpleXml
public SimpleXml(java.io.PrintWriter w) throws java.io.IOException
Creates aSimpleXml
instance 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
-true
if the output should use indentation,false
otherwise- 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
-true
if the XML declaration should be omitted,false
otherwise- 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
-true
if content should be in a CDATA block,false
otherwise- Returns:
- The XML element
- Throws:
java.io.IOException
- If output fails
-
closeDocument
public void closeDocument() throws java.io.IOException
Closes 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
-
-