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
.
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.
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.
closeStream
protected boolean closeStream
Closes the stream on document close
document
protected Document document
This is the document that has to be written.
open
protected boolean open
Is the writer open for writing?
pageSize
protected Rectangle pageSize
The pageSize.
pause
protected boolean pause
Do we have to pause all writing actions?
add
public boolean add(Element element)
throws DocumentException
Signals that an
Element
was added to the
Document
.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class.
- add in interface ElementListener
element
- A high level object to add
add
public boolean add(Watermark watermark)
Sets the
Watermark
.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
a
Watermark
.
- add in interface DocListener
watermark
- A watermark object
false
(because watermarks aren't supported by default).
addTabs
protected void addTabs(int indent)
throws IOException
Writes a number of tabs.
indent
- the number of tabs to add
close
public void close()
Signals that the Document
was closed and that no other
Elements
will be added.
- close in interface DocListener
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.
text
- the text to be converted
hasMarkupAttributes
protected static boolean hasMarkupAttributes(Element element)
Returns true
if the specified Element
implements
MarkupAttributes
and has one or more attributes to write.
element
- the Element
to check.
isCloseStream
public boolean isCloseStream()
Checks if the stream is to be closed on document close
- true if the stream is closed on documnt close
newPage
public boolean newPage()
throws DocumentException
Signals that an new page has to be started.
This does nothing. Has to be overridden if needed.
- newPage in interface DocListener
true
if the page was added, false
if not.
open
public void open()
Signals that the Document
was opened.
- open in interface DocListener
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 overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
footers.
- resetFooter in interface DocListener
resetHeader
public void resetHeader()
Resets the header of this document.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
headers.
- resetHeader in interface DocListener
resetPageCount
public void resetPageCount()
Sets the page number to 0.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
pagenumbers.
- resetPageCount in interface DocListener
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
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 overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
footers.
- setFooter in interface DocListener
setHeader
public void setHeader(HeaderFooter header)
Changes the header of this document.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
headers.
- setHeader in interface 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.
- setMargins in interface DocListener
marginLeft
- the margin on the leftmarginRight
- the margin on the rightmarginTop
- the margin on the topmarginBottom
- the margin on the bottom
setPageCount
public void setPageCount(int pageN)
Sets the page number.
This method should be overriden in the specific
DocWriter
classes
derived from this abstract class if they actually support the use of
pagenumbers.
- setPageCount in interface DocListener
pageN
- the new page number
write
protected void write(String string)
throws IOException
Writes a String
to the OutputStream
.
string
- the String
to write
write
protected void write(String key,
String value)
throws IOException
Writes a key-value pair to the outputstream.
key
- the name of an attributevalue
- the value of an attribute
writeEnd
protected void writeEnd()
throws IOException
Writes an endtag to the outputstream.
writeEnd
protected void writeEnd(String tag)
throws IOException
Writes an endtag to the outputstream.
tag
- the name of the tag
writeMarkupAttributes
protected boolean writeMarkupAttributes(MarkupAttributes mAtt)
throws IOException
Writes the markup attributes of the specified MarkupAttributes
object to the OutputStream
.
mAtt
- the MarkupAttributes
to write.
- true, if writing the markup attributes succeeded
writeStart
protected void writeStart(String tag)
throws IOException
Writes a starttag to the outputstream.
tag
- the name of the tag