Class SAXiTextHandler
java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.aowagie.text.xml.SAXiTextHandler
- All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
- Direct Known Subclasses:
SAXmyHandler
This 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
FieldsModifier and TypeFieldDescriptionprivate BaseFontprivate floatcurrent margin of a page.private booleanThis is a flag that can be set, if you want to open and close the Document-object yourself.private ChunkThis is the current chunk to which characters can be added.private final DocListenerThis is the resulting document.private booleanThis is the current chunk to which characters can be added.private floatcurrent margin of a page.protected HashMapThis hashmap contains all the custom keys and peers.private floatcurrent margin of a page.private final StackThis is aStackof objects, waiting to be added to the document.private floatcurrent margin of a page. -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)SAXiTextHandler(DocListener document) privateSAXiTextHandler(DocListener document, HtmlTagMap myTags) (package private)SAXiTextHandler(DocListener document, HashMap myTags) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidvoidcharacters(char[] ch, int start, int length) This method gets called when characters are encountered.voidendElement(String uri, String lname, String name) This method gets called when an end tag is encountered.(package private) voidhandleEndingTags(String name) This method deals with the starting tags.(package private) voidhandleStartingTags(String name, 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(String tag) Checks if a certain tag corresponds with the roottag.private booleanChecks if a certain tag corresponds with the newpage-tag.private booleanChecks 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(String uri, String lname, String name, Attributes attrs) This method gets called when a start tag is encountered.Methods inherited from class DefaultHandler
endDocument, endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentHandler
declaration
-
Field Details
-
document
This is the resulting document. -
stack
This is aStackof objects, waiting to be added to the document. -
currentChunk
This is the current chunk to which characters can be added. -
ignore
private boolean ignoreThis is the current chunk to which characters can be added. -
controlOpenClose
private boolean controlOpenCloseThis is a flag that can be set, if you want to open and close the Document-object yourself. -
topMargin
private float topMargincurrent margin of a page. -
rightMargin
private float rightMargincurrent margin of a page. -
leftMargin
private float leftMargincurrent margin of a page. -
bottomMargin
private float bottomMargincurrent margin of a page. -
myTags
This hashmap contains all the custom keys and peers. -
bf
-
-
Constructor Details
-
SAXiTextHandler
SAXiTextHandler(DocListener document) - Parameters:
document- Document
-
SAXiTextHandler
- Parameters:
document- DocumentmyTags- tags
-
SAXiTextHandler
SAXiTextHandler(DocListener document, HashMap myTags) - Parameters:
document- DocumentmyTags- tags
-
-
Method Details
-
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
This method gets called when a start tag is encountered.- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- 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
This method deals with the starting tags.- Parameters:
name- the name of the tagattributes- the list of attributes
-
addImage
- Throws:
EmptyStackException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) This method gets called when ignorable white space encountered.- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- 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 interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Parameters:
ch- an array of charactersstart- the start position in the arraylength- the number of characters to read from the array
-
setBaseFont
-
endElement
This method gets called when an end tag is encountered.- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- 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
This method deals with the starting tags.- Parameters:
name- the name of the tag
-
isNewpage
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag- a presumed tagname- Returns:
trueorfalse
-
isNewline
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag- a presumed tagname- Returns:
trueorfalse
-
isDocumentRoot
Checks if a certain tag corresponds with the roottag.- Parameters:
tag- a presumed tagname- Returns:
trueif tag equalsitext,falseotherwise.
-