Example usage for javax.xml.transform TransformerConfigurationException getMessage

List of usage examples for javax.xml.transform TransformerConfigurationException getMessage

Introduction

In this page you can find the example usage for javax.xml.transform TransformerConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.oprisnik.semdroid.SemdroidServlet.java

public String getResults(SemdroidReport results, InputStream transformationStyle) {
    try {/*from  w  ww .  j  a v  a  2  s  .c  o  m*/
        Document doc = XmlUtils.createDocument();
        Element rootElement = doc.createElement("AnalysisResults");
        doc.appendChild(rootElement);
        XmlUtils.addResults(results, doc, rootElement);

        StringWriter writer = new StringWriter();

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        StreamSource stylesource = new StreamSource(transformationStyle);
        Transformer transformer = transformerFactory.newTransformer(stylesource);
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
        return writer.toString();

    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
        log.warning("Exception: " + pce.getMessage());
        log.throwing(this.getClass().getName(), "getResults", pce);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
        log.warning("Exception: " + e.getMessage());
        log.throwing(this.getClass().getName(), "getResults", e);
    } catch (TransformerException e) {
        e.printStackTrace();
        log.warning("Exception: " + e.getMessage());
        log.throwing(this.getClass().getName(), "getResults", e);
    }
    return null;
}

From source file:eu.eidas.auth.engine.SAMLEngineUtils.java

/**
*
* @param xmlObj//from   w w w  . j  a v a2s. c  o  m
* @return a string containing the xml representation of the entityDescriptor
*/
public static String serializeObject(XMLObject xmlObj) {
    StringWriter stringWriter = new StringWriter();
    String stringRepresentation = "";
    try {
        DocumentBuilder builder;
        DocumentBuilderFactory factory = DocumentBuilderFactoryUtil.getSecureDocumentBuilderFactory();

        builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Marshaller out = Configuration.getMarshallerFactory().getMarshaller(xmlObj);
        out.marshall(xmlObj, document);

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        StreamResult streamResult = new StreamResult(stringWriter);
        DOMSource source = new DOMSource(document);
        transformer.transform(source, streamResult);
    } catch (ParserConfigurationException pce) {
        LOG.info("ERROR : parser error", pce.getMessage());
        LOG.debug("ERROR : parser error", pce);
    } catch (TransformerConfigurationException tce) {
        LOG.info("ERROR : transformer configuration error", tce.getMessage());
        LOG.debug("ERROR : transformer configuration error", tce);
    } catch (TransformerException te) {
        LOG.info("ERROR : transformer error", te.getMessage());
        LOG.debug("ERROR : transformer error", te);
    } catch (MarshallingException me) {
        LOG.info("ERROR : marshalling error", me.getMessage());
        LOG.debug("ERROR : marshalling error", me);
    } finally {
        try {
            stringWriter.close();
            stringRepresentation = stringWriter.toString();
        } catch (IOException ioe) {
            LOG.warn("ERROR when closing the marshalling stream {}", ioe);
        }
    }
    return stringRepresentation;
}

From source file:io.onedecision.engine.decisions.web.DecisionDmnModelController.java

protected TransformUtil getTransformUtil() {
    // if (transformUtil == null) {
    transformUtil = new TransformUtil();
    try {/*from w  ww .  ja  v  a  2  s  . c  o  m*/
        transformUtil.setXsltResources("/static/xslt/dmn2html.xslt");
    } catch (TransformerConfigurationException e) {
        LOGGER.error(e.getMessage(), e);
        throw new DecisionException("Unable to render decision model", e);
    }
    // }
    return transformUtil;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static StringBuffer printDom(Node node, boolean indent, boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    TransformerFactory transfac = TransformerFactory.newInstance();
    Transformer trans;/*from www.  j  a  va 2 s .co m*/
    try {
        trans = transfac.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new SystemException("Error in XML configuration: " + e.getMessage(), e);
    }
    trans.setOutputProperty(OutputKeys.INDENT, (indent ? "yes" : "no"));
    trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); // XALAN-specific
    trans.setParameter(OutputKeys.ENCODING, "utf-8");
    // Note: serialized XML does not contain xml declaration
    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, (omitXmlDeclaration ? "yes" : "no"));

    DOMSource source = new DOMSource(node);
    try {
        trans.transform(source, new StreamResult(writer));
    } catch (TransformerException e) {
        throw new SystemException("Error in XML transformation: " + e.getMessage(), e);
    }

    return writer.getBuffer();
}

From source file:eu.europa.ec.markt.tlmanager.core.signature.SignatureManager.java

/**
 * Initialises the <code>InMemoryDocument</code> from a provided <code>Document</code>.
 */// w  w w. j av  a2 s  .co m
