|
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 Enum<E>,A extends 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(OutputStream stream,
IXMLResolver<E,A> xmlResolver)
Create a new writer. |
|
XMLWriter(PrintWriter writer,
IXMLResolver<E,A> xmlResolver)
Create a new writer. |
|
| Method Summary | |
|---|---|
void |
addAttribute(A attribute,
Object value)
Add a attribute. |
void |
addCDataSection(String cdata)
Add CDATA section. |
void |
addClosedElement(E element,
Object... attributes)
Convenience method for adding an element together with (some of) its attributes. |
void |
addClosedTextElement(E element,
String text,
Object... attributes)
Convenience method for adding an element together with (some of) its attributes and text inbetween. |
void |
addComment(String text)
Add an XML comment. |
void |
addHeader(String version,
String encoding)
Add an XML header. |
void |
addNewLine()
Add new line. |
void |
addPublicDocTypeDefintion(E rootElement,
String publicId,
String systemId)
Add public document type definiton |
protected void |
addRawString(String text)
Adds the given text unprocessed to the writer. |
void |
addText(String text)
Add a text element to an element. |
void |
close()
Close the writer. |
void |
closeElement(E element)
Close an element. |
static String |
escape(String text)
Escape text for XML. |
void |
flush()
Flushes the underlying writer. |
protected E |
getCurrentElement()
Returns the element we are currently in. |
protected PrintWriter |
getWriter()
Get writer this writer writes to. |
void |
openElement(E element)
Start a new element |
void |
openElement(E element,
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 Enum<E>,A extends Enum<A>> xmlResolver
| Constructor Detail |
|---|
public XMLWriter(OutputStream stream,
IXMLResolver<E,A> xmlResolver)
stream - the stream to write to.xmlResolver - resolvers used by this writer
public XMLWriter(PrintWriter writer,
IXMLResolver<E,A> xmlResolver)
writer - the writer to write to.xmlResolver - resolvers used by this writer| Method 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(String version,
String encoding)
version - version stringencoding - encoding definition
public void addPublicDocTypeDefintion(E rootElement,
String publicId,
String systemId)
rootElement - root elementpublicId - public idsystemId - sytem idpublic void openElement(E element)
element - the element to start.
public void addAttribute(A attribute,
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,
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,
Object... attributes)
openElement(Enum, Object[]), but
also closes the element.
public void addClosedTextElement(E element,
String text,
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(String text)
text - the text to add.public void addCDataSection(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(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(String text)
protected PrintWriter getWriter()
protected E getCurrentElement()
EmptyStackException - if there is no unclosed element.public static String escape(String text)
null value.
|
TUM CCSM Commons | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||