Search in sources :

Example 76 with Result

use of javax.xml.transform.Result in project cayenne by apache.

the class DefaultUpgradeService method saveDocument.

protected void saveDocument(UpgradeUnit upgradeUnit) {
    try {
        Source input = new DOMSource(upgradeUnit.getDocument());
        Result output = new StreamResult(Util.toFile(upgradeUnit.getResource().getURL()));
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(input, output);
    } catch (Exception ex) {
        logger.warn("Can't save the document: ", ex);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXException(org.xml.sax.SAXException) ConfigurationException(org.apache.cayenne.ConfigurationException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 77 with Result

use of javax.xml.transform.Result in project cxf by apache.

the class JAXBUtils method generateJaxbSchemas.

public static List<DOMResult> generateJaxbSchemas(JAXBContext context, final Map<String, DOMResult> builtIns) throws IOException {
    final List<DOMResult> results = new ArrayList<>();
    context.generateSchema(new SchemaOutputResolver() {

        @Override
        public Result createOutput(String ns, String file) throws IOException {
            DOMResult result = new DOMResult();
            if (builtIns.containsKey(ns)) {
                DOMResult dr = builtIns.get(ns);
                result.setSystemId(dr.getSystemId());
                results.add(dr);
                return result;
            }
            result.setSystemId(file);
            results.add(result);
            return result;
        }
    });
    return results;
}
Also used : SchemaOutputResolver(javax.xml.bind.SchemaOutputResolver) DOMResult(javax.xml.transform.dom.DOMResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) DOMResult(javax.xml.transform.dom.DOMResult)

Example 78 with Result

use of javax.xml.transform.Result in project linuxtools by eclipse.

the class AbstractDataAdapter method toString.

@Override
public String toString() {
    String ret = null;
    Source source = new DOMSource(getDocument());
    StringWriter stw = new StringWriter();
    Result result = new StreamResult(stw);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer xformer;
    try {
        xformer = factory.newTransformer();
        // $NON-NLS-1$ //$NON-NLS-2$
        xformer.setOutputProperty("indent", "yes");
        xformer.transform(source, result);
        ret = stw.toString();
    } catch (TransformerException e) {
        e.printStackTrace();
    }
    return ret;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 79 with Result

use of javax.xml.transform.Result in project knime-core by knime.

the class NodeDescriptionConverter method buildDocumentationFor.

/**
 * Gets the {@link RepositoryManager} and transforms all NodeDescriptions
 * into HTML files, which are placed into the roots HTML directory.
 *
 * @param pluginId the id of the plugin for which the help files should be
 *            generated
 * @param destinationDir directory, where the created/modified files should
 *            be written to. If <code>null</code> they are written directly
 *            into the plugin's directory.
 * @throws Exception if something goes wrong
 */
public synchronized void buildDocumentationFor(final String pluginId, final File destinationDir) throws Exception {
    final Root root = RepositoryManager.INSTANCE.getRoot();
    if (m_monitor != null) {
        Display d = Display.getDefault();
        d.syncExec(new Runnable() {

            @Override
            public void run() {
                if (m_monitor.isCanceled()) {
                    m_canceled = true;
                    return;
                }
                if (m_first) {
                    m_monitor.beginTask("Processing " + m_pluginID, m_nrPlugins * root.getChildren().length);
                    m_first = false;
                } else {
                    m_monitor.subTask("Processing " + m_pluginID);
                }
            }
        });
    }
    if (m_canceled) {
        return;
    }
    m_pluginID = pluginId;
    if (destinationDir == null) {
        m_destinationDir = getPluginDir();
    } else {
        m_destinationDir = destinationDir;
    }
    File nodesDir = new File(m_destinationDir, HTML_DIR + File.separator + NODES_DIR);
    if (!nodesDir.exists() && !nodesDir.mkdirs()) {
        throw new IOException("Could not create directory '" + nodesDir + "'");
    }
    File tocsDir = new File(m_destinationDir, TOC_DIR);
    if (!tocsDir.exists() && !tocsDir.mkdirs()) {
        throw new IOException("Could not create directory '" + tocsDir + "'");
    }
    parsePluginXML();
    if (m_dialog != null) {
        m_dialog.setCancelable(false);
    }
    // processing
    processAll(root.getChildren(), null);
    // at the end -> persist plugin.xml
    Document doc = m_pluginXML;
    Source src = new DOMSource(doc);
    File f = new File(m_destinationDir, m_isFragment ? "fragment.xml" : "plugin.xml");
    Result streamResult = new StreamResult(f);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer serializer = tf.newTransformer();
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.transform(src, streamResult);
    // at the end add the two dependencies to the manifest file
    // org.eclipse.help, org.eclipse.help.ui
    updateManifest();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) Root(org.knime.workbench.repository.model.Root) StreamResult(javax.xml.transform.stream.StreamResult) IOException(java.io.IOException) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 80 with Result

use of javax.xml.transform.Result in project knime-core by knime.

the class NodeDescriptionConverter method writeNodeTocFile.

private void writeNodeTocFile(final Document root, final String fileName) throws IOException, TransformerException {
    Document doc = root;
    Source src = new DOMSource(doc);
    File f = new File(m_destinationDir, TOC_DIR + File.separator + fileName + ".xml");
    Result streamResult = new StreamResult(f);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer serializer = tf.newTransformer();
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.transform(src, streamResult);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document) File(java.io.File) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Aggregations

Result (javax.xml.transform.Result)80 StreamResult (javax.xml.transform.stream.StreamResult)72 Source (javax.xml.transform.Source)52 Transformer (javax.xml.transform.Transformer)52 DOMSource (javax.xml.transform.dom.DOMSource)42 TransformerFactory (javax.xml.transform.TransformerFactory)33 StringWriter (java.io.StringWriter)24 TransformerException (javax.xml.transform.TransformerException)21 IOException (java.io.IOException)20 StreamSource (javax.xml.transform.stream.StreamSource)20 SAXResult (javax.xml.transform.sax.SAXResult)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 File (java.io.File)15 Document (org.w3c.dom.Document)14 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)11 DOMResult (javax.xml.transform.dom.DOMResult)11 InputSource (org.xml.sax.InputSource)11 SAXException (org.xml.sax.SAXException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9