Package com.aowagie.text.xml
Class SAXiTextHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.aowagie.text.xml.SAXiTextHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
- Direct Known Subclasses:
SAXmyHandler
class SAXiTextHandler extends org.xml.sax.helpers.DefaultHandlerThis class is a Handler that controls the iText XML to PDF conversion. Subclass it, if you want to change the way iText translates XML to PDF.
-
-
Field Summary
Fields Modifier and Type Field Description private BaseFontbfprivate floatbottomMargincurrent margin of a page.private booleancontrolOpenCloseThis is a flag that can be set, if you want to open and close the Document-object yourself.private ChunkcurrentChunkThis is the current chunk to which characters can be added.private DocListenerdocumentThis is the resulting document.private booleanignoreThis is the current chunk to which characters can be added.private floatleftMargincurrent margin of a page.protected java.util.HashMapmyTagsThis hashmap contains all the custom keys and peers.private floatrightMargincurrent margin of a page.private java.util.StackstackThis is aStackof objects, waiting to be added to the document.private floattopMargincurrent margin of a page.
-
Constructor Summary
Constructors Modifier Constructor Description (package private)SAXiTextHandler(DocListener document)privateSAXiTextHandler(DocListener document, HtmlTagMap myTags)(package private)SAXiTextHandler(DocListener document, java.util.HashMap myTags)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddImage(Image img)voidcharacters(char[] ch, int start, int length)This method gets called when characters are encountered.voidendElement(java.lang.String uri, java.lang.String lname, java.lang.String name)This method gets called when an end tag is encountered.(package private) voidhandleEndingTags(java.lang.String name)This method deals with the starting tags.(package private) voidhandleStartingTags(java.lang.String name, java.util.Properties attributes)This method deals with the starting tags.voidignorableWhitespace(char[] ch, int start, int length)This method gets called when ignorable white space encountered.private booleanisDocumentRoot(java.lang.String tag)Checks if a certain tag corresponds with the roottag.private booleanisNewline(java.lang.String tag)Checks if a certain tag corresponds with the newpage-tag.private booleanisNewpage(java.lang.String tag)Checks if a certain tag corresponds with the newpage-tag.voidsetBaseFont(BaseFont bf)Sets the font that has to be used.voidsetControlOpenClose(boolean controlOpenClose)Sets the parameter that allows you to enable/disable the control over the Document.open() and Document.close() method.voidstartElement(java.lang.String uri, java.lang.String lname, java.lang.String name, org.xml.sax.Attributes attrs)This method gets called when a start tag is encountered.
-
-
-
Field Detail
-
document
private final DocListener document
This is the resulting document.
-
stack
private final java.util.Stack stack
This is aStackof objects, waiting to be added to the document.
-
currentChunk
private Chunk currentChunk
This is the current chunk to which characters can be added.
-
ignore
private boolean ignore
This is the current chunk to which characters can be added.
-
controlOpenClose
private boolean controlOpenClose
This is a flag that can be set, if you want to open and close the Document-object yourself.
-
topMargin
private float topMargin
current margin of a page.
-
rightMargin
private float rightMargin
current margin of a page.
-
leftMargin
private float leftMargin
current margin of a page.
-
bottomMargin
private float bottomMargin
current margin of a page.
-
myTags
protected java.util.HashMap myTags
This hashmap contains all the custom keys and peers.
-
bf
private BaseFont bf
-
-
Constructor Detail
-
SAXiTextHandler
SAXiTextHandler(DocListener document)
- Parameters:
document- Document
-
SAXiTextHandler
private SAXiTextHandler(DocListener document, HtmlTagMap myTags)
- Parameters:
document- DocumentmyTags- tags
-
SAXiTextHandler
SAXiTextHandler(DocListener document, java.util.HashMap myTags)
- Parameters:
document- DocumentmyTags- tags
-
-
Method Detail
-
setControlOpenClose
public void setControlOpenClose(boolean controlOpenClose)
Sets the parameter that allows you to enable/disable the control over the Document.open() and Document.close() method.If you set this parameter to true (= default), the parser will open the Document object when the start-root-tag is encountered and close it when the end-root-tag is met. If you set it to false, you have to open and close the Document object yourself.
- Parameters:
controlOpenClose- set this to false if you plan to open/close the Document yourself
-
startElement
public void startElement(java.lang.String uri, java.lang.String lname, java.lang.String name, org.xml.sax.Attributes attrs)This method gets called when a start tag is encountered.- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Parameters:
uri- the Uniform Resource Identifierlname- the local name (without prefix), or the empty string if Namespace processing is not being performed.name- the name of the tag that is encounteredattrs- the list of attributes
-
handleStartingTags
void handleStartingTags(java.lang.String name, java.util.Properties attributes)This method deals with the starting tags.- Parameters:
name- the name of the tagattributes- the list of attributes
-
addImage
private void addImage(Image img) throws java.util.EmptyStackException
- Throws:
java.util.EmptyStackException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length)This method gets called when ignorable white space encountered.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Overrides:
ignorableWhitespacein classorg.xml.sax.helpers.DefaultHandler- Parameters:
ch- an array of charactersstart- the start position in the arraylength- the number of characters to read from the array
-
characters
public void characters(char[] ch, int start, int length)This method gets called when characters are encountered.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Parameters:
ch- an array of charactersstart- the start position in the arraylength- the number of characters to read from the array
-
setBaseFont
public void setBaseFont(BaseFont bf)
Sets the font that has to be used.- Parameters:
bf- Base font
-
endElement
public void endElement(java.lang.String uri, java.lang.String lname, java.lang.String name)This method gets called when an end tag is encountered.- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Parameters:
uri- the Uniform Resource Identifierlname- the local name (without prefix), or the empty string if Namespace processing is not being performed.name- the name of the tag that ends
-
handleEndingTags
void handleEndingTags(java.lang.String name)
This method deals with the starting tags.- Parameters:
name- the name of the tag
-
isNewpage
private boolean isNewpage(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag- a presumed tagname- Returns:
trueorfalse
-
isNewline
private boolean isNewline(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag- a presumed tagname- Returns:
trueorfalse
-
isDocumentRoot
private boolean isDocumentRoot(java.lang.String tag)
Checks if a certain tag corresponds with the roottag.- Parameters:
tag- a presumed tagname- Returns:
trueif tag equalsitext,falseotherwise.
-
-