Search in sources :

Example 11 with SnuggleRuntimeException

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;
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with SnuggleRuntimeException

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();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException) SnuggleRuntimeException(uk.ac.ed.ph.snuggletex.SnuggleRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

SnuggleRuntimeException (uk.ac.ed.ph.snuggletex.SnuggleRuntimeException)12 Transformer (javax.xml.transform.Transformer)6 DOMSource (javax.xml.transform.dom.DOMSource)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 TransformerException (javax.xml.transform.TransformerException)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerFactory (javax.xml.transform.TransformerFactory)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Document (org.w3c.dom.Document)3 StringWriter (java.io.StringWriter)2 DOMResult (javax.xml.transform.dom.DOMResult)2 StreamSource (javax.xml.transform.stream.StreamSource)2 SerializationMethod (uk.ac.ed.ph.snuggletex.SerializationMethod)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Source (javax.xml.transform.Source)1 Templates (javax.xml.transform.Templates)1