com.lowagie.text.xml
Class XmlWriter

java.lang.Object
  extended by com.lowagie.text.DocWriter
      extended by com.lowagie.text.xml.XmlWriter
All Implemented Interfaces:
DocListener, ElementListener, EventListener

public class XmlWriter
extends DocWriter
implements DocListener

A 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();
 


Field Summary
static byte[] DOCTYPE
          This is the reference to the DTD.
static byte[] DTD
          This is the place where the DTD is located.
static byte[] PROLOG
          This is the first line of the XML page.
 
Fields inherited from class com.lowagie.text.DocWriter
closeStream, document, EQUALS, FORWARD, GT, LT, NEWLINE, open, os, pageSize, pause, QUOTE, SPACE, TAB
 
Constructor Summary
protected XmlWriter(Document doc, OutputStream os)
          Constructs an XmlWriter.
protected XmlWriter(Document doc, OutputStream os, String dtd)
          Constructs an XmlWriter.
 
Method Summary
 boolean add(Element element)
          Signals that an Element was added to the Document.
 void close()
          Signals that the Document was closed and that no other Elements will be added.
static XmlWriter getInstance(Document document, OutputStream os)
          Gets an instance of the XmlWriter.
static XmlWriter getInstance(Document document, OutputStream os, 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.
 
Methods inherited from class com.lowagie.text.DocWriter
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, writeStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.lowagie.text.DocListener
add, clearTextWrap, removeWatermark, resetFooter, resetHeader, resetPageCount, setFooter, setHeader, setMarginMirroring, setMargins, setPageCount, setPageSize
 

Field Detail

PROLOG

public static final byte[] PROLOG
This is the first line of the XML page.


DOCTYPE

public static final byte[] DOCTYPE
This is the reference to the DTD.


DTD

public static final byte[] DTD
This is the place where the DTD is located.

Constructor Detail

XmlWriter

protected XmlWriter(Document doc,
                    OutputStream os)
Constructs an XmlWriter.

Parameters:
doc - The Document that has to be written as XML
os - The OutputStream the writer has to write to.

XmlWriter

protected XmlWriter(Document doc,
                    OutputStream os,
                    String dtd)
Constructs an XmlWriter.

Parameters:
doc - The Document that has to be written as XML
os - The OutputStream the writer has to write to.
dtd - The DTD to use
Method Detail

getInstance

public static XmlWriter getInstance(Document document,
                                    OutputStream os)
Gets an instance of the XmlWriter.

Parameters:
document - The Document that has to be written
os - The OutputStream the writer has to write to.
Returns:
a new XmlWriter

getInstance

public static XmlWriter getInstance(Document document,
                                    OutputStream os,
                                    String dtd)
Gets an instance of the XmlWriter.

Parameters:
document - The Document that has to be written
os - The OutputStream the writer has to write to.
dtd - The DTD to use
Returns:
a new XmlWriter

add

public boolean add(Element element)
            throws DocumentException
Signals that an Element was added to the Document.

Specified by:
add in interface ElementListener
Overrides:
add in class DocWriter
Parameters:
element - A high level object that will be added to the XML
Returns:
true if the element was added, false if not.
Throws:
DocumentException - when a document isn't open yet, or has been closed

open

public void open()
Signals that the Document has been opened and that Elements can be added.

Specified by:
open in interface DocListener
Overrides:
open in class DocWriter

newPage

public boolean newPage()
                throws DocumentException
Signals that an new page has to be LTed.

Specified by:
newPage in interface DocListener
Overrides:
newPage in class DocWriter
Returns:
true if the page was added, false if not.
Throws:
DocumentException - when a document isn't open yet, or has been closed

close

public void close()
Signals that the Document was closed and that no other Elements will be added.

Specified by:
close in interface DocListener
Overrides:
close in class DocWriter


Copyright © 2006-2007 EGIZ - E-Government Innovationszentrum. All Rights Reserved.