Class Parser


  • @ThreadSafe
    public final class Parser
    extends java.lang.Object
    A JAXP compatible approach to MathML Parsing.
    Version:
    $Revision: 5a7becda9147 $
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Parser()
      Default constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      javax.xml.parsers.DocumentBuilder getDocumentBuilder()
      Retrieve a DocumentBuilder suitable for MathML parsing.
      static Parser getInstance()
      Retrieve the singleton Parser instance.
      static Parser getParser()
      Deprecated.
      use getInstance() instead.
      org.w3c.dom.Node parse​(javax.xml.transform.Source source)
      Extract the top Node from a given Source.
      org.w3c.dom.Document parseStreamSource​(javax.xml.transform.stream.StreamSource streamSource)
      Parse a StreamSource and return its Document.
      org.w3c.dom.Document parseStreamSourceAsOdf​(javax.xml.transform.stream.StreamSource streamSource)
      Parse a given StreamSource which represents an ODF document.
      org.w3c.dom.Document parseStreamSourceAsXml​(javax.xml.transform.stream.StreamSource streamSource)
      Parse a given StreamSource which represents an XML document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Parser

        protected Parser()
        Default constructor.
    • Method Detail

      • getInstance

        public static Parser getInstance()
        Retrieve the singleton Parser instance.
        Returns:
        a Parser object.
      • parseStreamSource

        public org.w3c.dom.Document parseStreamSource​(javax.xml.transform.stream.StreamSource streamSource)
                                               throws org.xml.sax.SAXException,
                                                      java.io.IOException
        Parse a StreamSource and return its Document.

        This method will auto-detect ODF or XML format and load an appropriate parser.

        Parameters:
        streamSource - A StreamSource.
        Returns:
        A DOM Document representation for this source.
        Throws:
        org.xml.sax.SAXException - if a parse error occurred.
        java.io.IOException - if an I/O error occurred.
      • parseStreamSourceAsOdf

        public org.w3c.dom.Document parseStreamSourceAsOdf​(javax.xml.transform.stream.StreamSource streamSource)
                                                    throws java.io.IOException,
                                                           org.xml.sax.SAXException
        Parse a given StreamSource which represents an ODF document.
        Parameters:
        streamSource - StreamSource to parse.
        Returns:
        the Document contained within.
        Throws:
        org.xml.sax.SAXException - if a parse error occurred.
        java.io.IOException - if an I/O error occurred.
      • parseStreamSourceAsXml

        public org.w3c.dom.Document parseStreamSourceAsXml​(javax.xml.transform.stream.StreamSource streamSource)
                                                    throws org.xml.sax.SAXException,
                                                           java.io.IOException
        Parse a given StreamSource which represents an XML document.
        Parameters:
        streamSource - StreamSource to parse.
        Returns:
        the Document contained within.
        Throws:
        org.xml.sax.SAXException - if a parse error occurred.
        java.io.IOException - if an I/O error occurred.
      • getDocumentBuilder

        public javax.xml.parsers.DocumentBuilder getDocumentBuilder()
        Retrieve a DocumentBuilder suitable for MathML parsing.

        Please note:

        • There is one instance of the builder per thread.
        • The builder instance is not thread safe, so it may not be passed among threads.
        • Multiple Threads may call getDocumentBuilder concurrently
        Returns:
        a DocumentBuilder
      • parse

        public org.w3c.dom.Node parse​(javax.xml.transform.Source source)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException
        Extract the top Node from a given Source.
        Parameters:
        source - the Source to use. Currently supported are DOMSource , StreamSource
        Returns:
        the top NODE.
        Throws:
        org.xml.sax.SAXException - if a parse error occurred.
        java.io.IOException - if an I/O error occurred.