Example usage for javax.xml.transform TransformerFactory getClass

List of usage examples for javax.xml.transform TransformerFactory getClass

Introduction

In this page you can find the example usage for javax.xml.transform TransformerFactory getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.ode.bpel.compiler.v1.xpath10.jaxp.JaxpXPath10ExpressionCompilerBPEL20.java

public JaxpXPath10ExpressionCompilerBPEL20(String bpelNS) {
    super(bpelNS);

    TransformerFactory trsf = TransformerFactory.newInstance();
    __log.debug("JAXP compiler: TransformerFactory impl = " + trsf.getClass());
    XslTransformHandler.getInstance().setTransformerFactory(trsf);

    _qnDoXslTransform = new QName(bpelNS, "doXslTransform");
}

From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpXPath10ExpressionRuntime.java

public void initialize(Map properties) throws ConfigurationException {
    TransformerFactory trsf = TransformerFactory.newInstance();
    __log.debug("JAXP runtime: TransformerFactory impl = " + trsf.getClass());
    XslTransformHandler.getInstance().setTransformerFactory(trsf);
}

From source file:org.eclipse.smila.search.servlet.SMILASearchServlet.java

/**
 * create XSL transformer for stylesheet.
 *
 * @param xslDoc/*from w  ww. j  av  a 2  s.com*/
 *          XSL DOM document
 * @return XSL transformer
 * @throws ServletException
 *           error.
 */
protected Transformer getXSLTransformer(final Document xslDoc) throws ServletException {
    final TransformerFactory tFactory = TransformerFactory.newInstance();
    if (tFactory.getFeature(DOMSource.FEATURE) && tFactory.getFeature(StreamResult.FEATURE)) {

        final DOMSource xslDomSource = new DOMSource(xslDoc);

        try {
            return tFactory.newTransformer(xslDomSource);
        } catch (final TransformerConfigurationException e) {
            throw new ServletException("error while creating the transformer", e);
        }
    } else {
        throw new ServletException("the transformer [" + tFactory.getClass().getName()
                + "] doesn't support the used DOMSource or StreamResult");
    }
}

From source file:org.fao.geonet.api.site.SiteInformation.java

/**
 * Compute information about the current system.
 *///from  www  .  ja v a  2 s .co m
private void loadSystemInfo() {
    systemProperties.put("java.version", properties.getProperty("java.version"));
    systemProperties.put("java.vm.name", properties.getProperty("java.vm.name"));
    systemProperties.put("java.vm.vendor", properties.getProperty("java.vm.vendor"));

    systemProperties.put("os.name", properties.getProperty("os.name"));
    systemProperties.put("os.arch", properties.getProperty("os.arch"));

    try {
        TransformerFactory transFact = TransformerFactoryFactory.getTransformerFactory();
        systemProperties.put("xslt.factory", transFact.getClass().getName());
    } catch (Exception e) {
        systemProperties.put("xslt.factory", "Exception:" + e.getMessage());
    }

    long freeMem = Runtime.getRuntime().freeMemory() / 1024;
    long totMem = Runtime.getRuntime().totalMemory() / 1024;
    systemProperties.put("mem.free", "" + freeMem);
    systemProperties.put("mem.total", "" + totMem);

}

From source file:org.fao.geonet.utils.Xml.java

/**
 * Clears the cache used in the stylesheet transformer factory. This will only work for the GeoNetwork Caching
 * stylesheet transformer factory. This is a no-op for other transformer factories.
 *///from   w  w  w .  jav  a  2s  .  c  o m
public static void clearTransformerFactoryStylesheetCache() {
    TransformerFactory transFact = TransformerFactory.newInstance();
    try {
        Class<?> class1 = transFact.getClass();
        Method cacheMethod = class1.getDeclaredMethod("clearCache");
        cacheMethod.invoke(transFact, new Object[0]);
    } catch (Exception e) {
        Log.error(Log.ENGINE, "Failed to find/invoke clearCache method - continuing (" + e.getMessage() + ")");
    }

}

From source file:org.fireflow.pdl.fpdl.io.FPDLDeserializer.java

/**
 * // w w w .j  a va2  s.c  om
 */
public FPDLDeserializer() {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();

    if (JDK_TRANSFORMER_CLASS.equals(transformerFactory.getClass().getName())) {
        useJDKTransformerFactory = true;
    }
}

From source file:org.fireflow.pdl.fpdl.io.FPDLSerializer.java

/**
 * xmloutString//from w ww  . j a  v a  2s  .  c  o  m
 * @param workflowProcess
 * @param out
 * @return
 * @throws IOException
 * @throws SerializerException
 * @throws InvalidModelException
 */
