Class SAXiTextHandler<T extends XmlPeer>

java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.lowagie.text.xml.SAXiTextHandler<T>
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
SAXmyHandler, SAXmyHtmlHandler

public class SAXiTextHandler<T extends XmlPeer> extends 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 Details

    • document

      protected DocListener document
      This is the resulting document.
    • stack

      protected Stack<Element> stack
      This is a Stack 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 Map<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 Details

    • SAXiTextHandler

      public SAXiTextHandler(DocListener document)
      Parameters:
      document - the DocListener
    • SAXiTextHandler

      public SAXiTextHandler(DocListener document, Map<String,T> myTags, BaseFont bf)
      Parameters:
      document - the DocListener
      myTags - a Map of the tags
      bf - the base class for the supported fonts
    • SAXiTextHandler

      public SAXiTextHandler(DocListener document, Map<String,T> myTags)
      Parameters:
      document - the DocListener
      myTags - a Map of the 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

      public void startElement(String uri, String localName, String name, Attributes attributes)
      This method gets called when a start tag is encountered.
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Parameters:
      uri - the Uniform Resource Identifier
      localName - the local name (without prefix), or the empty string if Namespace processing is not being performed.
      name - the name of the tag that is encountered
      attributes - the list of attributes
    • handleStartingTags

      public void handleStartingTags(String name, Properties attributes)
      This method deals with the starting tags.
      Parameters:
      name - the name of the tag
      attributes - 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 interface ContentHandler
      Overrides:
      ignorableWhitespace in class DefaultHandler
      Parameters:
      ch - an array of characters
      start - the start position in the array
      length - 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 interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Parameters:
      ch - an array of characters
      start - the start position in the array
      length - 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(String uri, String lname, String name)
      This method gets called when an end tag is encountered.
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Parameters:
      uri - the Uniform Resource Identifier
      lname - 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(String name)
      This method deals with the starting tags.
      Parameters:
      name - the name of the tag
    • isNotBlank

      private boolean isNotBlank(String text)
    • addImage

      protected void addImage(Image img) throws EmptyStackException
      Throws:
      EmptyStackException
    • isNewpage

      private boolean isNewpage(String tag)
      Checks if a certain tag corresponds with the newpage-tag.
      Parameters:
      tag - a presumed tagname
      Returns:
      true or false
    • isNewline

      private boolean isNewline(String tag)
      Checks if a certain tag corresponds with the newpage-tag.
      Parameters:
      tag - a presumed tagname
      Returns:
      true or false
    • isDocumentRoot

      protected boolean isDocumentRoot(String tag)
      Checks if a certain tag corresponds with the roottag.
      Parameters:
      tag - a presumed tagname
      Returns:
      true if tag equals itext ,false otherwise.