Class DocWriter
- All Implemented Interfaces:
DocListener
,ElementListener
,AutoCloseable
,EventListener
- Direct Known Subclasses:
HtmlWriter
,PdfWriter
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Closes the stream on document closeprotected Document
This is the document that has to be written.static final byte
This is some byte that is often used.static final byte
This is some byte that is often used.static final byte
This is some byte that is often used.static final byte
This is some byte that is often used.static final byte
This is some byte that is often used.protected boolean
Is the writer open for writing?protected OutputStreamCounter
The outputstream of this writer.protected Rectangle
The pageSize.protected boolean
Do we have to pause all writing actions?static final byte
This is some byte that is often used.static final byte
This is some byte that is often used.static final byte
This is some byte that is often used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
DocWriter
(Document document, OutputStream os) Constructs aDocWriter
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Signals that anElement
was added to theDocument
.protected void
addTabs
(int indent) Writes a number of tabs.void
close()
Signals that theDocument
was closed and that no otherElements
will be added.void
flush()
Flushes theBufferedOutputStream
.static final byte[]
getISOBytes
(String text) Converts aString
into aByte
array according to the ISO-8859-1 codepage.boolean
Checks if the stream is to be closed on document closeboolean
isPaused()
Checks if writing is paused.boolean
newPage()
Signals that an new page has to be started.void
open()
Signals that theDocument
was opened.void
pause()
Let the writer know that all writing has to be paused.void
Resets the footer of this document.void
Resets the header of this document.void
Sets the page number to 0.void
resume()
Let the writer know that writing may be resumed.void
setCloseStream
(boolean closeStream) Sets the close state of the stream after document closevoid
setFooter
(HeaderFooter footer) Changes the footer of this document.void
setHeader
(HeaderFooter header) Changes the header of this document.boolean
setMarginMirroring
(boolean MarginMirroring) Allows you to do left/right margin mirroring (odd/even pages)boolean
setMarginMirroringTopBottom
(boolean MarginMirroring) Parameter that allows you to do top/bottom margin mirroring (odd/even pages)boolean
setMargins
(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.void
setPageCount
(int pageN) Sets the page number.boolean
setPageSize
(Rectangle pageSize) Sets the pagesize.protected void
Writes aString
to theOutputStream
.protected void
Writes a key-value pair to the outputstream.protected void
writeEnd()
Writes an endtag to the outputstream.protected void
Writes an endtag to the outputstream.protected boolean
writeMarkupAttributes
(Properties markup) Writes the markup attributes of the specifiedMarkupAttributes
object to theOutputStream
.protected void
writeStart
(String tag) Writes a starttag to the outputstream.
-
Field Details
-
NEWLINE
public static final byte NEWLINEThis is some byte that is often used.- See Also:
-
TAB
public static final byte TABThis is some byte that is often used.- See Also:
-
LT
public static final byte LTThis is some byte that is often used.- See Also:
-
SPACE
public static final byte SPACEThis is some byte that is often used.- See Also:
-
EQUALS
public static final byte EQUALSThis is some byte that is often used.- See Also:
-
QUOTE
public static final byte QUOTEThis is some byte that is often used.- See Also:
-
GT
public static final byte GTThis is some byte that is often used.- See Also:
-
FORWARD
public static final byte FORWARDThis is some byte that is often used.- See Also:
-
pageSize
The pageSize. -
document
This is the document that has to be written. -
os
The outputstream of this writer. -
open
protected boolean openIs the writer open for writing? -
pause
protected boolean pauseDo we have to pause all writing actions? -
closeStream
protected boolean closeStreamCloses the stream on document close
-
-
Constructor Details
-
DocWriter
protected DocWriter() -
DocWriter
Constructs aDocWriter
.- Parameters:
document
- TheDocument
that has to be writtenos
- TheOutputStream
the writer has to write to.
-
-
Method Details
-
getISOBytes
Converts aString
into aByte
array according to the ISO-8859-1 codepage.- Parameters:
text
- the text to be converted- Returns:
- the conversion result
-
add
Signals that anElement
was added to theDocument
.This method should be overridden in the specific
DocWriter
classes derived from this abstract class.- Specified by:
add
in interfaceElementListener
- Parameters:
element
- A high level object to add- Returns:
false
- Throws:
DocumentException
- when a document isn't open yet, or has been closed
-
open
public void open()Signals that theDocument
was opened.- Specified by:
open
in interfaceDocListener
-
setPageSize
Sets the pagesize.- Specified by:
setPageSize
in interfaceDocListener
- Parameters:
pageSize
- the new pagesize- Returns:
- a
boolean
-
setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.This does nothing. Has to be overridden if needed.
- Specified by:
setMargins
in interfaceDocListener
- Parameters:
marginLeft
- the margin on the leftmarginRight
- the margin on the rightmarginTop
- the margin on the topmarginBottom
- the margin on the bottom- Returns:
false
-
newPage
public boolean newPage()Signals that an new page has to be started.This does nothing. Has to be overridden if needed.
- Specified by:
newPage
in interfaceDocListener
- Returns:
true
if the page was added,false
if not.
-
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.- Specified by:
resetHeader
in interfaceDocListener
-
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.- Specified by:
resetPageCount
in interfaceDocListener
-
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.- Specified by:
setPageCount
in interfaceDocListener
- Parameters:
pageN
- the new page number
-
close
public void close()Signals that theDocument
was closed and that no otherElements
will be added.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDocListener
-
pause
public void pause()Let the writer know that all writing has to be paused. -
isPaused
public boolean isPaused()Checks if writing is paused.- Returns:
true
if writing temporarily has to be paused,false
otherwise.
-
resume
public void resume()Let the writer know that writing may be resumed. -
flush
public void flush()Flushes theBufferedOutputStream
. -
write
Writes aString
to theOutputStream
.- Parameters:
string
- theString
to write- Throws:
IOException
- if there is any error
-
addTabs
Writes a number of tabs.- Parameters:
indent
- the number of tabs to add- Throws:
IOException
- if there is any error
-
write
Writes a key-value pair to the outputstream.- Parameters:
key
- the name of an attributevalue
- the value of an attribute- Throws:
IOException
- if there is any error
-
writeStart
Writes a starttag to the outputstream.- Parameters:
tag
- the name of the tag- Throws:
IOException
- if there is any error
-
writeEnd
Writes an endtag to the outputstream.- Parameters:
tag
- the name of the tag- Throws:
IOException
- if there is any error
-
writeEnd
Writes an endtag to the outputstream.- Throws:
IOException
- if there is any error
-
writeMarkupAttributes
Writes the markup attributes of the specifiedMarkupAttributes
object to theOutputStream
.- Parameters:
markup
- aProperties
collection to write.- Returns:
- true, if writing the markup attributes succeeded
- Throws:
IOException
- if there is any error
-
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
-
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
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring) Description copied from interface:DocListener
Allows you to do left/right margin mirroring (odd/even pages)- Specified by:
setMarginMirroring
in interfaceDocListener
- Parameters:
MarginMirroring
- left/right margin mirroring (odd/even pages)- Returns:
- true if successful
- See Also:
-
setMarginMirroringTopBottom
public boolean setMarginMirroringTopBottom(boolean MarginMirroring) Description copied from interface:DocListener
Parameter that allows you to do top/bottom margin mirroring (odd/even pages)- Specified by:
setMarginMirroringTopBottom
in interfaceDocListener
- Parameters:
MarginMirroring
- top/bottom margin mirroring (odd/even pages)- Returns:
- true if successful
- Since:
- 2.1.6
- See Also:
-