public class XmlWriter extends DocWriter implements DocListener
DocWriter class for XML (Remark: this class is not finished yet!).
An XmlWriter can be added as a DocListener
to a certain Document by getting an instance.
Every Element added to the original Document
will be written to the OutputStream of this XmlWriter.
Example:
// creation of the document with a certain size and certain margins
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// this will write XML to the Standard OutputStream
XmlWriter.getInstance(document, System.out);
// this will write XML to a file called text.html
XmlWriter.getInstance(document, new FileOutputStream("text.xml"));
// this will write XML to for instance the OutputStream of a HttpServletResponse-object
XmlWriter.getInstance(document, response.getOutputStream());
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
// this will close the document and all the OutputStreams listening to it
document.close();
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
DOCTYPE
This is the reference to the DTD.
|
static byte[] |
DTD
This is the place where the DTD is located.
|
private java.util.TreeMap |
itext
This is the meta information of the document.
|
static byte[] |
PROLOG
This is the first line of the XML page.
|
private static java.lang.String[] |
xmlCode
This is an array containing character to XML translations.
|
| Modifier | Constructor and Description |
|---|---|
protected |
XmlWriter(Document doc,
java.io.OutputStream os)
Constructs an
XmlWriter. |
protected |
XmlWriter(Document doc,
java.io.OutputStream os,
java.lang.String dtd)
Constructs an
XmlWriter. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Element element)
Signals that an
Element was added to the Document. |
(package private) static void |
addTabs(java.lang.StringBuffer buf,
int indent)
Adds a number of tabs to a
StringBuffer. |
void |
close()
Signals that the
Document was closed and that no other
Elements will be added. |
(package private) static java.lang.String |
encode(java.lang.String string,
int indent)
Encodes a
String. |
static XmlWriter |
getInstance(Document document,
java.io.OutputStream os)
Gets an instance of the
XmlWriter. |
static XmlWriter |
getInstance(Document document,
java.io.OutputStream os,
java.lang.String dtd)
Gets an instance of the
XmlWriter. |
boolean |
newPage()
Signals that an new page has to be LTed.
|
void |
open()
Signals that the
Document has been opened and that
Elements can be added. |
private void |
write(Element element,
int indent)
Writes the XML representation of an element.
|
private void |
write(Font font)
Writes the XML representation of a
Font. |
private void |
write(Rectangle rectangle)
Writes the XML representation of this
Rectangle. |
private void |
writeSection(Section section,
int indent)
Writes the XML representation of a section.
|
add, addTabs, clearTextWrap, flush, getISOBytes, hasMarkupAttributes, isCloseStream, pause, removeWatermark, resetFooter, resetHeader, resetPageCount, resume, setCloseStream, setFooter, setHeader, setMarginMirroring, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStartclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadd, clearTextWrap, removeWatermark, resetFooter, resetHeader, resetPageCount, setFooter, setHeader, setMarginMirroring, setMargins, setPageCount, setPageSizepublic static final byte[] PROLOG
public static final byte[] DOCTYPE
public static final byte[] DTD
private static final java.lang.String[] xmlCode
private java.util.TreeMap itext
protected XmlWriter(Document doc, java.io.OutputStream os)
XmlWriter.doc - The Document that has to be written as XMLos - The OutputStream the writer has to write to.protected XmlWriter(Document doc, java.io.OutputStream os, java.lang.String dtd)
XmlWriter.doc - The Document that has to be written as XMLos - The OutputStream the writer has to write to.dtd - The DTD to usepublic static XmlWriter getInstance(Document document, java.io.OutputStream os)
XmlWriter.document - The Document that has to be writtenos - The OutputStream the writer has to write to.XmlWriterpublic static XmlWriter getInstance(Document document, java.io.OutputStream os, java.lang.String dtd)
XmlWriter.document - The Document that has to be writtenos - The OutputStream the writer has to write to.dtd - The DTD to useXmlWriterpublic boolean add(Element element) throws DocumentException
Element was added to the Document.add in interface ElementListeneradd in class DocWriterelement - A high level object that will be added to the XMLtrue if the element was added, false if not.DocumentException - when a document isn't open yet, or has been closedpublic void open()
Document has been opened and that
Elements can be added.open in interface DocListeneropen in class DocWriterpublic boolean newPage()
throws DocumentException
newPage in interface DocListenernewPage in class DocWritertrue if the page was added, false if not.DocumentException - when a document isn't open yet, or has been closedpublic void close()
Document was closed and that no other
Elements will be added.close in interface DocListenerclose in class DocWriterprivate void write(Element element, int indent) throws java.io.IOException
element - the elementindent - the indentationjava.io.IOExceptionprivate void writeSection(Section section, int indent) throws java.io.IOException
section - the section to writeindent - the indentationjava.io.IOExceptionprivate void write(Rectangle rectangle) throws java.io.IOException
Rectangle.rectangle - a Rectanglejava.io.IOExceptionstatic final java.lang.String encode(java.lang.String string,
int indent)
String.string - the String to encodeindent - counter that keeps the number of tabs that has to be added for indentationStringstatic final void addTabs(java.lang.StringBuffer buf,
int indent)
StringBuffer.buf - the stringbufferindent - the number of tabs to addprivate void write(Font font) throws java.io.IOException
Font.font - a Fontjava.io.IOException