Example usage for org.dom4j.io XMLWriter XMLWriter

List of usage examples for org.dom4j.io XMLWriter XMLWriter

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter XMLWriter.

Prototype

public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException 

Source Link

Usage

From source file:io.mashin.oep.parts.WorkflowNodeEditPart.java

License:Open Source License

private void performOpen() {
    if (getCastedModel() instanceof CustomActionNode) {
        CustomActionNode customActionNode = (CustomActionNode) getCastedModel();
        String customActionNodeXML = "";

        try {//from w ww  .  j a va2  s  .  co m
            StringWriter stringWriter = new StringWriter();
            XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
            writer.write(DocumentHelper
                    .parseText((String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML))
                    .getRootElement());
            writer.flush();
            customActionNodeXML = stringWriter.toString();
        } catch (Exception e) {
            e.printStackTrace();
            customActionNodeXML = (String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML);
        }

        XMLEditor.getInstance().open(customActionNode, customActionNodeXML, customActionNode.getName(),
                xml -> getViewer().getEditDomain().getCommandStack()
                        .execute(new CustomActionNodeXMLEditCommand(customActionNode, xml)));
    }
}

From source file:io.mashin.oep.ui.editor.WorkflowEditor.java

License:Open Source License

private String writeModel() {
    try {/*from  ww w.j  a  va 2 s  . c  o m*/
        Document document = DocumentHelper.createDocument();
        workflow.write(document.addElement("dummy"));
        OutputFormat format = OutputFormat.createPrettyPrint();
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        writer.write(document);
        stringWriter.flush();
        String hpdl = stringWriter.toString();
        hpdl = XMLUtils.schemaVersionToXmlns(hpdl);
        //hpdl = XMLUtils.slaVersionToXmlnsSLA(hpdl);
        return hpdl;
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:iqq.app.service.impl.IMResourceServiceImpl.java

License:Apache License

@Override
public void writeXml(Document document, File xmlFile) {
    try {//  www .ja  v a 2s  .com
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
        outputFormat.setEncoding("UTF-8");// XML?
        outputFormat.setIndent(true);// ?
        outputFormat.setIndent("   ");// TAB?
        outputFormat.setNewlines(true);// ??
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(xmlFile), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:iqq.app.util.XmlUtils.java

License:Apache License

/**
 * XML//from   w w w.  j a  va  2 s. c om
 *
 * @param document
 * @param xmlFile
 * @throws IOException
 */
public static void writeXml(String filename, Document document) throws IOException {
    LOG.debug("XML: " + filename);
    OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
    outputFormat.setEncoding("UTF-8");// XML?
    outputFormat.setIndent(true);// ?
    outputFormat.setIndent("   ");// TAB?
    outputFormat.setNewlines(true);// ??
    synchronized (document) {
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(filename), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    }
}

From source file:it.doqui.index.ecmengine.business.foundation.repository.ExportSvcBean.java

License:Open Source License

private Exporter createXMLExporter(OutputStream viewWriter, ReferenceType referenceType) {
    // Define output format
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(2);//from  www .  j  a va 2s .c om
    format.setEncoding("UTF-8");

    // Construct an XML Exporter
    try {
        XMLWriter writer = new XMLWriter(viewWriter, format);
        ECMEngineExporter exporter = new ECMEngineExporter(serviceRegistry.getNamespaceService(),
                serviceRegistry.getNodeService(), serviceRegistry.getSearchService(),
                serviceRegistry.getDictionaryService(), serviceRegistry.getPermissionService(), writer);
        exporter.setReferenceType(referenceType);
        return exporter;
    } catch (UnsupportedEncodingException e) {
        throw new ExporterException("Failed to create XML Writer for export", e);
    } catch (Exception e) {
        throw new ExporterException("Failed to create XML Writer for export", e);
    }
}

From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java

License:Mozilla Public License

private void guardedWrite(Document document, File file) {
    Writer out;/*from w w  w  .  ja v a2 s  .  co m*/
    OutputFormat format;
    XMLWriter writer;

    logger.debug("IN");

    out = null;
    writer = null;

    try {

        logger.debug("acquiring lock...");
        getLock();
        logger.debug("Lock acquired");

        out = null;
        try {
            out = new FileWriter(file);
        } catch (IOException e) {
            throw new DAOException("Impossible to open file [" + file + "]", e);
        }
        Assert.assertNotNull(out, "Output stream cannot be null");

        format = OutputFormat.createPrettyPrint();
        format.setEncoding("ISO-8859-1");
        format.setIndent("    ");
        writer = new XMLWriter(out, format);
        try {

            writer.write(document);
            writer.flush();
        } catch (IOException e) {
            throw new DAOException("Impossible to write to file [" + file + "]", e);
        }
    } catch (Throwable t) {
        if (t instanceof DAOException)
            throw (DAOException) t;
        throw new DAOException("An unpredicetd error occurred while writing on file [" + file + "]");
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                throw new DAOException("Impossible to properly close stream to file file [" + file + "]", e);
            }
        }
        logger.debug("releasing lock...");
        releaseLock();
        logger.debug("lock released");

        logger.debug("OUT");
    }

}

From source file:it.pdfsam.env.EnvWorker.java

License:Open Source License

/**
 * Saves the environment//from   w  ww  .j av a  2s . c o  m
 * 
 */
public void saveJob() {
    try {
        file_chooser.setApproveButtonText(GettextResource.gettext(i18n_messages, "Save job"));
        int return_val = file_chooser.showOpenDialog(null);
        File chosen_file = null;
        if (return_val == JFileChooser.APPROVE_OPTION) {
            chosen_file = file_chooser.getSelectedFile();
            if (chosen_file != null) {
                try {
                    Document document = DocumentHelper.createDocument();
                    Element root = document.addElement("pdfsam_saved_jobs");
                    root.addAttribute("version", MainGUI.NAME);
                    root.addAttribute("savedate", new SimpleDateFormat("dd-MMM-yyyy").format(new Date()));
                    for (int i = 0; i < pl_panel.length; i++) {
                        Element node = (Element) root.addElement("plugin");
                        node.addAttribute("class", pl_panel[i].getClass().getName());
                        node.addAttribute("name", pl_panel[i].getPluginName());
                        pl_panel[i].getJobNode(node);
                        fireLogPropertyChanged(GettextResource.gettext(i18n_messages,
                                pl_panel[i].getPluginName() + " job node loaded."), LogPanel.LOG_DEBUG);
                    }
                    FileWriter file_writer = new FileWriter(chosen_file);
                    OutputFormat format = OutputFormat.createPrettyPrint();
                    XMLWriter xml_file_writer = new XMLWriter(file_writer, format);
                    xml_file_writer.write(document);
                    xml_file_writer.flush();
                    xml_file_writer.close();
                    fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Job saved."),
                            LogPanel.LOG_INFO);
                } catch (Exception ex) {
                    fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(),
                            LogPanel.LOG_ERROR);

                }
            }
        }
    } catch (RuntimeException re) {
        fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "RuntimeError:")
                + " Unable to load environment. " + re.getMessage(), LogPanel.LOG_ERROR);
    } catch (Exception e) {
        fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error:")
                + " Unable to load environment. " + e.getMessage(), LogPanel.LOG_ERROR);
    }
}

