Search in sources :

Example 11 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project midpoint by Evolveum.

the class SchemaDistMojo method serializeXml.

private void serializeXml(Document dom, Path filePath, File workDir, File outDir) throws MojoFailureException, MojoExecutionException {
    Path fileRelPath = workDir.toPath().relativize(filePath);
    File outFile = new File(outDir, fileRelPath.toString());
    initializeOutDir(outFile.getParentFile());
    try {
        DOMUtil.serializeDOMToFile(dom, outFile);
    } catch (TransformerFactoryConfigurationError | TransformerException e) {
        throw new MojoExecutionException("Error serializing modified file " + fileRelPath + " to XML: " + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TransformerException(javax.xml.transform.TransformerException)

Example 12 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateXslFile.

private void generateXslFile(String resource, String xslfile, String cssfile, String folder) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        org.w3c.dom.Document document = builder.parse(new File(resource));
        org.w3c.dom.Element rootElement = document.getDocumentElement();
        //$NON-NLS-1$
        NodeList list = rootElement.getElementsByTagName("style");
        org.w3c.dom.Element element = (org.w3c.dom.Element) list.item(0);
        String value = element.getChildNodes().item(0).getNodeValue();
        if (value != null) {
            if (folder != null) {
                //$NON-NLS-1$
                CSSParserUtils.createCssFile(value, folder + File.separator + "default.css");
            }
            if (cssfile != null && !cssfile.equals("")) {
                //$NON-NLS-1$
                if (folder != null) {
                    String cssName = new File(cssfile).getName();
                    if (cssName.equalsIgnoreCase("default.css")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        cssName = "User_" + cssName;
                    }
                    File file = new File(folder + File.separator + cssName);
                    if (!file.exists()) {
                        file.createNewFile();
                    }
                    FileCopyUtils.copy(cssfile, folder + File.separator + cssName);
                }
                CSSRuleList ruleList = CSSParserUtils.parserCSSSelectors(null, cssfile);
                if (ruleList == null) {
                    return;
                } else {
                    String newValue = CSSParserUtils.generateCssStyle(cssfile, ruleList, value);
                    element.getChildNodes().item(0).setNodeValue(newValue);
                    // replace the old value and generate a new xsl file
                    DOMSource ds = new DOMSource(document);
                    StreamResult sr = new StreamResult(new File(xslfile));
                    TransformerFactory.newInstance().newTransformer().transform(ds, sr);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        ExceptionHandler.process(e);
    } catch (SAXException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (TransformerConfigurationException e) {
        ExceptionHandler.process(e);
    } catch (TransformerException e) {
        ExceptionHandler.process(e);
    } catch (TransformerFactoryConfigurationError e) {
        ExceptionHandler.process(e);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NodeList(org.w3c.dom.NodeList) Element(org.dom4j.Element) IOException(java.io.IOException) CSSRuleList(org.w3c.dom.css.CSSRuleList) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 13 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project geode by apache.

the class ConfigurationResponse method describeConfig.

public String describeConfig() {
    StringBuffer sb = new StringBuffer();
    if (requestedConfiguration.isEmpty()) {
        sb.append("Received an empty shared configuration");
    } else {
        Set<Entry<String, Configuration>> entries = requestedConfiguration.entrySet();
        Iterator<Entry<String, Configuration>> iter = entries.iterator();
        while (iter.hasNext()) {
            Entry<String, Configuration> entry = iter.next();
            String configType = entry.getKey();
            Configuration config = entry.getValue();
            if (config != null) {
                sb.append("\n***************************************************************");
                sb.append("\nConfiguration for  '" + configType + "'");
                sb.append("\n\nJar files to deployed");
                Set<String> jarNames = config.getJarNames();
                Iterator<String> jarIter = jarNames.iterator();
                int jarCounter = 0;
                while (jarIter.hasNext()) {
                    sb.append("\n" + ++jarCounter + "." + jarIter.next());
                }
                try {
                    String cacheXmlContent = config.getCacheXmlContent();
                    if (StringUtils.isNotBlank(cacheXmlContent)) {
                        sb.append("\n" + XmlUtils.prettyXml(cacheXmlContent));
                    }
                } catch (IOException | TransformerFactoryConfigurationError | TransformerException | SAXException | ParserConfigurationException e) {
                    throw new InternalGemFireError(e);
                }
            }
        }
    }
    return sb.toString();
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 14 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project apps-android-commons by commons-app.

the class Utils method getStringFromDOM.

public static String getStringFromDOM(Node dom) {
    Transformer transformer = null;
    try {
        transformer = TransformerFactory.newInstance().newTransformer();
    } catch (TransformerConfigurationException | TransformerFactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    StringWriter outputStream = new StringWriter();
    DOMSource domSource = new DOMSource(dom);
    StreamResult strResult = new StreamResult(outputStream);
    try {
        transformer.transform(domSource, strResult);
    } catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return outputStream.toString();
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) TransformerException(javax.xml.transform.TransformerException)

Example 15 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project ddf by codice.

the class XPathHelper method print.

/**
     * @param xmlDeclaration
     * @param indent
     * @return
     */
public String print(String xmlDeclaration, String indent) {
    Transformer serializer;
    try {
        serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, xmlDeclaration);
        serializer.setOutputProperty(OutputKeys.INDENT, indent);
        serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_CONTENT_HANDLER, org.apache.xml.serializer.ToXMLStream.class.getName());
        StringWriter writer = new StringWriter();
        serializer.transform(new DOMSource(document), new StreamResult(writer));
        return writer.toString();
    } catch (TransformerFactoryConfigurationError | TransformerException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return null;
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) TransformerException(javax.xml.transform.TransformerException)

Aggregations

TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)15 TransformerException (javax.xml.transform.TransformerException)11 StreamResult (javax.xml.transform.stream.StreamResult)9 Transformer (javax.xml.transform.Transformer)8 IOException (java.io.IOException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 DOMSource (javax.xml.transform.dom.DOMSource)6 File (java.io.File)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 FileOutputStream (java.io.FileOutputStream)3 Locale (java.util.Locale)3 Entry (java.util.Map.Entry)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 TransformerFactory (javax.xml.transform.TransformerFactory)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2 ResourceBundle (java.util.ResourceBundle)2 StreamSource (javax.xml.transform.stream.StreamSource)2