Package org.jfree.xml

Class Parser

All Implemented Interfaces:
Serializable, Cloneable, Configuration, ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public abstract class Parser extends FrontendDefaultHandler
The Parser handles the SAXEvents and forwards the event call to the currently active ElementDefinitionHandler. Contains methods to manage and configure the parsing process.

An initial report definition handler must be set before the parser can be used.

See Also:
  • Field Details

    • CONTENTBASE_KEY

      public static final String CONTENTBASE_KEY
      A key for the content base.
      See Also:
    • activeFactories

      private Stack activeFactories
      A stack for the active factories.
    • initialFactory

      private ElementDefinitionHandler initialFactory
      The initial factory.
    • parserHelperObjects

      private HashMap parserHelperObjects
      Storage for temporary objects and factories used during the parsing process.
  • Constructor Details

    • Parser

      public Parser()
      Creates a new parser.
  • Method Details

    • getComments

      public String[] getComments()
      Returns the currently collected comments.
      Returns:
      the comments.
    • pushFactory

      public void pushFactory(ElementDefinitionHandler factory)
      Pushes a handler onto the stack.
      Parameters:
      factory - the handler.
    • peekFactory

      public ElementDefinitionHandler peekFactory()
      Reads a handler off the stack without removing it.
      Returns:
      The handler.
    • popFactory

      public ElementDefinitionHandler popFactory()
      Pops a handler from the stack.
      Returns:
      The handler.
    • endDocument

      public void endDocument() throws SAXException
      Receive notification of the end of the document.

      By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of a document (such as finalising a tree or closing an output file).

      Specified by:
      endDocument in interface ContentHandler
      Overrides:
      endDocument in class DefaultHandler
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • startDocument

      public void startDocument() throws SAXException
      Receive notification of the beginning of the document.

      By default, do nothing. Application writers may override this method in a subclass to take specific actions at the beginning of a document (such as allocating the root node of a tree or creating an output file).

      Specified by:
      startDocument in interface ContentHandler
      Overrides:
      startDocument in class DefaultHandler
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • characters

      public void characters(char[] ch, int start, int length) throws SAXException
      Receive notification of character data inside an element.

      By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).

      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Parameters:
      ch - the characters.
      start - the start position in the character array.
      length - the number of characters to use from the character array.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • endElement

      public void endElement(String uri, String localName, String qName) throws SAXException
      Receive notification of the end of an element.

      By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Parameters:
      uri - the URI.
      localName - the element type name.
      qName - the name.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • startElement

      public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
      Receive notification of the start of an element.

      By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Parameters:
      uri - the URI.
      localName - the element type name.
      qName - the name.
      attributes - the specified or defaulted attributes.
      Throws:
      SAXException - Any SAX exception, possibly wrapping another exception.
      See Also:
    • setInitialFactory

      public void setInitialFactory(ElementDefinitionHandler factory)
      Sets the initial handler.
      Parameters:
      factory - the initial handler.
    • getInitialFactory

      public ElementDefinitionHandler getInitialFactory()
      Returns the initial handler.
      Returns:
      The initial handler.
    • setHelperObject

      public void setHelperObject(String key, Object value)
      Sets a helper object.
      Parameters:
      key - the key.
      value - the value.
    • getHelperObject

      public Object getHelperObject(String key)
      Returns a helper object.
      Parameters:
      key - the key.
      Returns:
      The object.
    • getInstance

      public abstract Parser getInstance()
      Returns a new instance of the parser.
      Returns:
      a new instance of the parser.
    • newInstance

      public final FrontendDefaultHandler newInstance()
      Returns a new instance of FrontendDefaultHandler.
      Specified by:
      newInstance in class FrontendDefaultHandler
      Returns:
      A new instance.
    • getResult

      public abstract Object getResult()
      Returns the parsed result object after the parsing is complete. Calling this function during the parsing is undefined and may result in an IllegalStateException.
      Specified by:
      getResult in class FrontendDefaultHandler
      Returns:
      the parsed result.