|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.tum.cs.commons.xml.XMLWriter<E,A>
public class XMLWriter<E extends java.lang.Enum<E>,A extends java.lang.Enum<A>>
Utility class for creating XML documents. Please consult test case
XMLWriterTest
to see how this class is intended to be used.
Field Summary | |
---|---|
protected IXMLResolver<E,A> |
xmlResolver
Resolver used by the writer. |
Constructor Summary | |
---|---|
XMLWriter(java.io.OutputStream stream,
IXMLResolver<E,A> xmlResolver)
Create a new writer. |
|
XMLWriter(java.io.PrintWriter writer,
IXMLResolver<E,A> xmlResolver)
Create a new writer. |
Method Summary | |
---|---|
void |
addAttribute(A attribute,
java.lang.Object value)
Add a attribute. |
void |
addCDataSection(java.lang.String cdata)
Add CDATA section. |
void |
addClosedElement(E element,
java.lang.Object... attributes)
Convenience method for adding an element together with (some of) its attributes. |
void |
addClosedTextElement(E element,
java.lang.String text,
java.lang.Object... attributes)
Convenience method for adding an element together with (some of) its attributes and text inbetween. |
void |
addComment(java.lang.String text)
Add an XML comment. |
void |
addHeader(java.lang.String version,
java.lang.String encoding)
Add an XML header. |
void |
addNewLine()
Add new line. |
void |
addPublicDocTypeDefintion(E rootElement,
java.lang.String publicId,
java.lang.String systemId)
Add public document type definiton |
protected void |
addRawString(java.lang.String text)
Adds the given text unprocessed to the writer. |
void |
addText(java.lang.String text)
Add a text element to an element. |
void |
close()
Close the writer. |
void |
closeElement(E element)
Close an element. |
static java.lang.String |
escape(java.lang.String text)
Escape text for XML. |
void |
flush()
Flushes the underlying writer. |
protected E |
getCurrentElement()
Returns the element we are currently in. |
protected java.io.PrintWriter |
getWriter()
Get writer this writer writes to. |
void |
openElement(E element)
Start a new element |
void |
openElement(E element,
java.lang.Object... attributes)
Convenience method for adding an element together with (some of) its attributes. |
void |
setSuppressLineBreaks(boolean supressLineBreaks)
Toogle line break behavior. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final IXMLResolver<E extends java.lang.Enum<E>,A extends java.lang.Enum<A>> xmlResolver
Constructor Detail |
---|
public XMLWriter(java.io.OutputStream stream, IXMLResolver<E,A> xmlResolver)
stream
- the stream to write to.xmlResolver
- resolvers used by this writerpublic XMLWriter(java.io.PrintWriter writer, IXMLResolver<E,A> xmlResolver)
writer
- the writer to write to.xmlResolver
- resolvers used by this writerMethod Detail |
---|
public void setSuppressLineBreaks(boolean supressLineBreaks)
true
the writer does
not write line breaks. If set to false
(default) line breaks
are written.
This can, for example, be used for HTML where line breaks sometimes change the layout.
public void addHeader(java.lang.String version, java.lang.String encoding)
version
- version stringencoding
- encoding definitionpublic void addPublicDocTypeDefintion(E rootElement, java.lang.String publicId, java.lang.String systemId)
rootElement
- root elementpublicId
- public idsystemId
- sytem idpublic void openElement(E element)
element
- the element to start.public void addAttribute(A attribute, java.lang.Object value)
attribute
- the attribute to createvalue
- its value
XMLWriterException
- if there's no element to add attributes to (
EXMLWriterExceptionType.ATTRIBUTE_OUTSIDE_ELEMENT
) or
if an attribute is added twice (
EXMLWriterExceptionType.DUPLICATE_ATTRIBUTE
).public void openElement(E element, java.lang.Object... attributes)
element
- The element to be opened (using openElement(Enum)
).attributes
- the attributes to be added. The number of arguments must be
even, where the first, third, etc. argument is an attribute
enum.public void addClosedElement(E element, java.lang.Object... attributes)
openElement(Enum, Object[])
, but
also closes the element.
public void addClosedTextElement(E element, java.lang.String text, java.lang.Object... attributes)
openElement(Enum, Object[])
, but then adds the provided text and
closes the element.
public void closeElement(E element)
element
- the element to close.
XMLWriterException
- on attempt to close the wrong element (
EXMLWriterExceptionType.UNCLOSED_ELEMENT
).public void addText(java.lang.String text)
text
- the text to add.public void addCDataSection(java.lang.String cdata)
XMLWriterException
- If the added text contains the CDATA closing tag
]]>
. This is not automatically escaped as some
parsers do not automatically unescape it when reading.public void addComment(java.lang.String text)
text
- comment text.public void addNewLine()
public void close()
XMLWriterException
- if there is a remaining open element.public void flush()
protected void addRawString(java.lang.String text)
protected java.io.PrintWriter getWriter()
protected E getCurrentElement()
java.util.EmptyStackException
- if there is no unclosed element.public static java.lang.String escape(java.lang.String text)
null
value.
|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |