com.waveset.util
Class XmlBuffer

java.lang.Object
  extended bycom.waveset.util.StringBufferWrapper
      extended bycom.waveset.util.XmlBuffer

public class XmlBuffer
extends StringBufferWrapper

A class that wraps a StringBuffer and provides awareness of XML.


Field Summary
static java.lang.String code_id
           
static char DOUBLE_QUOTE
           
static boolean INDENT
          A global flag the enables or disables indentation.
static char SINGLE_QUOTE
           
 
Fields inherited from class com.waveset.util.StringBufferWrapper
_indentIncrement
 
Constructor Summary
XmlBuffer()
           
XmlBuffer(int length)
           
XmlBuffer(java.lang.String str)
           
 
Method Summary
 void addAttribute(java.lang.String name, boolean value)
          Adds a boolean attribute to the buffer.
 void addAttribute(java.lang.String name, java.util.Date value)
          Adds a date attribute to the buffer.
 void addAttribute(java.lang.String name, int value)
          Adds an integer attribute to the buffer.
 void addAttribute(java.lang.String name, java.lang.Object obj)
          Add an an attribute value using an arbitrary object, by calling its toString method.
 void addAttribute(java.lang.String name, java.lang.String value)
          Adds an attribute name and value to the buffer.
 void addAttribute(java.lang.String name, java.lang.String[] map, int value)
          Adds an integer attribute to the buffer mapping it to a string.
 void addContent(java.lang.String s)
          Adds a string of element content to the buffer.
 void addElement(java.lang.String element, java.lang.String content)
          Adds an element with content to the buffer, being careful to escape content.
 void addEndTag(java.lang.String e)
          Backward compatibilty
 void addHeader(java.lang.String doctypeName)
          Add the default header, need to be able to customize this better.
 void addIndent(int indent)
          Add indentation to the buffer.
 void addObject(java.lang.String wrapper, XmlObject obj)
          Adds an object to the buffer, wrapped in some other elemenet.
 void addOpenStartTag(java.lang.String element)
          Backward compatibility.
 void addStartTag(java.lang.String element, boolean newline)
          backward compatibility
 void closeEmptyTag()
          Close an empty open start tag.
 void closeTag()
          Close an open start tag.
 void decIndent()
           
 void decIndent(int i)
          Decrement the indentation level.
 void endTag(java.lang.String element)
          Adds an element end tag.
 void endTagHanging(java.lang.String element)
          Adds an element end tag, but does not indent.
 java.lang.String getEncoding()
           
 int getIndent()
           
 char getPreferredDelimiter()
           
 void incIndent()
           
 void incIndent(int i)
          Increment the indentation level.
static void main(java.lang.String[] args)
           
 void openStartTag(java.lang.String element)
          Adds an open element start tag.
 void setEncoding(java.lang.String encoding)
           
 void setIndent(int i)
          Set the current indentation level (i.e., the number of spaces to indent).
 void setPreferredDelimiter(char c)
           
 void startTag(java.lang.String element)
          Adds a closed element start tag followed by a newline.
 void startTagHanging(java.lang.String element)
          Adds a closed element start tag with no newline.
 
Methods inherited from class com.waveset.util.StringBufferWrapper
append, append, append, append, charAt, getBuffer, getIndentIncrement, length, setIndentIncrement, setLength, substring, substring, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

SINGLE_QUOTE

public static final char SINGLE_QUOTE
See Also:
Constant Field Values

DOUBLE_QUOTE

public static final char DOUBLE_QUOTE
See Also:
Constant Field Values

INDENT

public static boolean INDENT
A global flag the enables or disables indentation.

Constructor Detail

XmlBuffer

public XmlBuffer()

XmlBuffer

public XmlBuffer(int length)

XmlBuffer

public XmlBuffer(java.lang.String str)
Method Detail

getIndent

public int getIndent()
Returns:
the current indentation level (i.e., the number of spaces to indent).

setIndent

public void setIndent(int i)
Set the current indentation level (i.e., the number of spaces to indent).

Useful when generating XML to match or replace portions of existing XML. Otherwise, call incIndent(int) or decIndent(int).


setEncoding

public void setEncoding(java.lang.String encoding)
                 throws InvalidArgument
Throws:
InvalidArgument

getEncoding

public java.lang.String getEncoding()

getPreferredDelimiter

public char getPreferredDelimiter()

setPreferredDelimiter

public void setPreferredDelimiter(char c)

incIndent

public void incIndent(int i)
Increment the indentation level.


incIndent

public void incIndent()

decIndent

public void decIndent(int i)
Decrement the indentation level.


decIndent

public void decIndent()

addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.String value)
Adds an attribute name and value to the buffer.

Performs any necessary escaping on the value. This should be used when you're building the XML for something, and its possible for an attribute value to have any of the characters &, ', or "


addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.Object obj)
Add an an attribute value using an arbitrary object, by calling its toString method.


addAttribute

public void addAttribute(java.lang.String name,
                         boolean value)
Adds a boolean attribute to the buffer.

If the value is false, the attribute is suppressed.


addAttribute

public void addAttribute(java.lang.String name,
                         int value)
Adds an integer attribute to the buffer.


addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.String[] map,
                         int value)
Adds an integer attribute to the buffer mapping it to a string.


addAttribute

public void addAttribute(java.lang.String name,
                         java.util.Date value)
Adds a date attribute to the buffer.

If the value is null, the attribute is suppressed.


addContent

public void addContent(java.lang.String s)
Adds a string of element content to the buffer.

Replaces special characters in a string with XML character entities. The characters replaced are '&' and '<'. This should be when building strings intended to be the values of XML attributes or XML element content.


addIndent

public void addIndent(int indent)
Add indentation to the buffer.


openStartTag

public void openStartTag(java.lang.String element)
Adds an open element start tag.


addOpenStartTag

public void addOpenStartTag(java.lang.String element)
Backward compatibility.


closeTag

public void closeTag()
Close an open start tag.


closeEmptyTag

public void closeEmptyTag()
Close an empty open start tag.


startTag

public void startTag(java.lang.String element)
Adds a closed element start tag followed by a newline.


startTagHanging

public void startTagHanging(java.lang.String element)
Adds a closed element start tag with no newline.


addStartTag

public void addStartTag(java.lang.String element,
                        boolean newline)
backward compatibility


endTag

public void endTag(java.lang.String element)
Adds an element end tag.


endTagHanging

public void endTagHanging(java.lang.String element)
Adds an element end tag, but does not indent.


addEndTag

public void addEndTag(java.lang.String e)
Backward compatibilty


addElement

public void addElement(java.lang.String element,
                       java.lang.String content)
Adds an element with content to the buffer, being careful to escape content.


addObject

public void addObject(java.lang.String wrapper,
                      XmlObject obj)
Adds an object to the buffer, wrapped in some other elemenet.


addHeader

public void addHeader(java.lang.String doctypeName)
Add the default header, need to be able to customize this better.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception