com.lowagie.text

Class DocWriter

public abstract class DocWriter extends Object implements DocListener

An abstract Writer class for documents.

DocWriter is the abstract class of several writers such as PdfWriter and HtmlWriter. A DocWriter can be added as a DocListener to a certain Document by getting an instance (see method getInstance() in the specific writer-classes). Every Element added to the original Document will be written to the OutputStream of the listening DocWriter.

See Also: Document DocListener

Field Summary
protected booleancloseStream
Closes the stream on document close
protected Documentdocument
This is the document that has to be written.
static byteEQUALS
This is some byte that is often used.
static byteFORWARD
This is some byte that is often used.
static byteGT
This is some byte that is often used.
static byteLT
This is some byte that is often used.
static byteNEWLINE
This is some byte that is often used.
protected booleanopen
Is the writer open for writing?
protected OutputStreamCounteros
The outputstream of this writer.
protected RectanglepageSize
The pageSize.
protected booleanpause
Do we have to pause all writing actions?
static byteQUOTE
This is some byte that is often used.
static byteSPACE
This is some byte that is often used.
static byteTAB
This is some byte that is often used.
Constructor Summary
protected DocWriter()
protected DocWriter(Document document, OutputStream os)
Constructs a DocWriter.
Method Summary
booleanadd(Element element)
Signals that an Element was added to the Document.
protected voidaddTabs(int indent)
Writes a number of tabs.
voidclose()
Signals that the Document was closed and that no other Elements will be added.
voidflush()
Flushes the BufferedOutputStream.
static byte[]getISOBytes(String text)
Converts a String into a Byte array according to the ISO-8859-1 codepage.
booleanisCloseStream()
Checks if the stream is to be closed on document close
booleanisPaused()
Checks if writing is paused.
booleannewPage()
Signals that an new page has to be started.
voidopen()
Signals that the Document was opened.
voidpause()
Let the writer know that all writing has to be paused.
voidresetFooter()
Resets the footer of this document.
voidresetHeader()
Resets the header of this document.
voidresetPageCount()
Sets the page number to 0.
voidresume()
Let the writer know that writing may be resumed.
voidsetCloseStream(boolean closeStream)
Sets the close state of the stream after document close
voidsetFooter(HeaderFooter footer)
Changes the footer of this document.
voidsetHeader(HeaderFooter header)
Changes the header of this document.
booleansetMarginMirroring(boolean MarginMirroring)
booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.
voidsetPageCount(int pageN)
Sets the page number.
booleansetPageSize(Rectangle pageSize)
Sets the pagesize.
protected voidwrite(String string)
Writes a String to the OutputStream.
protected voidwrite(String key, String value)
Writes a key-value pair to the outputstream.
protected voidwriteEnd(String tag)
Writes an endtag to the outputstream.
protected voidwriteEnd()
Writes an endtag to the outputstream.
protected booleanwriteMarkupAttributes(Properties markup)
Writes the markup attributes of the specified MarkupAttributes object to the OutputStream.
protected voidwriteStart(String tag)
Writes a starttag to the outputstream.

Field Detail

closeStream

protected boolean closeStream
Closes the stream on document close

document

protected Document document
This is the document that has to be written.

EQUALS

public static final byte EQUALS
This is some byte that is often used.

FORWARD

public static final byte FORWARD
This is some byte that is often used.

GT

public static final byte GT
This is some byte that is often used.

LT

public static final byte LT
This is some byte that is often used.

NEWLINE

public static final byte NEWLINE
This is some byte that is often used.

open

protected boolean open
Is the writer open for writing?

os

protected OutputStreamCounter os
The outputstream of this writer.

pageSize

protected Rectangle pageSize
The pageSize.

pause

protected boolean pause
Do we have to pause all writing actions?

QUOTE

public static final byte QUOTE
This is some byte that is often used.

SPACE

public static final byte SPACE
This is some byte that is often used.

TAB

public static final byte TAB
This is some byte that is often used.

Constructor Detail

DocWriter

protected DocWriter()

DocWriter

protected DocWriter(Document document, OutputStream os)
Constructs a DocWriter.

Parameters: document The Document that has to be written os The OutputStream the writer has to write to.

Method Detail

add

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

This method should be overridden in the specific DocWriter classes derived from this abstract class.

Parameters: element A high level object to add

Returns: false

Throws: DocumentException when a document isn't open yet, or has been closed

addTabs

protected void addTabs(int indent)
Writes a number of tabs.

Parameters: indent the number of tabs to add

Throws: IOException

close

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

flush

public void flush()
Flushes the BufferedOutputStream.

getISOBytes

public static final byte[] getISOBytes(String text)
Converts a String into a Byte array according to the ISO-8859-1 codepage.

Parameters: text the text to be converted

Returns: the conversion result

isCloseStream

public boolean isCloseStream()
Checks if the stream is to be closed on document close

Returns: true if the stream is closed on document close

isPaused

public boolean isPaused()
Checks if writing is paused.

Returns: true if writing temporarily has to be paused, false otherwise.

newPage

public boolean newPage()
Signals that an new page has to be started.

This does nothing. Has to be overridden if needed.

Returns: true if the page 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 was opened.

pause

public void pause()
Let the writer know that all writing has to be paused.

resetFooter

public void resetFooter()
Resets the footer of this document.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of footers.

resetHeader

public void resetHeader()
Resets the header of this document.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of headers.

resetPageCount

public void resetPageCount()
Sets the page number to 0.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of pagenumbers.

resume

public void resume()
Let the writer know that writing may be resumed.

setCloseStream

public void setCloseStream(boolean closeStream)
Sets the close state of the stream after document close

Parameters: closeStream true if the stream is closed on document close

setFooter

public void setFooter(HeaderFooter footer)
Changes the footer of this document.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of footers.

Parameters: footer the new footer

setHeader

public void setHeader(HeaderFooter header)
Changes the header of this document.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of headers.

Parameters: header the new header

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)

See Also: DocListener

setMargins

public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.

This does nothing. Has to be overridden if needed.

Parameters: marginLeft the margin on the left marginRight the margin on the right marginTop the margin on the top marginBottom the margin on the bottom

Returns: false

setPageCount

public void setPageCount(int pageN)
Sets the page number.

This method should be overridden in the specific DocWriter classes derived from this abstract class if they actually support the use of pagenumbers.

Parameters: pageN the new page number

setPageSize

public boolean setPageSize(Rectangle pageSize)
Sets the pagesize.

Parameters: pageSize the new pagesize

Returns: a boolean

write

protected void write(String string)
Writes a String to the OutputStream.

Parameters: string the String to write

Throws: IOException

write

protected void write(String key, String value)
Writes a key-value pair to the outputstream.

Parameters: key the name of an attribute value the value of an attribute

Throws: IOException

writeEnd

protected void writeEnd(String tag)
Writes an endtag to the outputstream.

Parameters: tag the name of the tag

Throws: IOException

writeEnd

protected void writeEnd()
Writes an endtag to the outputstream.

Throws: IOException

writeMarkupAttributes

protected boolean writeMarkupAttributes(Properties markup)
Writes the markup attributes of the specified MarkupAttributes object to the OutputStream.

Parameters: markup a Properties collection to write.

Returns: true, if writing the markup attributes succeeded

Throws: IOException

writeStart

protected void writeStart(String tag)
Writes a starttag to the outputstream.

Parameters: tag the name of the tag

Throws: IOException