org.deckfour.spex
Class SXDocument

java.lang.Object
  extended by org.deckfour.spex.SXNode
      extended by org.deckfour.spex.SXDocument

public class SXDocument
extends SXNode

This class represents an XML document. It is a convenient wrapper for writing XML documents sequentially, while preserving a quasi-object-oriented interface.

Author:
Christian W. Guenther (christian@deckfour.org)
See Also:
SXTag

Field Summary
protected  boolean isOpen
          Whether this document is still open.
protected  SXNode lastChildNode
          Last opened child node of this document.
protected  String tabString
          Tabulator string.
 
Fields inherited from class org.deckfour.spex.SXNode
tabLevel, writer
 
Constructor Summary
SXDocument(File aFile)
          Creates a new document with standard UTF-8 encoding.
SXDocument(OutputStream aStream)
          Creates a new document with standard UTF-8 encoding.
SXDocument(OutputStream aStream, Charset aCharset)
          Creates a new document.
SXDocument(OutputStream aStream, String aCharsetName)
          Creates a new document.
SXDocument(Writer writer, Charset charset)
          Creates a new document.
 
Method Summary
 void addComment(String comment)
          Adds a comment to this document.
 SXTag addNode(String tagName)
          Adds a regular, named node to this document (usually one single root node) WARNING: This will close the last added tag, if applicable!
 void close()
          Closes this document.
 String getTabString()
          Returns this document's tabulator encoding.
protected  void prepareToAddChildNode()
          Internal abstraction method; prepares the document for inserting a new child tag of any type.
 void setTabString(String aTabString)
          Sets this document's tabulator encoding.
 
Methods inherited from class org.deckfour.spex.SXNode
getTabLevel, indentLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tabString

protected String tabString
Tabulator string.


lastChildNode

protected SXNode lastChildNode
Last opened child node of this document.


isOpen

protected boolean isOpen
Whether this document is still open.

Constructor Detail

SXDocument

public SXDocument(Writer writer,
                  Charset charset)
           throws IOException
Creates a new document.

Parameters:
aWriter - writer instance to write document to
aCharset - charset used for encoding in the provided Writer
Throws:
IOException

SXDocument

public SXDocument(OutputStream aStream,
                  Charset aCharset)
           throws IOException
Creates a new document.

Parameters:
aStream - output stream to write document to
aCharset - charset to be used for encoding
Throws:
IOException

SXDocument

public SXDocument(OutputStream aStream,
                  String aCharsetName)
           throws IOException
Creates a new document.

Parameters:
aStream - output stream to write document to
aCharsetName - standard name of the charset to be used for encoding
Throws:
IOException

SXDocument

public SXDocument(OutputStream aStream)
           throws IOException
Creates a new document with standard UTF-8 encoding.

Parameters:
aStream - output stream to write document to
Throws:
IOException

SXDocument

public SXDocument(File aFile)
           throws IOException
Creates a new document with standard UTF-8 encoding.

Parameters:
aFile - file to write the document to
Throws:
IOException
Method Detail

prepareToAddChildNode

protected void prepareToAddChildNode()
                              throws IOException
Internal abstraction method; prepares the document for inserting a new child tag of any type.

Throws:
IOException

addNode

public SXTag addNode(String tagName)
              throws IOException
Adds a regular, named node to this document (usually one single root node) WARNING: This will close the last added tag, if applicable!

Parameters:
tagName - The name of the tag to add (contents between brackets)
Returns:
A Node abstraction.
Throws:
IOException

addComment

public void addComment(String comment)
                throws IOException
Adds a comment to this document. WARNING: This will close the last added tag, if applicable!

Parameters:
comment - The comment line to be added.
Throws:
IOException

close

public void close()
           throws IOException
Closes this document. NOTICE: It is absolutely necessary to call this method in the end, as otherwise the last added child node will not be appropriately finished!

Specified by:
close in class SXNode
Throws:
IOException

setTabString

public void setTabString(String aTabString)
Sets this document's tabulator encoding.

Parameters:
aTabString - Tabulator string to be used.

getTabString

public String getTabString()
Returns this document's tabulator encoding.

Returns:
This document's tabulator encoding.