|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object prefuse.util.io.XMLWriter
public class XMLWriter
Utility class for writing XML files. This class provides convenience methods for creating XML documents, such as starting and ending tags, and adding content and comments. This class handles correct XML formatting and will properly escape text to ensure that the text remains valid XML.
To use this class, create a new instance with the desired
PrintWriter to write the XML to. Call the begin()
or
begin(String, int)
method when ready to start outputting
XML. Then use the provided methods to generate the XML file.
Finally, call either the finish()
or finish(String)
methods to signal the completion of the file.
Constructor Summary | |
---|---|
XMLWriter(java.io.PrintWriter out)
Create a new XMLWriter. |
|
XMLWriter(java.io.PrintWriter out,
int tabLength)
Create a new XMLWriter. |
Method Summary | |
---|---|
void |
begin()
Begin the XML document. |
void |
begin(java.lang.String header,
int bias)
Begin the XML document. |
void |
comment(java.lang.String comment)
Print a comment in the XML document. |
void |
content(java.lang.String content)
Print content text. |
void |
contentTag(java.lang.String tag,
java.lang.String content)
Print a new content tag with no attributes, consisting of an open tag, content text, and a closing tag, all on one line. |
void |
contentTag(java.lang.String tag,
java.lang.String name,
java.lang.String value,
java.lang.String content)
Print a new content tag with a single attribute, consisting of an open tag, content text, and a closing tag, all on one line. |
void |
end()
Close the most recently opened tag. |
protected void |
escapeString(java.lang.String str)
Escape a string such that it is safe to use in an XML document. |
void |
finish()
Finish the XML document. |
void |
finish(java.lang.String footer)
Finish the XML document, printing the given footer text at the end of the document. |
void |
print(java.lang.String s)
Print unescaped text into the XML file. |
void |
println()
Print a newline into the XML file. |
void |
println(java.lang.String s)
Print unescaped text into the XML file, followed by a newline. |
void |
spacing()
Print the current spacing (determined by the indentation level) into the document. |
void |
start(java.lang.String tag)
Print a start tag without attributes. |
void |
start(java.lang.String tag,
java.util.ArrayList names,
java.util.ArrayList values,
int nattr)
Print a start tag with attributes. |
void |
start(java.lang.String tag,
java.lang.String[] names,
java.lang.String[] values,
int nattr)
Print a start tag with attributes. |
void |
start(java.lang.String tag,
java.lang.String name,
java.lang.String value)
Print a start tag with one attribute. |
void |
tag(java.lang.String tag,
java.util.ArrayList names,
java.util.ArrayList values,
int nattr)
Print a closed tag with attributes. |
protected void |
tag(java.lang.String tag,
java.util.ArrayList names,
java.util.ArrayList values,
int nattr,
boolean close)
Internal method for printing a tag with attributes. |
void |
tag(java.lang.String tag,
java.lang.String[] names,
java.lang.String[] values,
int nattr)
Print a closed tag with attributes. |
protected void |
tag(java.lang.String tag,
java.lang.String[] names,
java.lang.String[] values,
int nattr,
boolean close)
Internal method for printing a tag with attributes. |
void |
tag(java.lang.String tag,
java.lang.String name,
java.lang.String value)
Print a closed tag with one attribute. |
protected void |
tag(java.lang.String tag,
java.lang.String name,
java.lang.String value,
boolean close)
Internal method for printing a tag with a single attribute. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLWriter(java.io.PrintWriter out)
out
- the print writer to write the XML topublic XMLWriter(java.io.PrintWriter out, int tabLength)
out
- the print writer to write the XML totabLength
- the number of spaces to use for each
level of indentation in the XML fileMethod Detail |
---|
public void print(java.lang.String s)
content(String)
method instead.
s
- the text to print. This String will not be escaped.public void println(java.lang.String s)
content(String)
method instead.
s
- the text to print. This String will not be escaped.public void println()
public void begin()
public void begin(java.lang.String header, int bias)
header
- header text to insert into the documentbias
- the spacing bias to use for all subsequent indentingpublic void comment(java.lang.String comment)
comment
- the comment textprotected void tag(java.lang.String tag, java.lang.String[] names, java.lang.String[] values, int nattr, boolean close)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributesclose
- true to close the tag, false to leave it
open and adjust the spacingpublic void tag(java.lang.String tag, java.lang.String[] names, java.lang.String[] values, int nattr)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributespublic void start(java.lang.String tag, java.lang.String[] names, java.lang.String[] values, int nattr)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributesprotected void tag(java.lang.String tag, java.lang.String name, java.lang.String value, boolean close)
tag
- the tag namename
- the name of the attributevalue
- the value of the attributeclose
- true to close the tag, false to leave it
open and adjust the spacingpublic void tag(java.lang.String tag, java.lang.String name, java.lang.String value)
tag
- the tag namename
- the name of the attributevalue
- the value of the attributepublic void start(java.lang.String tag, java.lang.String name, java.lang.String value)
tag
- the tag namename
- the name of the attributevalue
- the value of the attributeprotected void tag(java.lang.String tag, java.util.ArrayList names, java.util.ArrayList values, int nattr, boolean close)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributesclose
- true to close the tag, false to leave it
open and adjust the spacingpublic void tag(java.lang.String tag, java.util.ArrayList names, java.util.ArrayList values, int nattr)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributespublic void start(java.lang.String tag, java.util.ArrayList names, java.util.ArrayList values, int nattr)
tag
- the tag namenames
- the names of the attributesvalues
- the values of the attributesnattr
- the number of attributespublic void start(java.lang.String tag)
tag
- the tag namepublic void end()
public void contentTag(java.lang.String tag, java.lang.String name, java.lang.String value, java.lang.String content)
tag
- the tag namename
- the name of the attributevalue
- the value of the attribute, this text will be escapedcontent
- the text content, this text will be escapedpublic void contentTag(java.lang.String tag, java.lang.String content)
tag
- the tag namecontent
- the text content, this text will be escapedpublic void content(java.lang.String content)
content
- the content text, this text will be escapedpublic void finish()
public void finish(java.lang.String footer)
footer
- the footer text, this will not be escapedpublic void spacing()
protected void escapeString(java.lang.String str)
str
- the string to escape
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |