Package com.lowagie.text.xml
Class SAXiTextHandler<T extends XmlPeer>
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.lowagie.text.xml.SAXiTextHandler<T>
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
- Direct Known Subclasses:
SAXmyHandler
,SAXmyHtmlHandler
public class SAXiTextHandler<T extends XmlPeer> extends org.xml.sax.helpers.DefaultHandler
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
Fields Modifier and Type Field Description private BaseFont
bf
private float
bottomMargin
current margin of a page.protected int
chapters
Counts the number of chapters in this document.private boolean
controlOpenClose
This is a flag that can be set, if you want to open and close the Document-object yourself.protected Chunk
currentChunk
This is the current chunk to which characters can be added.protected DocListener
document
This is the resulting document.protected boolean
ignore
This is the current chunk to which characters can be added.private float
leftMargin
current margin of a page.protected java.util.Map<java.lang.String,T>
myTags
This hashmap contains all the custom keys and peers.private float
rightMargin
current margin of a page.protected java.util.Stack<Element>
stack
This is aStack
of objects, waiting to be added to the document.private float
topMargin
current margin of a page.
-
Constructor Summary
Constructors Constructor Description SAXiTextHandler(DocListener document)
SAXiTextHandler(DocListener document, java.util.Map<java.lang.String,T> myTags)
SAXiTextHandler(DocListener document, java.util.Map<java.lang.String,T> myTags, BaseFont bf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addImage(Image img)
void
characters(char[] ch, int start, int length)
This method gets called when characters are encountered.void
endElement(java.lang.String uri, java.lang.String lname, java.lang.String name)
This method gets called when an end tag is encountered.void
handleEndingTags(java.lang.String name)
This method deals with the starting tags.void
handleStartingTags(java.lang.String name, java.util.Properties attributes)
This method deals with the starting tags.void
ignorableWhitespace(char[] ch, int start, int length)
This method gets called when ignorable white space encountered.protected boolean
isDocumentRoot(java.lang.String tag)
Checks if a certain tag corresponds with the roottag.private boolean
isNewline(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.private boolean
isNewpage(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.private boolean
isNotBlank(java.lang.String text)
void
setBaseFont(BaseFont bf)
Sets the font that has to be used.void
setControlOpenClose(boolean controlOpenClose)
Sets the parameter that allows you to enable/disable the control over the Document.open() and Document.close() method.void
startElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)
This method gets called when a start tag is encountered.
-
-
-
Field Detail
-
document
protected DocListener document
This is the resulting document.
-
stack
protected java.util.Stack<Element> stack
This is aStack
of objects, waiting to be added to the document.
-
chapters
protected int chapters
Counts the number of chapters in this document.
-
currentChunk
protected Chunk currentChunk
This is the current chunk to which characters can be added.
-
ignore
protected boolean ignore
This is the current chunk to which characters can be added.
-
myTags
protected java.util.Map<java.lang.String,T extends XmlPeer> myTags
This hashmap contains all the custom keys and peers.
-
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.
-
bf
private BaseFont bf
-
-
Constructor Detail
-
SAXiTextHandler
public SAXiTextHandler(DocListener document)
- Parameters:
document
- the DocListener
-
SAXiTextHandler
public SAXiTextHandler(DocListener document, java.util.Map<java.lang.String,T> myTags, BaseFont bf)
- Parameters:
document
- the DocListenermyTags
- a Map of the tagsbf
- the base class for the supported fonts
-
SAXiTextHandler
public SAXiTextHandler(DocListener document, java.util.Map<java.lang.String,T> myTags)
- Parameters:
document
- the DocListenermyTags
- a Map of the 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 localName, java.lang.String name, org.xml.sax.Attributes attributes)
This method gets called when a start tag is encountered.- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.xml.sax.helpers.DefaultHandler
- Parameters:
uri
- the Uniform Resource IdentifierlocalName
- the local name (without prefix), or the empty string if Namespace processing is not being performed.name
- the name of the tag that is encounteredattributes
- the list of attributes
-
handleStartingTags
public 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
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length)
This method gets called when ignorable white space encountered.- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Overrides:
ignorableWhitespace
in 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:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in 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
- the base class for the supported fonts
-
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:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in 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
public void handleEndingTags(java.lang.String name)
This method deals with the starting tags.- Parameters:
name
- the name of the tag
-
isNotBlank
private boolean isNotBlank(java.lang.String text)
-
addImage
protected void addImage(Image img) throws java.util.EmptyStackException
- Throws:
java.util.EmptyStackException
-
isNewpage
private boolean isNewpage(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag
- a presumed tagname- Returns:
true
orfalse
-
isNewline
private boolean isNewline(java.lang.String tag)
Checks if a certain tag corresponds with the newpage-tag.- Parameters:
tag
- a presumed tagname- Returns:
true
orfalse
-
isDocumentRoot
protected boolean isDocumentRoot(java.lang.String tag)
Checks if a certain tag corresponds with the roottag.- Parameters:
tag
- a presumed tagname- Returns:
true
if tag equalsitext
,false
otherwise.
-
-