org.jagatoo.util.xml
Class SimpleXMLWriter

java.lang.Object
  extended by org.jagatoo.util.xml.SimpleXMLWriter

public class SimpleXMLWriter
extends java.lang.Object

Writes XML data.

This class simply wrapps an inverted SAX parser to generate valid XML.

Author:
Marvin Froehlich (aka Qudus)

Constructor Summary
  SimpleXMLWriter(java.io.File file)
          Parses the given file.
  SimpleXMLWriter(java.io.File file, java.nio.charset.Charset charset)
          Parses the given file.
  SimpleXMLWriter(java.io.File file, java.lang.String charset)
          Parses the given file.
  SimpleXMLWriter(java.io.OutputStream out)
          Parses the given file.
  SimpleXMLWriter(java.io.OutputStream out, java.nio.charset.Charset charset)
          Parses the given file.
  SimpleXMLWriter(java.io.OutputStream out, java.lang.String charset)
          Parses the given file.
protected SimpleXMLWriter(java.io.OutputStream out, java.lang.String codepage, java.nio.charset.Charset charset)
           
  SimpleXMLWriter(java.lang.String filename)
          Parses the given file.
  SimpleXMLWriter(java.lang.String filename, java.nio.charset.Charset charset)
          Parses the given file.
  SimpleXMLWriter(java.lang.String filename, java.lang.String charset)
          Parses the given file.
 
Method Summary
 void close()
           
protected  void finalize()
          
 boolean getAddNewLines()
           
 int getLevel()
           
 XMLPath getPath()
           
protected  java.lang.Object getPathObject(int level, java.lang.String element)
          Converts the passed element to a path element.
 boolean getUseTabsForIndentation()
           
protected  void newLine()
           
 void popElement()
          Pops the level hierarchy one level up.
 void setAddNewLines(boolean addNewLines)
           
 void setIndentation(int indent)
           
 void setIndentation(int indent, boolean useTabs)
           
protected  void writeElement(boolean push, java.lang.String name, java.lang.Object[] attributes)
          Writes an XML element to the file.
 void writeElement(java.lang.String name, java.lang.Object... attributes)
          Writes an XML element to the file.
 void writeElementAndPush(java.lang.String name, java.lang.Object... attributes)
          Writes an XML element to the file and pushes one level down, so that succeeding elements become children of this.
protected  void writeElementData(java.lang.String data)
          Writes element data into the last started element.
 void writeElementWithData(java.lang.String name, java.lang.String data, java.lang.Object... attributes)
          Writes an XML element to the file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleXMLWriter

protected SimpleXMLWriter(java.io.OutputStream out,
                          java.lang.String codepage,
                          java.nio.charset.Charset charset)
                   throws java.io.IOException
Parameters:
out -
codepage -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.OutputStream out,
                       java.lang.String charset)
                throws java.io.IOException
Parses the given file.

Parameters:
out -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.OutputStream out,
                       java.nio.charset.Charset charset)
                throws java.io.IOException
Parses the given file.

Parameters:
out -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.OutputStream out)
                throws java.io.IOException
Parses the given file.

Parameters:
out -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.File file,
                       java.lang.String charset)
                throws java.io.IOException
Parses the given file.

Parameters:
file -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.File file,
                       java.nio.charset.Charset charset)
                throws java.io.IOException
Parses the given file.

Parameters:
file -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.io.File file)
                throws java.io.IOException
Parses the given file.

Parameters:
file -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.lang.String filename,
                       java.lang.String charset)
                throws java.io.IOException
Parses the given file.

Parameters:
filename -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.lang.String filename,
                       java.nio.charset.Charset charset)
                throws java.io.IOException
Parses the given file.

Parameters:
filename -
charset -
Throws:
java.io.IOException

SimpleXMLWriter

public SimpleXMLWriter(java.lang.String filename)
                throws java.io.IOException
Parses the given file.

Parameters:
filename -
Throws:
java.io.IOException
Method Detail

setIndentation

public void setIndentation(int indent,
                           boolean useTabs)

setIndentation

public final void setIndentation(int indent)

getUseTabsForIndentation

public final boolean getUseTabsForIndentation()

setAddNewLines

public void setAddNewLines(boolean addNewLines)

getAddNewLines

public final boolean getAddNewLines()

getPath

public final XMLPath getPath()

getLevel

public final int getLevel()

newLine

protected void newLine()
                throws java.io.IOException
Throws:
java.io.IOException

getPathObject

protected java.lang.Object getPathObject(int level,
                                         java.lang.String element)
Converts the passed element to a path element. By default the passed element is returned.

Parameters:
level -
element -
Returns:
the converted path element.

writeElement

protected void writeElement(boolean push,
                            java.lang.String name,
                            java.lang.Object[] attributes)
                     throws java.io.IOException,
                            org.xml.sax.SAXException
Writes an XML element to the file.

Parameters:
push - push element hierarchy one level down?
name - the element's name
attributes - the attributes (attribName1, attribValue1, attribName2, attribValue2, ...)
Throws:
java.io.IOException
org.xml.sax.SAXException

writeElement

public final void writeElement(java.lang.String name,
                               java.lang.Object... attributes)
                        throws java.io.IOException,
                               org.xml.sax.SAXException
Writes an XML element to the file.

Parameters:
name - the element's name
attributes - the attributes (attribName1, attribValue1, attribName2, attribValue2, ...)
Throws:
java.io.IOException
org.xml.sax.SAXException

writeElementWithData

public final void writeElementWithData(java.lang.String name,
                                       java.lang.String data,
                                       java.lang.Object... attributes)
                                throws java.io.IOException,
                                       org.xml.sax.SAXException
Writes an XML element to the file.

Parameters:
name - the element's name
data -
attributes - the attributes (attribName1, attribValue1, attribName2, attribValue2, ...)
Throws:
java.io.IOException
org.xml.sax.SAXException

writeElementAndPush

public final void writeElementAndPush(java.lang.String name,
                                      java.lang.Object... attributes)
                               throws java.io.IOException,
                                      org.xml.sax.SAXException
Writes an XML element to the file and pushes one level down, so that succeeding elements become children of this.

Parameters:
name - the element's name
attributes - the attributes (attribName1, attribValue1, attribName2, attribValue2, ...)
Throws:
java.io.IOException
org.xml.sax.SAXException

writeElementData

protected void writeElementData(java.lang.String data)
                         throws java.io.IOException,
                                org.xml.sax.SAXException
Writes element data into the last started element.

Parameters:
data -
Throws:
java.io.IOException
org.xml.sax.SAXException

popElement

public void popElement()
                throws java.io.IOException,
                       org.xml.sax.SAXException
Pops the level hierarchy one level up.

Throws:
java.io.IOException
org.xml.sax.SAXException

close

public void close()
           throws java.io.IOException,
                  org.xml.sax.SAXException
Throws:
java.io.IOException
org.xml.sax.SAXException

finalize

protected void finalize()
                 throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable