webeq3.util
Class EquationUtilities

java.lang.Object
  extended by webeq3.util.EquationUtilities

public class EquationUtilities
extends java.lang.Object

This utility class provides all the MathML markup generation methods for the equation instance.


Field Summary
static int CONTENT
           
static int ENTITY_NAMES
           
static int ENTITY_OR_NUMERICAL
           
static int ESCAPE_ALL
           
static int ESCAPE_NONE
           
static int ESCAPE_SPECIAL
           
static int MIXED_MARKUP
           
static int NORMALIZED_PRESENTATION
           
static int NUMERICAL_REFERENCES
           
static int PACKED
           
static int PACKED_AND_ESCAPED
           
static int PACKED_AND_WRAPPED
           
static int PASS_THROUGH
           
static int PRESENTATION
           
static int PRETTY_PRINT
           
static int REGULAR_PRESENTATION
           
static int UNICODE
           
 
Constructor Summary
EquationUtilities()
           
 
Method Summary
static java.lang.String getContentMathML(webeq3.app.Equation eq)
          Returns the formatted content MathML markup for the specified equation.
static java.lang.String getDoubleEscapedContentMathML(webeq3.app.Equation eq)
          Returns the double escaped packed content MathML markup for the specified equation.
static java.lang.String getDoubleEscapedMathML(webeq3.app.Equation eq)
          Returns the double escaped packed MathML markup for the specified equation in which unicode characters have been double escaped, in the format of "&" + EntityName + ";".
static java.lang.String getFormattedMathML(webeq3.app.Equation eq, int markupType, int formatLevel, boolean namespaceAttr, java.lang.String namespacePrefix, int characterType, boolean selectionOnly)
           
static java.lang.String getFormattedMathML(webeq3.app.Equation eq, int markupType, int formatLevel, boolean namespaceAttr, java.lang.String namespacePrefix, int characterType, int escapePref, boolean selectionOnly, boolean outputCursor, boolean filterChars)
          Returns the MathML for the specified equation with the specified format.
static java.lang.String getMathML(webeq3.app.Equation eq)
          Returns the formatted presentation MathML markup for the specified equation.
static java.lang.String getPackedContentMathML(webeq3.app.Equation eq)
          Returns the unformatted content MathML markup for the specified equation.
static java.lang.String getPackedMathML(webeq3.app.Equation eq)
          Returns the unformatted MathML markup for the specified equation.
static java.lang.String getURLDecodedString(java.lang.String mml)
          In complicated web apps, such as Blackboard deploys, the double escaping problem is severe.
static java.lang.String getURLDecodedString(java.lang.String mml, int chopOff)
          Returns the URL-decoded version of the string passed in, with the specified number of characters chopped off at the end.
static java.lang.String getURLEncodedContentMathML(webeq3.app.Equation eq)
          Returns the URL-encoded packed content MathML markup for the specified equation.
static java.lang.String getURLEncodedMathML(webeq3.app.Equation eq)
          Returns the URL-encoded packed MathML markup for the specified equation in which necessary characters have been escaped in order for the string to be safely transmitted as CGI data.
static boolean isEquationEmpty(webeq3.app.Equation eq)
          Returns true if the specified equation meets any of the following conditions: 1.
static boolean isEquationSelectable(webeq3.app.Equation eq)
          Returns true if the specified equation is selectable.
static boolean stringEqualsChar(java.lang.String s, char c)
           
static java.lang.String unescapeMathML(java.lang.String escapedMML)
          Returns an unescaped version of the specified MathML.
static java.lang.String unescapeSpecialChars(java.lang.String mml)
          Returns the modified MathML which unescapes some special characters, such as <, >, ', and &.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT

public static final int CONTENT
See Also:
Constant Field Values

ENTITY_NAMES

public static final int ENTITY_NAMES
See Also:
Constant Field Values

ENTITY_OR_NUMERICAL

public static final int ENTITY_OR_NUMERICAL
See Also:
Constant Field Values

ESCAPE_ALL

public static final int ESCAPE_ALL
See Also:
Constant Field Values

ESCAPE_NONE

public static final int ESCAPE_NONE
See Also:
Constant Field Values

ESCAPE_SPECIAL

