Class OMXMLReader

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.episteme.core.mathematics.loaders.openmath.io.OMXMLReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class OMXMLReader extends DefaultHandler
Constructs an OpenMath Object (OMObject) from the XML-input.

Version:
$Revision: 1.2 $
Author:
Manfred Riem (mriem@manorrock.org)
  • Field Details

    • sOMObjects

      protected static String[] sOMObjects
      Stores a static array with all the OpenMath element-names in use.

    • mOMObject

      protected OMObject mOMObject
      Stores the OMObject for this reader.

    • mElementStack

      protected Vector<OMObject> mElementStack
      Stores an vector with the last active element as the last in the vector. This vector grows/shrinks during parsing. It is used to easily keep track of the current parent object in the tree.

    • mInputSource

      protected InputSource mInputSource
      Stores the input-source.

    • keep

      protected boolean keep
      Stores if we should keep the outer OMOBJ.

    • foreign

      protected int foreign
      Stores if we are inside a foreign object section.

      Note: if we find another foreign inside the foreign we add to this number to make sure we can handle the endElements correctly.

  • Constructor Details

    • OMXMLReader

      public OMXMLReader()
      Constructor.

    • OMXMLReader

      public OMXMLReader(InputSource fInputSource)
      Constructor.

      Parameters:
      fInputSource - the InputSource to read from.
    • OMXMLReader

      public OMXMLReader(String fString)
      Constructor taking a String as the InputSource.

      Parameters:
      fString - the string to read from.
    • OMXMLReader

      public OMXMLReader(String newString, boolean newKeep)
      Constructor taking a String as the InputSource and a boolean indicating if we want to keep the outer OMOBJ.

      Parameters:
      newString - the input source
      newKeep - the boolean indicating if we keep the OMOBJ
  • Method Details

    • characters

      public void characters(char[] fCharacters, int fStart, int fLength) throws SAXException
      We've encountered a PCDATA section.

      Check if we have an enclosing OMInteger or OMString and set the data-members accordingly.

      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Parameters:
      fCharacters - the characters to handle.
      fStart - the start index into the characters array.
      fLength - the number of characters to read from the start.
      Throws:
      SAXException - when something is seriously wrong.
    • endDocument

      public void endDocument()
      End the document.

      Specified by:
      endDocument in interface ContentHandler
      Overrides:
      endDocument in class DefaultHandler
    • endElement

      public void endElement(String fNamespaceURI, String fLocalName, String fRawName) throws SAXException
      End a XML element.

      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Parameters:
      fNamespaceURI - the URI of the namespace.
      fLocalName - the locale name of the element.
      fRawName - the raw name of the element.
      Throws:
      SAXException - when something is seriously wrong.
    • ignorableWhitespace

      public void ignorableWhitespace(char[] tCharacter, int tStart, int tLength)
      Process ignorable whitespace.

      Specified by:
      ignorableWhitespace in interface ContentHandler
      Overrides:
      ignorableWhitespace in class DefaultHandler
      Parameters:
      tCharacter - the characters that can be ignored.
      tStart - the start index into the characters array.
      tLength - the number of characters to ignore.
    • processingInstruction

      public void processingInstruction(String fTarget, String fData)
      Process the processing instruction.

      Specified by:
      processingInstruction in interface ContentHandler
      Overrides:
      processingInstruction in class DefaultHandler
      Parameters:
      fTarget - the target of the processing instruction.
      fData - the data of the processing instruction.
    • readObject

      public OMObject readObject() throws IOException
      Read an OpenMath object.

      Returns:
      the OpenMath object to was read.
      Throws:
      IOException - when reading failed.
    • getObject

      public OMObject getObject()
      Get the OpenMath object.

      Note: if you didn't set this reader up from an input-source nor from a String, you will need this method to get the actual object at the end of reading. This method will only garantuee the proper result if you call it after 'endDocument' has be recognized.

      Returns:
      the parsed OMObject or null
    • setDocumentLocator

      public void setDocumentLocator(Locator fLocator)
      Set the document-locator.

      Specified by:
      setDocumentLocator in interface ContentHandler
      Overrides:
      setDocumentLocator in class DefaultHandler
      Parameters:
      fLocator - the document locator to use.
    • startDocument

      public void startDocument()
      Signals the start of the document.

      We reinitiliaze all the data-structures used during parsing, note that this parser is not reentrant and should only be used sequentially.

      Specified by:
      startDocument in interface ContentHandler
      Overrides:
      startDocument in class DefaultHandler
    • startElement

      public void startElement(String fNamespaceURI, String fLocalName, String fRawName, Attributes fAttributes) throws SAXException
      Start a XML element.

      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Parameters:
      fNamespaceURI - the namespace URI.
      fLocalName - the local name of the element.
      fRawName - the raw name of the element.
      fAttributes - the attributes of the element.
      Throws:
      SAXException - when something is seriously wrong.