Class FunctionBuilder
- java.lang.Object
-
- com.singularsys.extensions.mathml.builder.ApplyConstructor
-
- com.singularsys.extensions.mathml.builder.FunctionBuilder
-
- All Implemented Interfaces:
MathMLFragmentBuilder
public class FunctionBuilder extends ApplyConstructor implements MathMLFragmentBuilder
Builds xml-fragments for jep functions. Most functions are converted to use the <apply> tag with the first child a specific mathml function element. For example sin(x) becomes <apply><sin/><ci>x</ci></apply> The functions map translate jep function name to MathML element names, and elements can be added using putFunction. Some functions like lg (base-2 log) have special behaviour implement by individual MathMLFragmentBuilder, special functions can be added using putSpecialFunction. Unknown functions are handled by the unknownFunctionBuilder, by default this throws an exception, but it can be configured to produce <csymbol> or <fn> elements.- Author:
- Richard Morris
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FunctionBuilder.CSymbolBuilder
Class to build a CSymbol element, with the name of the jep-function.static class
FunctionBuilder.ErrorBuilder
Default builder for unknown function, throws a jep exception.static class
FunctionBuilder.FnBuilder
Class to build a Fn element, with the name of the jep-function.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.String>
functions
protected java.util.Map<java.lang.String,MathMLFragmentBuilder>
specialFunctions
protected MathMLFragmentBuilder
unknownFunctionBuilder
-
Constructor Summary
Constructors Constructor Description FunctionBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.w3c.dom.Element
build(Node n, org.w3c.dom.Document d, MathMLDocumentBuilder db)
Builds a Element for a jep Node.protected org.w3c.dom.Element
buildStandardFunction(Node node, org.w3c.dom.Document doc, MathMLDocumentBuilder db)
java.util.Map<java.lang.String,java.lang.String>
getFunctions()
Gets the map of standard functionsjava.util.Map<java.lang.String,MathMLFragmentBuilder>
getSpecialFunctions()
Gets the map of special functionsMathMLFragmentBuilder
getUnknownFunctionBuilder()
java.lang.String
putFunction(java.lang.String key, java.lang.String value)
Adds a standard functionMathMLFragmentBuilder
putSpecialFunction(java.lang.String key, MathMLFragmentBuilder value)
Adds a special functionvoid
setUnknownFunctionBuilder(MathMLFragmentBuilder unknownFunctionBuilder)
-
-
-
Field Detail
-
unknownFunctionBuilder
protected MathMLFragmentBuilder unknownFunctionBuilder
-
functions
protected java.util.Map<java.lang.String,java.lang.String> functions
-
specialFunctions
protected java.util.Map<java.lang.String,MathMLFragmentBuilder> specialFunctions
-
-
Method Detail
-
build
public org.w3c.dom.Element build(Node n, org.w3c.dom.Document d, MathMLDocumentBuilder db) throws JepException
Description copied from interface:MathMLFragmentBuilder
Builds a Element for a jep Node.- Specified by:
build
in interfaceMathMLFragmentBuilder
- Parameters:
n
- The jep sub expression.d
- The document to create the element in.db
- Used create elements and attributes and child nodes.- Returns:
- element representing the node
- Throws:
JepException
-
buildStandardFunction
protected org.w3c.dom.Element buildStandardFunction(Node node, org.w3c.dom.Document doc, MathMLDocumentBuilder db) throws JepException
- Throws:
JepException
-
putFunction
public java.lang.String putFunction(java.lang.String key, java.lang.String value)
Adds a standard function- Parameters:
key
- jep function namevalue
- MathML element name- Returns:
- old value for function or null
-
putSpecialFunction
public MathMLFragmentBuilder putSpecialFunction(java.lang.String key, MathMLFragmentBuilder value)
Adds a special function- Parameters:
key
- jep function namevalue
- builder to handle this type of function- Returns:
- old value for function or null
-
getFunctions
public java.util.Map<java.lang.String,java.lang.String> getFunctions()
Gets the map of standard functions- Returns:
- the map
-
getSpecialFunctions
public java.util.Map<java.lang.String,MathMLFragmentBuilder> getSpecialFunctions()
Gets the map of special functions- Returns:
- the map
-
getUnknownFunctionBuilder
public MathMLFragmentBuilder getUnknownFunctionBuilder()
-
setUnknownFunctionBuilder
public void setUnknownFunctionBuilder(MathMLFragmentBuilder unknownFunctionBuilder)
-
-