com.lightdev.lib.xml.io
Class XmlWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.BufferedWriter
          extended by com.lightdev.lib.xml.io.XmlWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
XmlDocumentWriter, XmlTreeWriter

public class XmlWriter
extends BufferedWriter

Basic XML writer to subclass from

This class provides basic methods for writing XML tags and attributes. It is meant for subclassing from in the way that a subclass transfroms content to XmlTag objects which it passes to its superclass (this class) for writing.

Version:
1, March 5, 2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software
See Also:
XmlTag

Field Summary
static char ATTR_NAME_START
          character to indicate the start of an attribute
static char ATTR_SEPARATOR
          character to separate an attribute name from an attribute value
static char ATTR_VALUE_BORDER
          character to indicate the start or end of an attribute value
static char END_TAG_INDICATOR
          character to indicate an end tag
static char INDENT_CHAR
          the character to use to indent
static int INDENT_INCREMENT
          indent increment per level
static char TAG_END
          character to indicate a tag end
static char TAG_START
          character to indicate a tag start
static char XML_TAG_INDICATOR
           
 
Constructor Summary
XmlWriter(Writer out, boolean maskSpecialChars)
          construct an XmlWriter
 
Method Summary
 void indent(int len)
          write indent characters for the given number of character positions
 void writeEndTag(XmlTag tag)
          write an end tag
 void writeStartTag(XmlTag tag, boolean asEndTag)
          write a start tag for given XML tag
 void writeTag(XmlTag tag)
          write a given XmlTag
 boolean writeTag(XmlTag tag, boolean hasChildren)
          write a given XmlTag
 
Methods inherited from class java.io.BufferedWriter
close, flush, newLine, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDENT_INCREMENT

public static final int INDENT_INCREMENT
indent increment per level

See Also:
Constant Field Values

INDENT_CHAR

public static final char INDENT_CHAR
the character to use to indent

See Also:
Constant Field Values

TAG_START

public static final char TAG_START
character to indicate a tag start

See Also:
Constant Field Values

TAG_END

public static final char TAG_END
character to indicate a tag end

See Also:
Constant Field Values

END_TAG_INDICATOR

public static final char END_TAG_INDICATOR
character to indicate an end tag

See Also:
Constant Field Values

ATTR_NAME_START

public static final char ATTR_NAME_START
character to indicate the start of an attribute

See Also:
Constant Field Values

ATTR_SEPARATOR

public static final char ATTR_SEPARATOR
character to separate an attribute name from an attribute value

See Also:
Constant Field Values

ATTR_VALUE_BORDER

public static final char ATTR_VALUE_BORDER
character to indicate the start or end of an attribute value

See Also:
Constant Field Values

XML_TAG_INDICATOR

public static final char XML_TAG_INDICATOR
See Also:
Constant Field Values
Constructor Detail

XmlWriter

public XmlWriter(Writer out,
                 boolean maskSpecialChars)
construct an XmlWriter

Parameters:
out - Writer the writer to write to
Method Detail

writeTag

public boolean writeTag(XmlTag tag,
                        boolean hasChildren)
                 throws IOException
write a given XmlTag

Parameters:
tag - XmlTag the tag to write
hasChildren - boolean true, if the tag has children
Returns:
true if an end tag is to be written by the calling method
Throws:
IOException

writeTag

public void writeTag(XmlTag tag)
              throws IOException
write a given XmlTag

Parameters:
tag - XmlTag the tag to write
Throws:
IOException

writeStartTag

public void writeStartTag(XmlTag tag,
                          boolean asEndTag)
                   throws IOException
write a start tag for given XML tag

Parameters:
tag - XmlTag the XML tag to write a start tag for
asEndTag - true, if the start tag is end tag too (all in one tag)
Throws:
IOException - if something goes wrong during a write activity

writeEndTag

public void writeEndTag(XmlTag tag)
                 throws IOException
write an end tag

Parameters:
tag - XmlTag the tag to write an end tag for
onNewLine - boolean true, if the end tag is to be written on a new line
Throws:
IOException - if something went wrong during write

indent

public void indent(int len)
            throws IOException
write indent characters for the given number of character positions

Parameters:
len - int the number of character positions to indent
Throws:
IOException