Class DocWriter
- All Implemented Interfaces:
DocListener, ElementListener, EventListener
- Direct Known Subclasses:
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 booleanCloses the stream on document closestatic final byteThis is some byte that is often used.static final byteThis is some byte that is often used.static final byteThis is some byte that is often used.static final byteThis is some byte that is often used.protected booleanDo we have to pause all writing actions?static final byteThis is some byte that is often used.booleanIs the writer open for writing?The outputstream of this writer.protected RectangleThe pageSize.static final byteThis is some byte that is often used.static final byteThis is some byte that is often used.static final byteThis is some byte that is often used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedConstructs aDocWriter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSignals that anElementwas added to theDocument.protected voidaddTabs(int indent) Writes a number of tabs.voidClears text wrapping around images (if applicable).voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.voidflush()Flushes theBufferedOutputStream.static final byte[]getISOBytes(String text) Converts aStringinto aBytearray according to the ISO-8859-1 codepage.protected static booleanhasMarkupAttributes(Element element) Returnstrueif the specifiedElementimplementsMarkupAttributesand has one or more attributes to write.booleanChecks if the stream is to be closed on document closebooleannewPage()Signals that an new page has to be started.voidopen()Signals that theDocumentwas opened.voidpause()Let the writer know that all writing has to be paused.voidResets the footer of this document.voidResets the header of this document.voidSets 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 closebooleansetMarginMirroring(boolean MarginMirroring) Parameter that allows you to do margin mirroring (odd/even pages)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 voidWrites aStringto theOutputStream.protected voidWrites a key-value pair to the outputstream.protected voidwriteEnd()Writes an endtag to the outputstream.protected voidWrites an endtag to the outputstream.protected booleanWrites the markup attributes of the specifiedMarkupAttributesobject to theOutputStream.protected voidwriteStart(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. -
os
The outputstream of this writer. -
open
public boolean openIs the writer open for writing? -
m_pause
protected boolean m_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:
os- TheOutputStreamthe writer has to write to.document- TheDocumentthat has to be written
-
-
Method Details
-
add
Signals that anElementwas added to theDocument.This method should be overriden in the specific
DocWriterclasses derived from this abstract class.- Specified by:
addin 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 theDocumentwas opened.- Specified by:
openin interfaceDocListener
-
setPageSize
Sets the pagesize.- Specified by:
setPageSizein 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:
setMarginsin 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
Signals that an new page has to be started.This does nothing. Has to be overridden if needed.
- Specified by:
newPagein interfaceDocListener- Returns:
trueif the page was added,falseif not.- Throws:
DocumentException- when a document isn't open yet, or has been closed
-
resetHeader
public void resetHeader()Resets the header of this document.This method should be overriden in the specific
DocWriterclasses 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 overriden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of pagenumbers.- Specified by:
resetPageCountin interfaceDocListener
-
setPageCount
public void setPageCount(int pageN) Sets the page number.This method should be overriden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of pagenumbers.- Specified by:
setPageCountin interfaceDocListener- Parameters:
pageN- the new page number
-
close
public void close()Signals that theDocumentwas closed and that no otherElementswill be added.- Specified by:
closein interfaceDocListener
-
getISOBytes
Converts aStringinto aBytearray according to the ISO-8859-1 codepage.- Parameters:
text- the text to be converted- Returns:
- the conversion result
-
pause
public void pause()Let the writer know that all writing has to be paused. -
resume
public void resume()Let the writer know that writing may be resumed. -
flush
public void flush()Flushes theBufferedOutputStream. -
write
Writes aStringto theOutputStream.- Parameters:
string- theStringto write- Throws:
IOException
-
addTabs
Writes a number of tabs.- Parameters:
indent- the number of tabs to add- Throws:
IOException
-
write
Writes a key-value pair to the outputstream.- Parameters:
key- the name of an attributevalue- the value of an attribute- Throws:
IOException
-
writeStart
Writes a starttag to the outputstream.- Parameters:
tag- the name of the tag- Throws:
IOException
-
writeEnd
Writes an endtag to the outputstream.- Parameters:
tag- the name of the tag- Throws:
IOException
-
writeEnd
Writes an endtag to the outputstream.- Throws:
IOException
-
writeMarkupAttributes
Writes the markup attributes of the specifiedMarkupAttributesobject to theOutputStream.- Parameters:
mAtt- theMarkupAttributesto write.- Returns:
- true, if writing the markup attributes succeeded
- Throws:
IOException
-
hasMarkupAttributes
Returnstrueif the specifiedElementimplementsMarkupAttributesand has one or more attributes to write.- Parameters:
element- theElementto check.- Returns:
boolean.
-
isCloseStream
public boolean isCloseStream()Checks if the stream is to be closed on document close- Returns:
- true if the stream is closed on documnt 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
-
clearTextWrap
Description copied from interface:DocListenerClears text wrapping around images (if applicable). Method suggested by Pelikan Stephan- Specified by:
clearTextWrapin interfaceDocListener- Throws:
DocumentException- See Also:
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring) Description copied from interface:DocListenerParameter that allows you to do margin mirroring (odd/even pages)- Specified by:
setMarginMirroringin interfaceDocListener- Parameters:
MarginMirroring-- Returns:
- true if succesfull
- See Also:
-