Top Description Fields Constructors Methods
uk.ac.ed.ph.snuggletex.upconversion

public final Class UpConversionUtilities

extends Object
Class Inheritance
Static Imports
uk.ac.ed.ph.snuggletex.SnuggleConstants.SNUGGLETEX_NAMESPACE, uk.ac.ed.ph.snuggletex.upconversion.UpConversionOptionDefinitions.OPTION_DEFINITIONS

Some static utility methods for the up-conversion process, including methods for extracting errors.
Author
David McKain
Since
1.1.0
Version
$Revision$

Field Summary

Modifier and TypeField and Description
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Element
appendSnuggleElement(Document document, Element parentElement, String localName)

public static void
appendUpConversionOptionsElement(Document
Document to append to
document
,
Element
Element that will be the parent of the resulting DOM fragment
containerElement
,
final UpConversionOptions
UpConversionOptions to write, may be null.
options
,
final boolean
if true, then default values for each option are written out when not explicitly specified or if UpConversionOptions is null.
applyDefaults
)

Writes out the given UpConversionOptions Object as a child Element of the given element, using a simple ad-hoc XML format.

public static UpConversionFailure
extractUpConversionFailure(final Element sFailElement)

Populates and returns an UpConversionFailure for the given Element, which is assumed to be a s:fail element having the appropriate structure.

public static List<UpConversionFailure>
extractUpConversionFailures(UnwrappedParallelMathMLDOM unwrappedDocument)

Extracts all of the s:fail elements within the given UnwrappedParallelMathMLDOM

private static void
extractUpConversionFailures(NodeList failureAnnotationContent, List<UpConversionFailure> resultBuilder)

public static List<UpConversionFailure>
extractUpConversionFailures(Document upConvertedDocument)

Searches the given DOM Document for all s:fail elements contained therein.

public static List<UpConversionFailure>
extractUpConversionFailures(Element startSearchElement)

Searches the given DOM Element and all its descendents for all s:fail elements contained therein.

public static String
getErrorMessage(UpConversionFailure failure)

Returns a full error message for the given UpConversionFailure, using the SnuggleTeX MessageFormatter class to do the hard work.

public static String
getErrorMessage(String upConversionErrorCodeAsString, Object... arguments)

Returns a full error message for the given UpConversionErrorCode String and arguments, using the SnuggleTeX MessageFormatter class to do the hard work.

public static boolean
isUpConversionFailureElement(Node node)

Checks to see whether the given DOM Node is an s:fail element.

private static void
walkDOM(Element searchElement, List<UpConversionFailure> resultBuilder)

Checks to see whether the given element is of the form:

<![CDATA[ <s:fail code="...
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

UPCONVERSION_OPTIONS_XML_LOCAL_NAMEback to summary
public static final String UPCONVERSION_OPTIONS_XML_LOCAL_NAME

Local name of XML container element when writing out options using appendUpConversionOptionsElement(Document, Element, UpConversionOptions, boolean)

Constructor Detail

UpConversionUtilitiesback to summary
public UpConversionUtilities()

Method Detail

appendSnuggleElementback to summary
private static Element appendSnuggleElement(Document document, Element parentElement, String localName)
appendUpConversionOptionsElementback to summary
public static void appendUpConversionOptionsElement(Document document, Element containerElement, final UpConversionOptions options, final boolean applyDefaults)

Writes out the given UpConversionOptions Object as a child Element of the given element, using a simple ad-hoc XML format.

This is used internally to pass Java-specified options to the stylesheets that perform the up-conversion process and may be useful in other situations as well.

Parameters
document:Document

Document to append to

containerElement:Element

Element that will be the parent of the resulting DOM fragment

options:UpConversionOptions

UpConversionOptions to write, may be null.

applyDefaults:boolean

if true, then default values for each option are written out when not explicitly specified or if UpConversionOptions is null.

Since
1.2.0
extractUpConversionFailureback to summary
public static UpConversionFailure extractUpConversionFailure(final Element sFailElement)

Populates and returns an UpConversionFailure for the given Element, which is assumed to be a s:fail element having the appropriate structure.

extractUpConversionFailuresback to summary
public static List<UpConversionFailure> extractUpConversionFailures(UnwrappedParallelMathMLDOM unwrappedDocument)

Extracts all of the s:fail elements within the given UnwrappedParallelMathMLDOM

Since
1.3.0
extractUpConversionFailuresback to summary
private static void extractUpConversionFailures(NodeList failureAnnotationContent, List<UpConversionFailure> resultBuilder)
extractUpConversionFailuresback to summary
public static List<UpConversionFailure> extractUpConversionFailures(Document upConvertedDocument)

Searches the given DOM Document for all s:fail elements contained therein.

extractUpConversionFailuresback to summary
public static List<UpConversionFailure> extractUpConversionFailures(Element startSearchElement)

Searches the given DOM Element and all its descendents for all s:fail elements contained therein.

getErrorMessageback to summary
public static String getErrorMessage(UpConversionFailure failure)

Returns a full error message for the given UpConversionFailure, using the SnuggleTeX MessageFormatter class to do the hard work.

getErrorMessageback to summary
public static String getErrorMessage(String upConversionErrorCodeAsString, Object... arguments)

Returns a full error message for the given UpConversionErrorCode String and arguments, using the SnuggleTeX MessageFormatter class to do the hard work.

isUpConversionFailureElementback to summary
public static boolean isUpConversionFailureElement(Node node)

Checks to see whether the given DOM Node is an s:fail element.

Since
1.3.0
walkDOMback to summary
private static void walkDOM(Element searchElement, List<UpConversionFailure> resultBuilder)

Checks to see whether the given element is of the form:

<![CDATA[ <s:fail code="..."> <s:arg>...</s:arg> ... <s:context>...</s:context> </s:fail> ]]>
<![CDATA[
<s:fail code="...">
  <s:arg>...</s:arg>
  ...
  <s:context>...</s:context>
</s:fail>
]]>
If so, creates an UpConversionFailure for this and adds to the result. If not, traverses downwards recursively.