Class XmlWriter
- java.lang.Object
-
- org.apache.rat.report.xml.writer.impl.base.XmlWriter
-
- All Implemented Interfaces:
IXmlWriter
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!
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description XmlWriter(java.io.Writer writer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Field Detail
-
NAME_START_MASK
private static final byte NAME_START_MASK
- See Also:
- Constant Field Values
-
NAME_MASK
private static final byte NAME_MASK
- See Also:
- Constant Field Values
-
NAME_BODY_CHAR
private static final byte NAME_BODY_CHAR
- See Also:
- Constant Field Values
-
NAME_START_OR_BODY_CHAR
private static final byte NAME_START_OR_BODY_CHAR
- See Also:
- Constant Field Values
-
ALLOWED_CHARACTERS
private static final boolean[] ALLOWED_CHARACTERS
-
CHARACTER_CODES
private static final byte[] CHARACTER_CODES
-
writer
private final java.io.Writer writer
-
elementNames
private final org.apache.commons.collections.ArrayStack elementNames
-
currentAttributes
private final java.util.Set<java.lang.CharSequence> currentAttributes
-
elementsWritten
boolean elementsWritten
-
inElement
boolean inElement
-
prologWritten
boolean prologWritten
-
-
Method Detail
-
startDocument
public IXmlWriter startDocument() throws java.io.IOException
Starts a document by writing a prolog. Calling this method is optional. When writing a document fragment, it should not be called.- Specified by:
startDocument
in interfaceIXmlWriter
- Returns:
- this object
- Throws:
OperationNotAllowedException
- if called after the first element has been written or once a prolog has already been writtenOperationNotAllowedException
- if called after the first element has been written or once a prolog has already been writtenjava.io.IOException
-
openElement
public IXmlWriter openElement(java.lang.CharSequence elementName) throws java.io.IOException
Writes the start of an element.- Specified by:
openElement
in interfaceIXmlWriter
- Parameters:
elementName
- the name of the element, not null- Returns:
- this object
- Throws:
InvalidXmlException
- if the name is not valid for an xml elementOperationNotAllowedException
- if called after the first element has been closedInvalidXmlException
- if the name is not valid for an xml elementOperationNotAllowedException
- if called after the first element has been closedjava.io.IOException
-
attribute
public IXmlWriter attribute(java.lang.CharSequence name, java.lang.CharSequence value) throws java.io.IOException
Writes an attribute of an element. Note that this is only allowed directly afteropenElement(CharSequence)
orattribute(java.lang.CharSequence, java.lang.CharSequence)
.- Specified by:
attribute
in interfaceIXmlWriter
- Parameters:
name
- the attribute name, not nullvalue
- the attribute value, not null- Returns:
- this object
- Throws:
InvalidXmlException
- if the name is not valid for an xml attribute or if a value for the attribute has already been writtenOperationNotAllowedException
- if called aftercontent(CharSequence)
orcloseElement()
or before any call toopenElement(CharSequence)
InvalidXmlException
- 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.IOException
-
writeAttributeContent
private void writeAttributeContent(java.lang.CharSequence content) throws java.io.IOException
- Throws:
java.io.IOException
-
content
public IXmlWriter content(java.lang.CharSequence content) throws java.io.IOException
Writes content. Calling this method will automatically Note that this method does not use CDATA.- Specified by:
content
in interfaceIXmlWriter
- Parameters:
content
- the content to write- Returns:
- this object
- Throws:
OperationNotAllowedException
- if called before any call toopenElement(java.lang.CharSequence)
or after the first element has been closedOperationNotAllowedException
- if called before any call to#openElement
or after the first element has been closedjava.io.IOException
-
writeBodyContent
private void writeBodyContent(java.lang.CharSequence content) throws java.io.IOException
- Throws:
java.io.IOException
-
writeEscaped
private void writeEscaped(java.lang.CharSequence content, boolean isAttributeContent) throws java.io.IOException
- Throws:
java.io.IOException
-
isOutOfRange
private boolean isOutOfRange(char character)
-
closeElement
public IXmlWriter closeElement() throws java.io.IOException
Closes the last element written.- Specified by:
closeElement
in interfaceIXmlWriter
- Returns:
- this object
- Throws:
OperationNotAllowedException
- if called before any call toopenElement(java.lang.CharSequence)
or after the first element has been closedOperationNotAllowedException
- if called before any call to#openElement
or after the first element has been closedjava.io.IOException
-
closeDocument
public IXmlWriter closeDocument() throws java.io.IOException
Closes all pending elements. When appropriate, resources are also flushed and closed. No exception is raised when called upon a document whose root element has already been closed.- Specified by:
closeDocument
in interfaceIXmlWriter
- Returns:
- this object
- Throws:
OperationNotAllowedException
- if called before any call toopenElement(java.lang.CharSequence)
OperationNotAllowedException
- if called before any call to#openElement
java.io.IOException
-
rawWrite
private void rawWrite(java.lang.CharSequence sequence) throws java.io.IOException
- Throws:
java.io.IOException
-
isInvalidName
private boolean isInvalidName(java.lang.CharSequence sequence)
-
isValidNameStart
private boolean isValidNameStart(char character)
-
isValidNameBody
private boolean isValidNameBody(char character)
-
-