public static final int ESCAPE_SPECIAL
See Also:
Constant Field Values

MIXED_MARKUP

public static final int MIXED_MARKUP
See Also:
Constant Field Values

NORMALIZED_PRESENTATION

public static final int NORMALIZED_PRESENTATION
See Also:
Constant Field Values

NUMERICAL_REFERENCES

public static final int NUMERICAL_REFERENCES
See Also:
Constant Field Values

PACKED

public static final int PACKED
See Also:
Constant Field Values

PACKED_AND_ESCAPED

public static final int PACKED_AND_ESCAPED
See Also:
Constant Field Values

PACKED_AND_WRAPPED

public static final int PACKED_AND_WRAPPED
See Also:
Constant Field Values

PASS_THROUGH

public static final int PASS_THROUGH
See Also:
Constant Field Values

PRESENTATION

public static final int PRESENTATION
See Also:
Constant Field Values

PRETTY_PRINT

public static final int PRETTY_PRINT
See Also:
Constant Field Values

REGULAR_PRESENTATION

public static final int REGULAR_PRESENTATION
See Also:
Constant Field Values

UNICODE

public static final int UNICODE
See Also:
Constant Field Values
Constructor Detail

EquationUtilities

public EquationUtilities()
Method Detail

getContentMathML

public static java.lang.String getContentMathML(webeq3.app.Equation eq)
Returns the formatted content MathML markup for the specified equation. If content markup generation fails, this will return the string "couldn't convert to content markup".

Parameters:
eq - the equation
Returns:
formatted content MathML for the current equation

getDoubleEscapedContentMathML

public static java.lang.String getDoubleEscapedContentMathML(webeq3.app.Equation eq)
Returns the double escaped packed content MathML markup for the specified equation. If content markup generation fails, this will return the string "couldn't convert to content markup".

Parameters:
eq - the equation
Returns:
the properly double escaped content MathML for the specified equation
See Also:
getDoubleEscapedMathML(Equation)

getDoubleEscapedMathML

public static java.lang.String getDoubleEscapedMathML(webeq3.app.Equation eq)
Returns the double escaped packed MathML markup for the specified equation in which unicode characters have been double escaped, in the format of "&" + EntityName + ";".

Parameters:
eq - the equation
Returns:
the properly double escaped MathML for the specified equation

getFormattedMathML

public static java.lang.String getFormattedMathML(webeq3.app.Equation eq,
                                                  int markupType,
                                                  int formatLevel,
                                                  boolean namespaceAttr,
                                                  java.lang.String namespacePrefix,
                                                  int characterType,
                                                  boolean selectionOnly)

getFormattedMathML

public static java.lang.String getFormattedMathML(webeq3.app.Equation eq,
                                                  int markupType,
                                                  int formatLevel,
                                                  boolean namespaceAttr,
                                                  java.lang.String namespacePrefix,
                                                  int characterType,
                                                  int escapePref,
                                                  boolean selectionOnly,
                                                  boolean outputCursor,
                                                  boolean filterChars)
Returns the MathML for the specified equation with the specified format.

Parameters:
eq - the equation
markupType - an integer value indicating the type of markup. The valid values are: 0 mixed content/presentation markup 1 presentation markup format 2 content markup format (if possible) 3 normalized presentation format (extra mrows removed)
formatLevel - an integer value indicating the format level. The valid values are: 0 pretty printed (on multiple lines and indented to make reading easier) 1 packed (all on one line, no indenting or extra spaces) 2 packed and escaped (all on one line, all <>& shown as escaped characters) 3 packed and wrapped (no extra white space, but returns added at nearest tag at 80 columns)
namespaceAttr - a boolean value indicating whether or not a namespace prefix should be added to each tag.
namespacePrefix - the namespace prefix prepending each tag, if namespaceAttr is true.
characterType - an integer value indicating the character type. The valid values are: 0 Special characters are shown as entity names if possible. 1 Special characters are shown in the format &#xXXXX; where X is a hexadecimal value. 2 Special characters are shown in UTF-8 format. This is the binary representation of the characters and may look strange in many text-processing programs.
escapePref - an integer value indicating how to escape entity names. The valid values are: 0 Do not escape entity names 1 Escape special entity names, such as '&', '<' and '>' 2 Escape all entity names
selectionOnly - an boolean value indicating whether we only generate MathML for the selected portion of the equation
outputCursor - an boolean value indicating whether we need to output cursor location and selection range
filterChars - an boolean value indicating whether we need to filter certain characters
Returns:
the MathML for the specified equation with the specified format