public void initInMemoryDocument(org.w3c.dom.Document document) {
    if (document == null) {
        LOG.log(Level.SEVERE, ">>> Document is null!");
    }
    try {
        ByteArrayOutputStream outputDoc = new ByteArrayOutputStream();
        Result output = new StreamResult(outputDoc);
        Transformer transformer = Util.createPrettyTransformer(3);
        Source source = new DOMSource(document);
        transformer.transform(source, output);
        this.document = new InMemoryDocument(outputDoc.toByteArray());

        outputDoc.close();
    } catch (TransformerConfigurationException tce) {
        LOG.log(Level.SEVERE, ">>>" + tce.getMessage());
    } catch (TransformerFactoryConfigurationError tfce) {
        LOG.log(Level.SEVERE, ">>>" + tfce.getMessage());
    } catch (TransformerException te) {
        LOG.log(Level.SEVERE, ">>>" + te.getMessage());
    } catch (IOException ioe) {
        LOG.log(Level.SEVERE, ">>>" + ioe.getMessage());
    }
}

From source file:com.collabnet.ccf.core.transformer.XsltProcessor.java

/**
 * Tries to load the XSLT from the file defined in the properties (will also
 * try to find the file on the class path if it can).
 * /*from w  ww .  ja  v  a 2 s.com*/
 * @throws ValidationException
 *             if the XSLT file is not defined in the properties, the file
 *             cannot be found or there was an error parsing it
 */
private Transformer loadXSLT(File xsltFile, Element element) {
    if (xsltFile == null) {
        String cause = "xsltFile property not set";
        log.error(cause);
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_TRANSFORMER_FILE);
        throw new CCFRuntimeException(cause);
    }
    Transformer transform = null;

    // load the transform
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        transform = factory.newTransformer(new StreamSource(xsltFile));

        log.debug("Loaded XSLT [" + xsltFile + "] successfully");
    } catch (TransformerConfigurationException e) {
        String cause = "Failed to load XSLT: [" + xsltFile + " ]" + e.getMessage();
        log.error(cause, e);
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_TRANSFORMER_FILE);
        throw new CCFRuntimeException(cause, e);
    }
    return transform;
}

From source file:net.sf.joost.trax.TransformerFactoryImpl.java

/**
 * Allows the user to set specific attributes on the underlying
 * implementation. An attribute in this context is defined to
 * be an option that the implementation provides.
 * @param name Name of the attribute (key)
 * @param value Value of the attribute./*  ww  w. j a v  a  2  s  .c o m*/
 * @throws IllegalArgumentException
 */
public void setAttribute(String name, Object value) throws IllegalArgumentException {

    if (KEY_TH_RESOLVER.equals(name)) {
        thResolver = (TransformerHandlerResolver) value;
    } else if (KEY_OUTPUT_URI_RESOLVER.equals(name)) {
        outputUriResolver = (OutputURIResolver) value;
    } else if (MESSAGE_EMITTER_CLASS.equals(name)) {
        // object is of type string, so use reflection
        if (value instanceof String) {
            try {
                msgEmitter = buildMessageEmitter((String) value);
            } catch (TransformerConfigurationException e) {
                if (log != null)
                    log.fatal(e.getMessage(), e);
                throw new IllegalArgumentException(e.getMessage());
            }
        } else if (value instanceof StxEmitter) { // already instantiated
            msgEmitter = (StxEmitter) value;
        } else {
            throw new IllegalArgumentException(
                    "Emitter is of wrong type," + "should be either a String or a StxEmitter");
        }
    } else if (KEY_XSLT_FACTORY.equals(name)) {
        System.setProperty(KEY_XSLT_FACTORY, (String) value);
    } else if (ALLOW_EXTERNAL_FUNCTIONS.equals(name)) {
        this.allowExternalFunctions = ((Boolean) value).booleanValue();
    } else if (DEBUG_FEATURE.equals(name)) {
        this.debugmode = ((Boolean) value).booleanValue();
    } else {
        if (log != null)
            log.warn("Feature not supported: " + name);
        throw new IllegalArgumentException("Feature not supported: " + name);
    }
}

From source file:com.servicelibre.jxsl.scenario.XslScenario.java

private Templates getCompiledXsl() {
    try {//www .j a v a  2s  . c  o  m
        return getTransformerFactory().newTemplates(new StreamSource(getXslPath()));
    } catch (TransformerConfigurationException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:com.servicelibre.jxsl.scenario.XslScenario.java

/**
 * Returns the default transformer//from www  . j av a  2  s  .c  om
 * 
 * 
 * @return
 */
public Transformer getTransformer() {

    if (this.transformer == null) {

        if (getXslPath() == null || getXslPath().trim().isEmpty()) {
            logger.error("xslPath is NULL or empty.  Cannot create Transformer.");
            return null;
        }

        try {

            this.transformer = getCompiledXsl().newTransformer();

            // Saxon specific
            if ((this.transformer instanceof net.sf.saxon.Controller)) {
                Controller saxonController = (Controller) this.transformer;
                saxonController.setOutputURIResolver(this.multipleOutputs);

                logger.info("Transformer used by this scenario: {}",
                        saxonController.getConfiguration().getProductTitle());
            } else {
                logger.info("Transformer used by this scenario: {}", this.transformer.getClass().getName());
            }

        } catch (TransformerConfigurationException e) {
            logger.error(e.getMessage(), e);
        }

    }

    return this.transformer;
}