to.etc.xml
Class XmlWriter

java.lang.Object
  extended by java.io.Writer
      extended by to.etc.util.IndentWriter
          extended by to.etc.xml.XmlWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class XmlWriter
extends IndentWriter

Small utility class to write formatted XML documents. This class writes it's data to a printstream. The stream is never closed. The data is formatted and nested appropriately by indenting tags. XML cdata is properly escaped (replacing < by &lt; and the like.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XmlWriter()
           
XmlWriter(java.io.Writer w)
           
 
Method Summary
 void attr(java.lang.String name, java.lang.String value)
           
 void cdata(java.lang.String s)
          Writes string data.
 void close()
          XMLWriters cannot be closed: ignore.
 void dumpBean(java.lang.Object o)
           
 void init(java.io.Writer w, int taglvl)
           
 void tag(java.lang.String tn)
           
 void tag(java.lang.String tn, java.lang.String... attrvalueset)
           
 void tag(java.lang.String tn, java.lang.String attrs)
          Writes a new XML tag.
 void tagendnl()
           
 void tagfull(java.lang.String tn)
          Writes a complete tag (open AND close) without attributes.
 void tagfull(java.lang.String tn, boolean onoff)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, java.lang.Boolean onoff)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, java.util.Date dt)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, int val)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, long val)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, java.lang.Number val)
           
 void tagfull(java.lang.String tn, java.lang.String text)
          Writes a tag, a #text content and the end tag on one line.
 void tagfull(java.lang.String tn, java.lang.String attrs, java.lang.String text)
          Writes a tag with the given attributes, a #text content and the end tag on one line.
 void tagnl(java.lang.String tn, java.lang.String... attrvalueset)
           
 void tagonly(java.lang.String tn, java.lang.String... attrvalueset)
          Outputs a tag AND parameters ONLY, i.e.
 void tagonlynl(java.lang.String tn, java.lang.String... attrvalueset)
           
 void unclosed()
           
 void wraw(java.lang.String s)
          Writes data without replacing stuff; it does expand newlines to indent.
 void writeAttr(java.lang.String name, java.lang.String value)
           
 
Methods inherited from class to.etc.util.IndentWriter
dec, flush, forceNewline, getStdoutWriter, getWriter, inc, indent, isIndentEnabled, print, println, println, setInd, setIndentEnabled, setSpacesPerIndent, write, write, writeRaw, writeRaw, writeRaw
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlWriter

public XmlWriter()

XmlWriter

public XmlWriter(java.io.Writer w)
Method Detail

init

public void init(java.io.Writer w,
                 int taglvl)
Overrides:
init in class IndentWriter

wraw

public void wraw(java.lang.String s)
          throws java.io.IOException
Writes data without replacing stuff; it does expand newlines to indent.

Parameters:
s -
Throws:
java.io.IOException

writeAttr

public void writeAttr(java.lang.String name,
                      java.lang.String value)
               throws java.io.IOException
Throws:
java.io.IOException

cdata

public void cdata(java.lang.String s)
           throws java.io.IOException
Writes string data. This escapes XML control characters to their entity equivalent. This does NOT indent data with newlines, because string data in a content block may not change.

Throws:
java.io.IOException

unclosed

public void unclosed()

tag

public void tag(java.lang.String tn,
                java.lang.String attrs)
         throws java.io.IOException
Writes a new XML tag. The attrs field must at least contain a '>' to close the tag. If you want the tag to be the only one on the line then add a linefeed to the attrs field also.

Parameters:
tn - The tag name without braces
attrs - attributes.
Throws:
java.io.IOException

tagnl

public void tagnl(java.lang.String tn,
                  java.lang.String... attrvalueset)
           throws java.io.IOException
Throws:
java.io.IOException

tag

public void tag(java.lang.String tn,
                java.lang.String... attrvalueset)
         throws java.io.IOException
Throws:
java.io.IOException

attr

public void attr(java.lang.String name,
                 java.lang.String value)
          throws java.io.IOException
Throws:
java.io.IOException

tagonly

public void tagonly(java.lang.String tn,
                    java.lang.String... attrvalueset)
             throws java.io.IOException
Outputs a tag AND parameters ONLY, i.e. it outputs the tag and completes it by adding />.

Parameters:
tn -
attrvalueset -
Throws:
java.io.IOException

tagonlynl

public void tagonlynl(java.lang.String tn,
                      java.lang.String... attrvalueset)
               throws java.io.IOException
Throws:
java.io.IOException

tag

public void tag(java.lang.String tn)
         throws java.io.IOException
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn)
             throws java.io.IOException
Writes a complete tag (open AND close) without attributes.

Parameters:
tag -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    java.lang.String text)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    java.util.Date dt)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    java.lang.String attrs,
                    java.lang.String text)
             throws java.io.IOException
Writes a tag with the given attributes, a #text content and the end tag on one line.

Parameters:
tag -
attrs -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    int val)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    long val)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    java.lang.Number val)
             throws java.io.IOException
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    boolean onoff)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagfull

public void tagfull(java.lang.String tn,
                    java.lang.Boolean onoff)
             throws java.io.IOException
Writes a tag, a #text content and the end tag on one line.

Parameters:
tag -
text -
Throws:
java.io.IOException

tagendnl

public void tagendnl()
              throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
XMLWriters cannot be closed: ignore.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class IndentWriter
Throws:
java.io.IOException
See Also:
Closeable.close()

dumpBean

public void dumpBean(java.lang.Object o)
              throws java.io.IOException
Throws:
java.io.IOException