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
IXmlWriterimplementation.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_CHARACTERSprivate static byte[]CHARACTER_CODESprivate java.util.Set<java.lang.CharSequence>currentAttributesprivate java.util.ArrayDequeelementNames(package private) booleanelementsWritten(package private) booleaninElementprivate static byteNAME_BODY_CHARprivate static byteNAME_MASKprivate static byteNAME_START_MASKprivate static byteNAME_START_OR_BODY_CHAR(package private) booleanprologWrittenprivate java.io.Writerwriter
-
Constructor Summary
Constructors Constructor Description XmlWriter(java.io.Writer writer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IXmlWriterattribute(java.lang.CharSequence name, java.lang.CharSequence value)Writes an attribute of an element.IXmlWritercloseDocument()Closes all pending elements.IXmlWritercloseElement()Closes the last element written.IXmlWritercontent(java.lang.CharSequence content)Writes content.private booleanisInvalidName(java.lang.CharSequence sequence)private booleanisOutOfRange(char character)private booleanisValidNameBody(char character)private booleanisValidNameStart(char character)IXmlWriteropenElement(java.lang.CharSequence elementName)Writes the start of an element.private voidrawWrite(java.lang.CharSequence sequence)IXmlWriterstartDocument()Starts a document by writing a prolog.private voidwriteAttributeContent(java.lang.CharSequence content)private voidwriteBodyContent(java.lang.CharSequence content)private voidwriteEscaped(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 java.util.ArrayDeque 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:
startDocumentin 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:
openElementin 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:
attributein 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:
contentin 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#openElementor 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:
closeElementin 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#openElementor 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:
closeDocumentin interfaceIXmlWriter- Returns:
- this object
- Throws:
OperationNotAllowedException- if called before any call toopenElement(java.lang.CharSequence)OperationNotAllowedException- if called before any call to#openElementjava.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)
-
-