public String serialize(WorkflowProcess workflowProcess, OutputStream out)
        throws IOException, SerializerException, InvalidModelException {
    try {
        Document document = serializeToDOM(workflowProcess);

        //??
        Element root = document.getDocumentElement();
        String displayname = root.getAttribute(DISPLAY_NAME);
        //============

        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        if (JDK_TRANSFORMER_CLASS.equals(transformerFactory.getClass().getName())) {
            useJDKTransformerFactory = true;
        }

        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, charset);
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");

        transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, CDATA_SECTION_ELEMENT_LIST);

        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        transformer.transform(new DOMSource(document), new StreamResult(out));

        out.flush();

        return charset;
    } catch (TransformerConfigurationException e) {
        throw new SerializerException(e);
    } catch (TransformerException e) {
        throw new SerializerException(e);
    } finally {

    }

}

From source file:org.fireflow.pdl.fpdl20.io.FPDLSerializer.java

public void serialize(WorkflowProcess workflowProcess, OutputStream out)
        throws IOException, SerializerException, InvalidModelException {
    try {/*from  w w w  . j av  a  2  s  . c o m*/
        Document document = serializeToDOM(workflowProcess);

        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        if (JDK_TRANSFORMER_CLASS.equals(transformerFactory.getClass().getName())) {
            useJDKTransformerFactory = true;
        }

        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, charset);
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");

        transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, CDATA_SECTION_ELEMENT_LIST);

        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        transformer.transform(new DOMSource(document), new StreamResult(out));
        out.flush();
    } catch (TransformerConfigurationException e) {
        throw new SerializerException(e);
    } catch (TransformerException e) {
        throw new SerializerException(e);
    } finally {

    }

}

From source file:org.mycore.common.content.transformer.MCRXSLTransformer.java

public synchronized void setTransformerFactory(String factoryClass)
        throws TransformerFactoryConfigurationError {
    TransformerFactory transformerFactory = Optional.ofNullable(factoryClass)
            .map(c -> TransformerFactory.newInstance(c, null)).orElseGet(TransformerFactory::newInstance);
    LOGGER.info("Transformerfactory: " + transformerFactory.getClass().getName());
    transformerFactory.setURIResolver(URI_RESOLVER);
    transformerFactory.setErrorListener(MCRErrorListener.getInstance());
    if (transformerFactory.getFeature(SAXSource.FEATURE) && transformerFactory.getFeature(SAXResult.FEATURE)) {
        this.tFactory = (SAXTransformerFactory) transformerFactory;
    } else {//from   w w  w  .  j a v  a 2  s  .  c om
        throw new MCRConfigurationException("Transformer Factory " + transformerFactory.getClass().getName()
                + " does not implement SAXTransformerFactory");
    }
}

From source file:org.pentaho.di.job.entries.xslt.JobEntryXSLT.java

