Package org.apache.rat.report.xml.writer
Class XmlWriter
java.lang.Object
org.apache.rat.report.xml.writer.XmlWriter
- All Implemented Interfaces:
AutoCloseable
,IXmlWriter
Lightweight IXmlWriter
implementation.
Requires a wrapper to be used safely in a multithreaded environment.
Not intended to be subclassed. Please copy and hack!
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattribute
(CharSequence name, CharSequence value) Writes an attribute of an element.cdata
(CharSequence content) Writes CDATA content.void
close()
Closes all pending elements.Closes the last element written.closeElement
(CharSequence name) Closes back to and including the last instance of the specified element name.comment
(CharSequence text) Writes a commentcontent
(CharSequence content) Writes content.openElement
(CharSequence elementName) Writes the start of an element.Starts a document by writing a prolog.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.rat.report.xml.writer.IXmlWriter
openElement
-
Constructor Details
-
XmlWriter
Constructs an XmlWriter with the specified writer for output.- Parameters:
writer
- the writer to write to.
-
-
Method Details
-
startDocument
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 writtenIOException
-
openElement
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 closedIOException
-
comment
Description copied from interface:IXmlWriter
Writes a comment- Specified by:
comment
in interfaceIXmlWriter
- Parameters:
text
- the comment text- Returns:
- this object
- Throws:
IOException
-
attribute
Writes an attribute of an element. Note that this is only allowed directly afteropenElement(CharSequence)
or a previousattribute
call.- 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)
IOException
-
content
Description copied from interface:IXmlWriter
Writes content. Note that this method does not support CDATA. This method automatically escapes characters.- Specified by:
content
in interfaceIXmlWriter
- Parameters:
content
- the content to write- Returns:
- this object
- Throws:
IOException
-
cdata
Description copied from interface:IXmlWriter
Writes CDATA content. This method DOES NOT automatically escape characters. It will remove enclosed CDATA closing strings (e.g.]]>
)- Specified by:
cdata
in interfaceIXmlWriter
- Parameters:
content
- the content to write- Returns:
- this object
- Throws:
IOException
-
closeElement
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 closedIOException
-
closeElement
Closes back to and including the last instance of the specified element name.- Specified by:
closeElement
in interfaceIXmlWriter
- Parameters:
name
- The name of the element to close. Must not benull
.- Returns:
- this object
- Throws:
OperationNotAllowedException
- if called before any call toopenElement(java.lang.CharSequence)
or after the first element has been closedIOException
-
closeDocument
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)
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-