Search in sources :

Example 6 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project zm-mailbox by Zimbra.

the class XsdCleaner method getTranformer.

public static Transformer getTranformer() {
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        return transformer;
    } catch (TransformerFactoryConfigurationError | TransformerException e) {
        LOG.error("XsdCleaner:Problem getting XML Transformer", e);
    }
    return null;
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) TransformerException(javax.xml.transform.TransformerException)

Example 7 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project jabref by JabRef.

the class MSBibExportFormat method performExport.

@Override
public void performExport(final BibDatabaseContext databaseContext, final String file, final Charset encoding, List<BibEntry> entries) throws SaveException {
    Objects.requireNonNull(databaseContext);
    Objects.requireNonNull(entries);
    if (entries.isEmpty()) {
        return;
    }
    // forcing to use UTF8 output format for some problems with xml export in other encodings
    SaveSession session = new FileSaveSession(StandardCharsets.UTF_8, false);
    MSBibDatabase msBibDatabase = new MSBibDatabase(databaseContext.getDatabase(), entries);
    try (VerifyingWriter ps = session.getWriter()) {
        try {
            DOMSource source = new DOMSource(msBibDatabase.getDomForExport());
            StreamResult result = new StreamResult(ps);
            Transformer trans = TransformerFactory.newInstance().newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            trans.transform(source, result);
        } catch (TransformerException | IllegalArgumentException | TransformerFactoryConfigurationError e) {
            throw new Error(e);
        }
        finalizeSaveSession(session, Paths.get(file));
    } catch (IOException ex) {
        throw new SaveException(ex);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) IOException(java.io.IOException) MSBibDatabase(org.jabref.logic.msbib.MSBibDatabase) TransformerException(javax.xml.transform.TransformerException)

Example 8 with TransformerFactoryConfigurationError

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

the class SimpleXmlSerializationManager method buildSerializationData.

@Override
public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) throws SerializationException {
    if (resource == null) {
        return null;
    }
    Map<String, Object> content = resource.getProperties();
    if (content == null || content.isEmpty()) {
        return null;
    }
    try {
        SAXTransformerFactory f = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        StreamResult sr = new StreamResult(result);
        TransformerHandler handler = f.newTransformerHandler();
        Transformer t = handler.getTransformer();
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        handler.setResult(sr);
        handler.startDocument();
        startElement(handler, TAG_RESOURCE);
        Set<Entry<String, Object>> entrySet = new TreeMap<>(content).entrySet();
        for (Map.Entry<String, Object> property : entrySet) {
            Object value = property.getValue();
            if (value instanceof String) {
                String tagName = property.getKey();
                String tagValue = (String) value;
                AttributesImpl attributes = new AttributesImpl();
                attributes.addAttribute("", ATT_PROPERTY_NAME, ATT_PROPERTY_NAME, null, tagName);
                handler.startElement("", TAG_PROPERTY, TAG_PROPERTY, attributes);
                handler.characters(tagValue.toCharArray(), 0, tagValue.length());
                handler.endElement("", TAG_PROPERTY, TAG_PROPERTY);
            } else {
                // TODO multi-valued properties, other primitives
                System.err.println("Can't yet handle property " + property.getKey() + " of type " + value.getClass());
            }
        }
        endElement(handler, TAG_RESOURCE);
        handler.endDocument();
        // TODO - also add the serialization type
        return new SerializationData(resource.getPath(), CONTENT_XML, result.toByteArray(), null);
    } catch (TransformerConfigurationException | TransformerFactoryConfigurationError | SAXException e) {
        // TODO proper exception handling
        throw new RuntimeException(e);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SerializationData(org.apache.sling.ide.serialization.SerializationData) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 9 with TransformerFactoryConfigurationError

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

the class AbstractFeatureConverterWfs20 method readGml.

protected Object readGml(String xml) {
    LOGGER.debug("readGml() input XML: {}", xml);
    //Add namespace into XML for processing
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    try {
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (ParserConfigurationException e) {
        LOGGER.debug("Unable to configure features on document builder.", e);
    }
    DocumentBuilder dBuilder = null;
    Document doc = null;
    Object gml = null;
    InputStream xmlIs = null;
    //Check if GML 3.2.1 namespace exist on XML chunk
    try {
        dBuilder = dbFactory.newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        doc = dBuilder.parse(is);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        LOGGER.debug(XML_PARSE_FAILURE);
    }
    if (null != doc) {
        String[] namePrefix = doc.getDocumentElement().getNodeName().split(":");
        String prefix = "";
        if (namePrefix.length < 2) {
            LOGGER.debug("Incoming XML has no GML prefix");
        } else {
            prefix = ":" + namePrefix[0];
        }
        String xmlNs = doc.getDocumentElement().getAttribute("xmlns" + prefix);
        if (xmlNs.equals(Wfs20Constants.GML_3_2_NAMESPACE)) {
            LOGGER.debug("Namespace already exists.");
        } else {
            doc.createElementNS(Wfs20Constants.GML_3_2_NAMESPACE, doc.getDocumentElement().getNodeName());
        }
        //Convert DOM to InputStream
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Source xmlSource = new DOMSource(doc);
        Result outputTarget = new StreamResult(outputStream);
        try {
            TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
        } catch (TransformerException | TransformerFactoryConfigurationError e) {
            LOGGER.debug(CREATE_TRANSFORMER_FAILURE);
        }
        xmlIs = new ByteArrayInputStream(outputStream.toByteArray());
        //Parse XML into a Geometry object
        Configuration configurationG = new org.geotools.gml3.v3_2.GMLConfiguration();
        Parser parser = new org.geotools.xml.Parser(configurationG);
        parser.setStrict(false);
        parser.setValidating(false);
        parser.setFailOnValidationError(false);
        parser.setForceParserDelegate(false);
        try {
            gml = parser.parse(xmlIs);
        } catch (IOException | SAXException | ParserConfigurationException e) {
            LOGGER.debug("{} {}", GML_FAILURE, xml);
        }
    }
    return gml;
}
Also used : InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Configuration(org.geotools.xml.Configuration) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXException(org.xml.sax.SAXException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Parser(org.geotools.xml.Parser) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 10 with TransformerFactoryConfigurationError

use of javax.xml.transform.TransformerFactoryConfigurationError in project che by eclipse.

the class History method save.

public synchronized void save() {
    IPath stateLocation = JavaPlugin.getDefault().getStateLocation().append(fFileName);
    File file = stateLocation.toFile();
    OutputStream out = null;
    try {
        out = new FileOutputStream(file);
        save(out);
    } catch (IOException e) {
        JavaPlugin.log(e);
    } catch (CoreException e) {
        JavaPlugin.log(e);
    } catch (TransformerFactoryConfigurationError e) {
        // The XML library can be misconficgured (e.g. via
        // -Djava.endorsed.dirs=C:\notExisting\xerces-2_7_1)
        JavaPlugin.log(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            JavaPlugin.log(e);
        }
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

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