use of uk.ac.ed.ph.snuggletex.SnuggleRuntimeException in project symja_android_library by axkr.
the class XMLUtilities method createSaxonTransformerFactory.
/**
* Explicitly creates a Saxon 9 {@link TransformerFactory}, as used by the up-conversion
* extensions.
*/
public static TransformerFactory createSaxonTransformerFactory() {
TransformerFactory transformerFactory;
try {
/* We call up SAXON explicitly without going through the usual factory path */
transformerFactory = (TransformerFactory) Class.forName(SAXON_TRANSFORMER_FACTORY_CLASS_NAME).newInstance();
} catch (Exception e) {
throw new SnuggleRuntimeException("Failed to explicitly instantiate Saxon " + SAXON_TRANSFORMER_FACTORY_CLASS_NAME + " class - check your ClassPath!", e);
}
/* Make sure we have DOM-based features */
requireFeature(transformerFactory, DOMSource.FEATURE);
requireFeature(transformerFactory, DOMResult.FEATURE);
/* Must have been OK! */
return transformerFactory;
}
use of uk.ac.ed.ph.snuggletex.SnuggleRuntimeException in project symja_android_library by axkr.
the class XMLUtilities method serializeNodeChildren.
/**
* Serializes the <tt>children</tt> of given {@link Node} to a well-formed external parsed entity.
*
* <p>(This uses a little XSLT stylesheet to help, hence the requirement for a {@link
* StylesheetManager}).
*
* @param stylesheetManager used to help compile and cache stylesheets used in this process.
* @param node DOM Node to serialize.
* @param serializationOptions XML serialization options
*/
public static String serializeNodeChildren(StylesheetManager stylesheetManager, final Node node, final SerializationSpecifier serializationOptions) {
StringWriter resultWriter = new StringWriter();
/* This process consists of an XSLT 1.0 transform to extract the child Nodes, plus
* a further optional XSLT 2.0 transform to map character references to named entities.
*/
try {
Transformer serializer = stylesheetManager.getSerializer(Globals.EXTRACT_CHILD_NODES_XSL_RESOURCE_NAME, serializationOptions);
serializer.transform(new DOMSource(node), new StreamResult(resultWriter));
} catch (Exception e) {
throw new SnuggleRuntimeException("Could not serialize DOM", e);
}
return resultWriter.toString();
}
Aggregations