Class MathMLContentParser
java.lang.Object
com.singularsys.extensions.mathml.MathMLContentParser
Main class for the Content-MathML parser.
The standard single argument constructor builds a parser with a default
set of parsing rules. Other rules can be added using the various
put(String, TagHandler)
methods.
Various parse methods are available for parsing complete documents or fragments of mathml code.
To enable mathml documents containing entities like π to be processed
the setPrependMathMLEntities(boolean) method can be called, if true a simple doctype
declaration defining the entities is inserted at the start of the document.
- Author:
- Richard Morris
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumBehaviour for unknown tags when parsing withparseAll(Reader, Behaviour). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AnnotationHandlerprotected ApplyHandlerprotected ConstantHandlerprotected DeclareHandlerprotected IdentifierHandlerprotected final Jepprotected MathTagHandlerprotected static final Stringprotected static final Stringprotected StringString with a simple DOCTYPE declaration defining MathML entities.protected MatrixHandlerprotected final MathMLDocumentHandlerprotected OperatorHandlerprotected final OperatorTableIprotected SemanticHandlerprotected SpecialNodeHandlerprotected SAXParserFactoryprotected StandardFunctionHandlerprotected UnSupportedHandler -
Constructor Summary
ConstructorsConstructorDescriptionMathMLContentParser(Jep jep) Creates a standard MathML parser.MathMLContentParser(Jep jep, SAXParserFactory spf, MathMLDocumentHandler mdh) Creates a MathML parser with a given parser factory and MathMLDocumentHandler. -
Method Summary
Modifier and TypeMethodDescriptionReturns a string with a simple DOCTYPE declaration with defined entities.booleanparseAll(Reader reader, MathMLContentParser.Behaviour behaviour) Parse a complete xml document containing one or more math tags, with one or more child elements.parseAll(Reader reader, TagHandler unknownHandler) Parse a complete xml document containing one or more math tags, with one or more child elements.parseAll(InputSource is, TagHandler unknownHandler) Parse a document containing one or more math tags, with one or more child elements.parseAllMath(Reader reader) Parse a document containing one or more math tags, with one or more child elements.parseAllMath(String xml) Parse a document containing one or more math tags, with one or more child elements.Parse a document containing one or more math tags, with one or more child elements.parseFragment(Reader reader) Parse a document containing a mathml fragment, not enclosed in a math tag.Parse a document containing a mathml fragment, not enclosed in a math tag.parseSingle(Reader reader) Parse a document containing a single <math> element with a single child node.parseSingle(String xml) Parse a document containing a single <math> element with a single child node.Parse a document containing a single <math> element with a single child node.put(String key, TagHandler handler) Adds the handler for a given elementputConstantElement(String key, String jepName) Add a handler for elements representing a constant.Adds a handler for a MathML Entity representing a constant.putFunction(String key, String jepName) Adds a handler for a Jep function, uses the standardFunctionHandlerputOperator(String key, Operator op) Adds a handler for a Jep operator, uses the operatorHandlerputSpecialNode(String key, int nchildren) Adds a handler for special nodes like <sep/>, <logbase> and >degree< which only have meaning inside other elements.Remove the handler associated with a give mathml element.removeEntity(String key) voidsetPrependMathMLEntities(boolean prependMathMLEntities) Whether to prepend a simple deceleration to the start of the document.void
-
Field Details
-
spf
-
mdh
-
jep
-
ot
-
mathElementHandler
-
unsupportedHandler
-
constantHandler
-
identifierHandler
-
operatorHandler
-
applyHandler
-
standardFunctionHandler
-
specialNodeHandler
-
matrixHandler
-
declareHandler
-
semanticHandler
-
annotationHandler
-
mathMLEntitiesString
String with a simple DOCTYPE declaration defining MathML entities. -
MathMLEntitiesStart
- See Also:
-
MathMLEntitiesEnd
- See Also:
-
mathMLEntities
-
-
Constructor Details
-
MathMLContentParser
Creates a MathML parser with a given parser factory and MathMLDocumentHandler. -
MathMLContentParser
Creates a standard MathML parser. Uses the default SAXParserFactory, standard MathMLDocumentHandler and default methods for MathML Content elements. Not all elements are supported.- Parameters:
jep- the Jep instance
-
-
Method Details
-
parseSingle
public Node parseSingle(InputSource is) throws ParserConfigurationException, SAXException, IOException Parse a document containing a single <math> element with a single child node.- Parameters:
is-- Returns:
- node representing the child node
- Throws:
ParserConfigurationExceptionSAXException- if document does not contain exactly one math tag, or any non mathml dataIOException
-
parseSingle
public Node parseSingle(Reader reader) throws ParserConfigurationException, SAXException, IOException Parse a document containing a single <math> element with a single child node.- Parameters:
reader-- Returns:
- node representing the child node
- Throws:
ParserConfigurationExceptionSAXException- if document does not contain exactly one math tag, or any non mathml dataIOException
-
parseSingle
Parse a document containing a single <math> element with a single child node.- Parameters:
xml- string containing mathml- Returns:
- node representing the child node
- Throws:
ParserConfigurationExceptionSAXException- if document does not contain exactly one math tag, or any non mathml dataIOException
-
parseFragment
public Node parseFragment(InputSource is) throws ParserConfigurationException, SAXException, IOException Parse a document containing a mathml fragment, not enclosed in a math tag.- Parameters:
is-- Returns:
- node representing the child node
- Throws:
ParserConfigurationExceptionSAXException- If the document contains non mathml data.IOException
-
parseFragment
public Node parseFragment(Reader reader) throws ParserConfigurationException, SAXException, IOException Parse a document containing a mathml fragment, not enclosed in a math tag.- Parameters:
reader-- Returns:
- node representing the child node
- Throws:
ParserConfigurationExceptionSAXException- If the document contains non mathml data.IOException
-
parseAllMath
public List<Node> parseAllMath(InputSource is) throws ParserConfigurationException, SAXException, IOException Parse a document containing one or more math tags, with one or more child elements. Surrounding xml elements are silently ignored.- Parameters:
is-- Returns:
- a list of all nodes one for each child of the math elements.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseAllMath
public List<Node> parseAllMath(Reader reader) throws ParserConfigurationException, SAXException, IOException Parse a document containing one or more math tags, with one or more child elements. Surrounding xml elements are silently ignored.- Parameters:
reader-- Returns:
- a list of all nodes for all child of the math elements.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseAllMath
public List<Node> parseAllMath(String xml) throws ParserConfigurationException, SAXException, IOException Parse a document containing one or more math tags, with one or more child elements. Surrounding xml elements are silently ignored.- Parameters:
xml- String with MathML.- Returns:
- a list of all nodes for all child of the math elements.
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseAll
public Object parseAll(InputSource is, TagHandler unknownHandler) throws ParserConfigurationException, SAXException, IOException Parse a document containing one or more math tags, with one or more child elements. Surrounding xml elements are silently ignored.- Parameters:
is-unknownHandler- a handler for unknown elements- Returns:
- the result of parsing
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseAll
public Object parseAll(Reader reader, TagHandler unknownHandler) throws ParserConfigurationException, SAXException, IOException Parse a complete xml document containing one or more math tags, with one or more child elements.- Parameters:
reader- the Reader to read fromunknownHandler- a handler for unknown elements- Returns:
- the result of parsing, actual type depends on the unknownHandler
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
parseAll
public Object parseAll(Reader reader, MathMLContentParser.Behaviour behaviour) throws ParserConfigurationException, SAXException, IOException Parse a complete xml document containing one or more math tags, with one or more child elements.- Parameters:
reader- the Reader to read frombehaviour-- Returns:
- the result of parsing, actual type depends on the unknownHandler
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
put
Adds the handler for a given element- Parameters:
key- the name of the elementhandler- the handler used for this type of element- Returns:
- handler
-
putOperator
Adds a handler for a Jep operator, uses the operatorHandler- Parameters:
key- the name of the mathml elementop- the jep operator- Returns:
- the operatorHandler
-
putFunction
Adds a handler for a Jep function, uses the standardFunctionHandler- Parameters:
key- name of the MathML elementjepName- name of the function used in jep- Returns:
- standardFunctionHandler
-
putConstantElement
Add a handler for elements representing a constant.- Parameters:
key- the name of the mathml elementjepName- name of the variable used in jep- Returns:
- constantHandler
-
putSpecialNode
Adds a handler for special nodes like <sep/>, <logbase> and >degree< which only have meaning inside other elements. These are handled by theSpecialNodeHandler- Parameters:
key- tag namenchildren- number of children- Returns:
- the handler
-
remove
Remove the handler associated with a give mathml element.- Parameters:
key- name of element- Returns:
- the handler
-
getMathMLEntitiesString
Returns a string with a simple DOCTYPE declaration with defined entities.- Returns:
- string containing DOCTYPE deceleration
-
isPrependMathMLEntities
public boolean isPrependMathMLEntities() -
setPrependMathMLEntities
public void setPrependMathMLEntities(boolean prependMathMLEntities) Whether to prepend a simple deceleration to the start of the document. This can be used to parse documents containing entities like ⅇ without having to include the full MathML DTD.- Parameters:
prependMathMLEntities-- See Also:
-
putEntity
Adds a handler for a MathML Entity representing a constant. Entity deceleration will be added to MathMLEntitiesString which will be added to the start of the document if preprendMathMLEntities is true.- Parameters:
entityName- name of the entity, e.g. "ExponentialE"unicode- unicode character for entity, "\\u2147"jepVariableName- name of variable used in jep, "e"- Returns:
- the constantHandler
- See Also:
-
removeEntity
-
getSAXParserFactory
-
setSAXParserFactory
-