private boolean processOneXMLFile(String xmlfilename, String xslfilename, String outputfilename, Result result,
        Job parentJob) {/*from  w  ww.  j av a  2  s .c o m*/
    boolean retval = false;
    FileObject xmlfile = null;
    FileObject xslfile = null;
    FileObject outputfile = null;

    try {
        xmlfile = KettleVFS.getFileObject(xmlfilename, this);
        xslfile = KettleVFS.getFileObject(xslfilename, this);
        outputfile = KettleVFS.getFileObject(outputfilename, this);

        if (xmlfile.exists() && xslfile.exists()) {
            if (outputfile.exists() && iffileexists == 2) {
                // Output file exists
                // User want to fail
                logError(BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists1.Label") + outputfilename
                        + BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists2.Label"));
                return retval;

            } else if (outputfile.exists() && iffileexists == 1) {
                // Do nothing
                if (log.isDebug()) {
                    logDebug(BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists1.Label") + outputfilename
                            + BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists2.Label"));
                }
                retval = true;
                return retval;

            } else {
                if (outputfile.exists() && iffileexists == 0) {
                    // the output file exists and user want to create new one with unique name
                    // Format Date

                    // Try to clean filename (without wildcard)
                    String wildcard = outputfilename.substring(outputfilename.length() - 4,
                            outputfilename.length());
                    if (wildcard.substring(0, 1).equals(".")) {
                        // Find wildcard
                        outputfilename = outputfilename.substring(0, outputfilename.length() - 4) + "_"
                                + StringUtil.getFormattedDateTimeNow(true) + wildcard;
                    } else {
                        // did not find wildcard
                        outputfilename = outputfilename + "_" + StringUtil.getFormattedDateTimeNow(true);
                    }
                    if (log.isDebug()) {
                        logDebug(BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists1.Label")
                                + outputfilename
                                + BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileExists2.Label"));
                        logDebug(BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileNameChange1.Label")
                                + outputfilename
                                + BaseMessages.getString(PKG, "JobEntryXSLT.OuputFileNameChange2.Label"));
                    }
                }

                // Create transformer factory
                TransformerFactory factory = TransformerFactory.newInstance();

                if (xsltfactory.equals(FACTORY_SAXON)) {
                    // Set the TransformerFactory to the SAXON implementation.
                    factory = new net.sf.saxon.TransformerFactoryImpl();
                }

                if (log.isDetailed()) {
                    log.logDetailed(BaseMessages.getString(PKG, "JobEntryXSL.Log.TransformerFactoryInfos"),
                            BaseMessages.getString(PKG, "JobEntryXSL.Log.TransformerFactory",
                                    factory.getClass().getName()));
                }

                InputStream xslInputStream = KettleVFS.getInputStream(xslfile);
                InputStream xmlInputStream = KettleVFS.getInputStream(xmlfile);
                OutputStream os = null;
                try {
                    // Use the factory to create a template containing the xsl file
                    Templates template = factory.newTemplates(new StreamSource(xslInputStream));

                    // Use the template to create a transformer
                    Transformer xformer = template.newTransformer();

                    if (log.isDetailed()) {
                        log.logDetailed(BaseMessages.getString(PKG, "JobEntryXSL.Log.TransformerClassInfos"),
                                BaseMessages.getString(PKG, "JobEntryXSL.Log.TransformerClass",
                                        xformer.getClass().getName()));
                    }

                    // Do we need to set output properties?
                    if (setOutputProperties) {
                        xformer.setOutputProperties(outputProperties);
                    }

                    // Do we need to pass parameters?
                    if (useParameters) {
                        for (int i = 0; i < nrParams; i++) {
                            xformer.setParameter(nameOfParams[i], valueOfParams[i]);
                        }
                    }

                    // Prepare the input and output files
                    Source source = new StreamSource(xmlInputStream);
                    os = KettleVFS.getOutputStream(outputfile, false);
                    StreamResult resultat = new StreamResult(os);

                    // Apply the xsl file to the source file and write the result to the output file
                    xformer.transform(source, resultat);

                    if (isAddFileToResult()) {
                        // Add output filename to output files
                        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL,
                                KettleVFS.getFileObject(outputfilename, this), parentJob.getJobname(),
                                toString());
                        result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
                    }

                    // Everything is OK
                    retval = true;
                } finally {
                    try {
                        xslInputStream.close();
                    } catch (IOException ignored) {
                        // ignore IO Exception on close
                    }
                    try {
                        xmlInputStream.close();
                    } catch (IOException ignored) {
                        // ignore IO Exception on close
                    }
                    try {
                        if (os != null) {
                            os.close();
                        }
                    } catch (IOException ignored) {
                        // ignore IO Exception on close
                    }
                }
            }
        } else {

            if (!xmlfile.exists()) {
                logError(BaseMessages.getString(PKG, "JobEntryXSLT.FileDoesNotExist1.Label") + xmlfilename
                        + BaseMessages.getString(PKG, "JobEntryXSLT.FileDoesNotExist2.Label"));
            }
            if (!xslfile.exists()) {
                logError(BaseMessages.getString(PKG, "JobEntryXSLT.FileDoesNotExist1.Label") + xmlfilename
                        + BaseMessages.getString(PKG, "JobEntryXSLT.FileDoesNotExist2.Label"));
            }
        }
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "JobEntryXSLT.ErrorXLST.Label")
                + BaseMessages.getString(PKG, "JobEntryXSLT.ErrorXLSTXML1.Label") + xmlfilename
                + BaseMessages.getString(PKG, "JobEntryXSLT.ErrorXLSTXML2.Label")
                + BaseMessages.getString(PKG, "JobEntryXSLT.ErrorXLSTXSL1.Label") + xslfilename
                + BaseMessages.getString(PKG, "JobEntryXSLT.ErrorXLSTXSL2.Label") + e.getMessage());
    } finally {
        try {
            if (xmlfile != null) {
                xmlfile.close();
            }

            if (xslfile != null) {
                xslfile.close();
            }
            if (outputfile != null) {
                outputfile.close();
            }
        } catch (IOException e) {
            logError("Unable to close file", e);
        }
    }

    return retval;
}