public final class XmlWriter extends java.lang.Object implements IXmlWriter
Lightweight IXmlWriter implementation.
Requires a wrapper to be used safely in a multithreaded environment.
Not intended to be subclassed. Please copy and hack!
| Modifier and Type | Field and Description |
|---|---|
private static boolean[] |
ALLOWED_CHARACTERS |
private static byte[] |
CHARACTER_CODES |
private java.util.Set<java.lang.CharSequence> |
currentAttributes |
private org.apache.commons.collections.ArrayStack |
elementNames |
(package private) boolean |
elementsWritten |
(package private) boolean |
inElement |
private static byte |
NAME_BODY_CHAR |
private static byte |
NAME_MASK |
private static byte |
NAME_START_MASK |
private static byte |
NAME_START_OR_BODY_CHAR |
(package private) boolean |
prologWritten |
private java.io.Writer |
writer |
| Constructor and Description |
|---|
XmlWriter(java.io.Writer writer) |
| Modifier and Type | Method and Description |
|---|---|
IXmlWriter |
attribute(java.lang.CharSequence name,
java.lang.CharSequence value)
Writes an attribute of an element.
|
IXmlWriter |
closeDocument()
Closes all pending elements.
|
IXmlWriter |
closeElement()
Closes the last element written.
|
IXmlWriter |
content(java.lang.CharSequence content)
Writes content.
|
private boolean |
isInvalidName(java.lang.CharSequence sequence) |
private boolean |
isOutOfRange(char character) |
private boolean |
isValidNameBody(char character) |
private boolean |
isValidNameStart(char character) |
IXmlWriter |
openElement(java.lang.CharSequence elementName)
Writes the start of an element.
|
private void |
rawWrite(java.lang.CharSequence sequence) |
IXmlWriter |
startDocument()
Starts a document by writing a prolog.
|
private void |
writeAttributeContent(java.lang.CharSequence content) |
private void |
writeBodyContent(java.lang.CharSequence content) |
private void |
writeEscaped(java.lang.CharSequence content,
boolean isAttributeContent) |
private static final byte NAME_START_MASK
private static final byte NAME_MASK
private static final byte NAME_BODY_CHAR
private static final byte NAME_START_OR_BODY_CHAR
private static final boolean[] ALLOWED_CHARACTERS
private static final byte[] CHARACTER_CODES
private final java.io.Writer writer
private final org.apache.commons.collections.ArrayStack elementNames
private final java.util.Set<java.lang.CharSequence> currentAttributes
boolean elementsWritten
boolean inElement
boolean prologWritten
public IXmlWriter startDocument() throws java.io.IOException
startDocument in interface IXmlWriterOperationNotAllowedException - if called after the first element has been written
or once a prolog has already been writtenjava.io.IOExceptionpublic IXmlWriter openElement(java.lang.CharSequence elementName) throws java.io.IOException
openElement in interface IXmlWriterelementName - the name of the element, not nullInvalidXmlException - if the name is not valid for an xml elementOperationNotAllowedException - if called after the first element has been closedjava.io.IOExceptionpublic IXmlWriter attribute(java.lang.CharSequence name, java.lang.CharSequence value) throws java.io.IOException
openElement(CharSequence)
or attribute(java.lang.CharSequence, java.lang.CharSequence).attribute in interface IXmlWritername - the attribute name, not nullvalue - the attribute value, not nullInvalidXmlException - if the name is not valid for an xml attribute
or if a value for the attribute has already been writtenOperationNotAllowedException - if called after content(CharSequence)
or closeElement() or before any call to openElement(CharSequence)java.io.IOExceptionprivate void writeAttributeContent(java.lang.CharSequence content)
throws java.io.IOException
java.io.IOExceptionpublic IXmlWriter content(java.lang.CharSequence content) throws java.io.IOException
content in interface IXmlWritercontent - the content to writeOperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence)
or after the first element has been closedjava.io.IOExceptionprivate void writeBodyContent(java.lang.CharSequence content)
throws java.io.IOException
java.io.IOExceptionprivate void writeEscaped(java.lang.CharSequence content,
boolean isAttributeContent)
throws java.io.IOException
java.io.IOExceptionprivate boolean isOutOfRange(char character)
public IXmlWriter closeElement() throws java.io.IOException
closeElement in interface IXmlWriterOperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence)
or after the first element has been closedjava.io.IOExceptionpublic IXmlWriter closeDocument() throws java.io.IOException
closeDocument in interface IXmlWriterOperationNotAllowedException - if called before any call to openElement(java.lang.CharSequence)java.io.IOExceptionprivate void rawWrite(java.lang.CharSequence sequence)
throws java.io.IOException
java.io.IOExceptionprivate boolean isInvalidName(java.lang.CharSequence sequence)
private boolean isValidNameStart(char character)
private boolean isValidNameBody(char character)