getMathML

public static java.lang.String getMathML(webeq3.app.Equation eq)
Returns the formatted presentation MathML markup for the specified equation.

Parameters:
eq - the equation
Returns:
formatted presentation MathML for the specified equation

getPackedContentMathML

public static java.lang.String getPackedContentMathML(webeq3.app.Equation eq)
Returns the unformatted content MathML markup for the specified equation. If content markup generation fails, this will return the string "couldn't convert to content markup".

Parameters:
eq - the equation
Returns:
unformatted content MathML for the specified equation

getPackedMathML

public static java.lang.String getPackedMathML(webeq3.app.Equation eq)
Returns the unformatted MathML markup for the specified equation. The markup is stripped of extra white space including linefeeds and indentation, and is much more compact than formatted MathML.

Parameters:
eq - the equation
Returns:
unformatted MathML for the specified equation

getURLDecodedString

public static java.lang.String getURLDecodedString(java.lang.String mml)
In complicated web apps, such as Blackboard deploys, the double escaping problem is severe. For these customers, we've added methods to directly pass in URL-encoded MathML. This method provides a centralized method for URL-decoded strings.

Parameters:
mml - the URL-encoded string
Returns:
the URL-decoded string

getURLDecodedString

public static java.lang.String getURLDecodedString(java.lang.String mml,
                                                   int chopOff)
Returns the URL-decoded version of the string passed in, with the specified number of characters chopped off at the end.

Parameters:
mml - the URL-encoded string
chopOff - number of characters to chop off at the end
Returns:
the URL-decoded string

getURLEncodedContentMathML

public static java.lang.String getURLEncodedContentMathML(webeq3.app.Equation eq)
Returns the URL-encoded packed content MathML markup for the specified equation. If content markup generation fails, this will return the string "couldn't convert to content markup".

Parameters:
eq - the equation
Returns:
the URL-encoded content MathML for the current equation
See Also:
getURLEncodedMathML(Equation)

getURLEncodedMathML

public static java.lang.String getURLEncodedMathML(webeq3.app.Equation eq)
Returns the URL-encoded packed MathML markup for the specified equation in which necessary characters have been escaped in order for the string to be safely transmitted as CGI data. The following characters will be encoded:
" " -> %20 "+" -> %2B "&" -> %26 "<" -> %3C "=" -> %3D ">" -> %3E "?" -> %3F

Parameters:
eq - the equation
Returns:
the URL-encoded MathML for the specified equation

isEquationEmpty

public static boolean isEquationEmpty(webeq3.app.Equation eq)
Returns true if the specified equation meets any of the following conditions: 1. It has zero children. 2. It has only one child which is a MRow with zero children. 3. It has only one child which is a MRow containing a single empty template.

Parameters:
eq - the equation
Returns:
true if the specified equation is considered empty

isEquationSelectable

public static boolean isEquationSelectable(webeq3.app.Equation eq)
Returns true if the specified equation is selectable.

Parameters:
eq - the equation
Returns:
true if the specified equation is selectable

stringEqualsChar

public static boolean stringEqualsChar(java.lang.String s,
                                       char c)

unescapeMathML

public static java.lang.String unescapeMathML(java.lang.String escapedMML)
Returns an unescaped version of the specified MathML. In some combinations OS/Browser (Mac OS9, Netscape) applet parameters values are read escaped (<.. -> <math><...), so we use this method to correct it.

Parameters:
escapedMML - the MathML which contains escaped entity names
Returns:
unescaped version of the specified MathML

unescapeSpecialChars

public static java.lang.String unescapeSpecialChars(java.lang.String mml)
Returns the modified MathML which unescapes some special characters, such as <, >, ', and &.

Parameters:
mml - the original MathML string
Returns:
the modified MathML which unescapes some special characters

Copyright (c) 2015 Design Science
All rights reserved