From source file:it.pdfsam.util.XMLParser.java

License:Open Source License

/**
 * Write the DOM to the xml file//from w  w  w.java2 s.  co  m
 * 
 * @param domDoc Document to write
 * @param full_path Full path to the xml file to write
 * @throws Exception
 */
public static void writeXmlFile(Document domDoc, String full_path) throws Exception {
    FileWriter file_writer = new FileWriter(full_path);
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter xml_file_writer = new XMLWriter(file_writer, format);
    xml_file_writer.write(domDoc);
    xml_file_writer.flush();
    xml_file_writer.close();
}

From source file:it.pdfsam.utils.XMLParser.java

License:Open Source License

/**
 * Write the DOM to the xml file/*from   w  w  w  .  j  a v a2  s  .  c o  m*/
 * @param domDoc Document to write
 * @param full_path Full path to the xml file to write
 * @throws Exception
 */
public static void writeXmlFile(Document domDoc, String full_path) throws Exception {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(full_path));
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter xml_file_writer = new XMLWriter(bos, format);
    xml_file_writer.write(domDoc);
    xml_file_writer.flush();
    xml_file_writer.close();
}

From source file:it.unibz.inf.xmlssd.metadator.helpers.Exporter.java

License:Apache License

/**
 * Export method which exports all the stored data as a XML document.
 * @throws IOException//from  ww  w.  j a  v  a2s. c  o  m
 */
public void export() throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(aFile.getCanonicalPath()), format);

    SQLiteManager sqlite = new SQLiteManager();

    writer.write(sqlite.get());
    writer.close();
}