|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.io.Writer
com.myjavatools.xml.XmlWriter
public class XmlWriter
| Field Summary | |
|---|---|
protected java.util.Stack<java.lang.CharSequence> |
Elements
|
static java.lang.String |
escapedChars
escapeChars - characters that ought to be escaped in output Xml file |
protected boolean |
isEmpty
|
static java.lang.String |
okChars
okChars - characters that are okay to be kept intact in output Xml file |
protected java.lang.String |
prefix
|
protected java.io.Writer |
writer
|
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
XmlWriter(java.io.OutputStream out)
Creates an XmlWriter from an OutputStream, using default UTF8 encoding. |
|
XmlWriter(java.io.OutputStream out,
java.lang.String encoding)
Creates an XmlWriter from an OutputStream, using apwxidiws encoding. |
|
XmlWriter(java.io.OutputStreamWriter out)
Creates an XmlWriter from an OutputStreamWriter, using its encoding. |
|
XmlWriter(java.io.Writer out)
Creates an XmlWriter from a Writer, using default UTF8 encoding. |
|
XmlWriter(java.io.Writer out,
java.lang.String encoding)
Creates an XmlWriter from a Writer, using specified encoding. |
|
| Method Summary | |
|---|---|
java.lang.String |
attributeToString(java.lang.CharSequence name,
java.lang.CharSequence value)
Converts a name-value pair to a string of form name="value". |
int |
attrSize(java.util.Map attrs)
Return the number of attrubutes in the attribute list which can be a string. |
void |
close()
Closes the output of Xml, dumping end tags of all elements stored in the stack. |
void |
closeElement()
Closes an element in output. |
protected void |
eol()
|
void |
flush()
Flushes the output. |
java.lang.String |
getAttribute(java.lang.Object attrs,
java.lang.String name)
Gets a value of an attribute from an attribute list hat can be a map or a name-value pair string array. |
protected static boolean |
isAlmostEmpty(java.lang.CharSequence string)
|
protected static boolean |
isEmpty(java.lang.CharSequence cs)
|
protected static boolean |
needsEscape(char c)
|
void |
openElement(java.lang.String type,
java.util.Map<java.lang.String,java.lang.String> attrs)
Starts outputting an element of Xml. |
static java.lang.String |
sgmlEntity(char c)
Encodes a character by SGML rules It can be a hex representation |
static java.lang.String |
toSgmlEncoding(char c)
Converts a character to its SGML numeric encoding |
void |
write(char[] cc,
int off,
int len)
Writes characters to output stream. |
static void |
write(java.io.File f,
java.lang.Object o)
Write the contents of object as an Xml file |
void |
write(java.lang.Object o)
Writes an object as Xml content to the output. |
static void |
write(java.io.OutputStream out,
java.lang.Object o)
Writes an object as Xml content to the output. |
void |
write(java.lang.String s)
Writes a string to output. |
static void |
write(java.lang.String filename,
java.lang.Object o)
Write the contents of object as an Xml file. |
void |
writeAttribute(java.lang.CharSequence name,
java.lang.CharSequence value)
Writes an attribute name-value pair to the output. |
void |
writeAttributes(java.util.Map<java.lang.String,java.lang.String> attrs)
Write attributes, name-value pairs, to the output. |
void |
writeElement(java.lang.CharSequence type,
java.lang.String value)
Writes an element that does not have any attributes or kids. |
void |
writeElement(java.lang.String type,
java.lang.String value,
java.util.Map<java.lang.String,java.lang.String> attrs)
Writes an element that does not have any kids. |
protected void |
writeXmlData(XmlData data)
|
static java.lang.CharSequence |
xmlEscape(java.lang.CharSequence s)
Converts a string to the form that is acceptable inside Xml files, escaping special characters. |
| 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 |
| Field Detail |
|---|
protected final java.io.Writer writer
protected java.lang.String prefix
protected java.util.Stack<java.lang.CharSequence> Elements
protected boolean isEmpty
public static final java.lang.String escapedChars
public static final java.lang.String okChars
| Constructor Detail |
|---|
public XmlWriter(java.io.Writer out,
java.lang.String encoding)
throws java.io.IOException
out - the original writerencoding - encoding to use
java.io.IOException
public XmlWriter(java.io.Writer out)
throws java.io.IOException
out - the original Writer
java.io.IOException
public XmlWriter(java.io.OutputStreamWriter out)
throws java.io.IOException
out - the original OutputStreamWriter
java.io.IOException
public XmlWriter(java.io.OutputStream out,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException,
java.io.IOException
out - the OutputStream to useencoding - encoding to use
java.io.IOException
java.io.UnsupportedEncodingException
public XmlWriter(java.io.OutputStream out)
throws java.io.UnsupportedEncodingException,
java.io.IOException
out - the OutputStream to use
java.io.IOException
java.io.UnsupportedEncodingException| Method Detail |
|---|
protected static boolean needsEscape(char c)
public static java.lang.CharSequence xmlEscape(java.lang.CharSequence s)
s - the string to convert
public void write(char[] cc,
int off,
int len)
throws java.io.IOException
write in class java.io.Writercc - char array to outputoff - offset inside the arrraylen - number of characters to write
java.io.IOException
public void write(java.lang.String s)
throws java.io.IOException
write in class java.io.Writers - the strign to write
java.io.IOException - if something went wrong
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - if something went wrong
protected void eol()
throws java.io.IOException
java.io.IOException
public void writeAttribute(java.lang.CharSequence name,
java.lang.CharSequence value)
throws java.io.IOException
name - attribute namevalue - attribute value
java.io.IOException - if something went wrong
public java.lang.String attributeToString(java.lang.CharSequence name,
java.lang.CharSequence value)
name - the name of the attributevalue - the value of the attribute
public void writeAttributes(java.util.Map<java.lang.String,java.lang.String> attrs)
throws java.io.IOException
attrs - maps attribute names to values
java.io.IOException - if somethings went wrongpublic int attrSize(java.util.Map attrs)
attrs - a map of attributes
public java.lang.String getAttribute(java.lang.Object attrs,
java.lang.String name)
attrs - attribute listname - the name of the attribute
public void openElement(java.lang.String type,
java.util.Map<java.lang.String,java.lang.String> attrs)
throws java.io.IOException
as a result of this, "<"type followed by attributes followed by ">" is sent to the output
type - element typeattrs - attributes (can be a string array or a map)
java.io.IOException
public void closeElement()
throws java.io.IOException
java.io.IOException
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.Writerjava.io.IOException
public void writeElement(java.lang.CharSequence type,
java.lang.String value)
throws java.io.IOException
type - element typevalue - element value
java.io.IOException
public void writeElement(java.lang.String type,
java.lang.String value,
java.util.Map<java.lang.String,java.lang.String> attrs)
throws java.io.IOException
type - element typevalue - element valueattrs - element attributes
java.io.IOException
protected void writeXmlData(XmlData data)
throws java.io.IOException
java.io.IOException
public void write(java.lang.Object o)
throws java.io.IOException
o - the data to be sent to output. If it is not XmlData, it is stringified first.
java.io.IOException
public static void write(java.io.OutputStream out,
java.lang.Object o)
throws java.io.IOException
out - the stream to output the data too - the data to output
java.io.IOException
public static void write(java.io.File f,
java.lang.Object o)
throws java.io.IOException
f - the file to write too - the object to write
java.io.IOException
public static void write(java.lang.String filename,
java.lang.Object o)
throws java.io.IOException
filename - the name of the file to write too - the object to write
java.io.IOExceptionprotected static final boolean isEmpty(java.lang.CharSequence cs)
protected static final boolean isAlmostEmpty(java.lang.CharSequence string)
public static java.lang.String toSgmlEncoding(char c)
c - the character
toSgmlEncoding('\n')
returns " ".public static java.lang.String sgmlEntity(char c)
c - the character
sgmlEntity('\60ab') returns "悫" (that is, Numeric Character Reference);sgmlEntity('<') returns "<" (that is, Predefined Entity);sgmlEntity('&') returns "<" (that is, Predefined Entity);sgmlEntity('X') returns null";sgmlEntity('\n') returns null".
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||