Example usage for org.dom4j.io XMLWriter flush

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

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the underlying Writer

Usage

From source file:org.mitre.muc.callisto.session.SessionLogger.java

License:Open Source License

/** Write xml file to specified stream. */
private void dumpXML(Document xdoc, OutputStream out) throws IOException {
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding("UTF-8");
    XMLWriter writer = new XMLWriter(out, outformat);
    writer.write(xdoc);//from  ww w.j a  va  2s. c om
    writer.flush();
}

From source file:org.neo4j.neoclipse.util.XMLUtils.java

License:Apache License

public static void save(Element pRoot, File pFile) {
    try {//from w ww  .java 2 s .co m
        pFile.getParentFile().mkdirs();
        FileOutputStream fileOutputStream = new FileOutputStream(pFile);
        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint());
        xmlWriter.startDocument();
        xmlWriter.write(pRoot);
        xmlWriter.endDocument();
        xmlWriter.flush();
        xmlWriter.close();
    } catch (Exception e) {
        ErrorMessage.showDialog("Couldn't save: " + pFile.getAbsolutePath(), e);
    }

}

From source file:org.opencms.configuration.CmsConfigurationManager.java

License:Open Source License

/**
 * Writes the XML configuration for the provided configuration instance.<p>
 * // w w  w  .j  a v  a  2 s . c  o  m
 * @param clazz the configuration class to write the XML for
 * @throws IOException in case of I/O errors while writing
 * @throws CmsConfigurationException if the given class is not a valid configuration class
 */
public void writeConfiguration(Class<?> clazz) throws IOException, CmsConfigurationException {

    I_CmsXmlConfiguration configuration = getConfiguration(clazz);
    if (configuration == null) {
        throw new CmsConfigurationException(
                Messages.get().container(Messages.ERR_CONFIG_WITH_UNKNOWN_CLASS_1, clazz.getName()));
    }

    // generate the file URL for the XML input
    File file = new File(m_baseFolder, configuration.getXmlFileName());
    if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_WRITE_CONFIG_XMLFILE_1, file.getAbsolutePath()));
    }

    // generate the XML document 
    Document config = generateXml(configuration);

    // output the document
    XMLWriter writer = null;
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndentSize(4);
    format.setTrimText(false);
    format.setEncoding(CmsEncoder.ENCODING_UTF_8);

    try {
        OutputStream out = new FileOutputStream(file);
        writer = new XMLWriter(out, format);
        writer.write(config);
        writer.flush();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }

    if (LOG.isInfoEnabled()) {
        LOG.info(Messages.get().getBundle().key(Messages.LOG_WRITE_CONFIG_SUCCESS_2, file.getAbsolutePath(),
                configuration.getClass().getName()));
    }
}

From source file:org.panopticode.PanopticodeProject.java

License:Open Source License

public void toFile(File file) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(file), format);
    writer.write(generateXMLDocument());
    writer.flush();
}

From source file:org.pdfsam.guiclient.business.environment.Environment.java

License:Open Source License

/**
 * saves and environment to the output file
 * /*from  ww  w.j  a  va2 s  . c  o m*/
 * @param outFile
 * @param savePasswords
 *            true save passwords informations
 */
public void saveEnvironment(File outFile, boolean savePasswords) {
    try {
        if (outFile != null) {
            synchronized (Environment.class) {
                Document document = DocumentHelper.createDocument();
                Element root = document.addElement("pdfsam_saved_jobs");
                root.addAttribute("version", GuiClient.getVersion());
                root.addAttribute("savedate", new SimpleDateFormat("dd-MMM-yyyy").format(new Date()));
                String selection = treePanel.getSelectedPlugin();
                if (selection != null && selection.length() > 0) {
                    root.addAttribute("selection", selection);
                }
                for (AbstractPlugablePanel plugablePanel : plugins.values()) {
                    Element node = (Element) root.addElement("plugin");
                    node.addAttribute("class", plugablePanel.getClass().getName());
                    node.addAttribute("name", plugablePanel.getPluginName());
                    plugablePanel.getJobNode(node, savePasswords);
                    LOG.info(GettextResource.gettext(i18nMessages,
                            plugablePanel.getPluginName() + " node environment loaded."));
                }
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile));
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setEncoding("UTF-8");
                XMLWriter xmlWriter = new XMLWriter(bos, format);
                xmlWriter.write(document);
                xmlWriter.flush();
                xmlWriter.close();
            }
            LOG.info(GettextResource.gettext(i18nMessages, "Environment saved."));
        } else {
            LOG.error(GettextResource.gettext(i18nMessages, "Error saving environment, output file is null."));
        }
    } catch (Exception ex) {
        LOG.error(GettextResource.gettext(i18nMessages, "Error saving environment."), ex);
    }
}

From source file:org.pdfsam.guiclient.utils.xml.XMLParser.java

License:Open Source License

/**
 * Write the DOM to the xml file//  w w  w. j av  a 2  s. c om
 * 
 * @param domDoc Document to write
 * @param outFile xml File to write
 * @throws Exception
 */
public static void writeXmlFile(Document domDoc, File outFile) throws Exception {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile));
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter xmlFileWriter = new XMLWriter(bos, format);
    xmlFileWriter.write(domDoc);
    xmlFileWriter.flush();
    xmlFileWriter.close();
}

From source file:org.pdfsam.guiclient.utils.XmlUtility.java

License:Open Source License

/**
 * Write the DOM to the xml file/*from w  w  w  .  j  a v a  2s .  co  m*/
 * 
 * @param domDoc
 *            Document to write
 * @param outFile
 *            xml File to write
 * @throws IOException
 */
public static void writeXmlFile(Document domDoc, File outFile) throws IOException {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile));
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter xmlFileWriter = new XMLWriter(bos, format);
    xmlFileWriter.write(domDoc);
    xmlFileWriter.flush();
    xmlFileWriter.close();
}

From source file:org.pdfsam.plugin.merge.actions.SaveListAsXmlAction.java

License:Open Source License

/**
 * Save the xml file//  www .jav  a2 s. c o m
 * 
 * @param rows
 * @param selectedFile
 * @throws Exception
 */
public void writeXmlFile(PdfSelectionTableItem[] rows, File selectedFile) throws Exception {
    if (selectedFile != null && rows != null) {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("filelist");
        for (int i = 0; i < rows.length; i++) {
            PdfSelectionTableItem row = rows[i];
            Element node = (Element) root.addElement("file");
            node.addAttribute("value", row.getInputFile().getAbsolutePath());
            String pwd = row.getPassword();
            if (pwd != null && pwd.length() > 0) {
                node.addAttribute("password", pwd);
            }
        }
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(selectedFile));
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter xmlWriter = new XMLWriter(bos, format);
        xmlWriter.write(document);
        xmlWriter.flush();
        xmlWriter.close();
        LOG.info(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "File xml saved."));
    } else {
        LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Error saving xml file, output file is null."));
    }
}

From source file:org.pdfsam.plugin.merge.components.JSaveListAsXmlMenuItem.java

License:Open Source License

/**
 * Save the xml file//from w  w w.j  a va2  s.c  om
 * @param rows
 * @param selectedFile
 * @throws Exception
 */
public void writeXmlFile(PdfSelectionTableItem[] rows, File selectedFile) throws Exception {
    if (selectedFile != null && rows != null) {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("filelist");
        for (int i = 0; i < rows.length; i++) {
            PdfSelectionTableItem row = rows[i];
            Element node = (Element) root.addElement("file");
            node.addAttribute("value", row.getInputFile().getAbsolutePath());
            String pwd = row.getPassword();
            if (pwd != null && pwd.length() > 0) {
                node.addAttribute("password", pwd);
            }
        }
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(selectedFile));
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter xmlWriter = new XMLWriter(bos, format);
        xmlWriter.write(document);
        xmlWriter.flush();
        xmlWriter.close();
        log.info(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "File xml saved."));
    } else {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Error saving xml file, output file is null."));
    }
}

From source file:org.pentaho.platform.plugin.adhoc.AdhocWebService.java

License:Open Source License

public static void main(String args[]) throws Exception {
    XMLWriter writer = new XMLWriter(System.out, OutputFormat.createPrettyPrint());
    Document doc = new AdhocWebService().createSolutionTree(new File("package-res/resources/templates"));

    Element folderElement = AdhocWebService.getFolderElement(doc, "/system/waqr/resources");
    Document systemDoc = null;/*from w w w  .j  a  v a2s. c om*/
    if (folderElement != null) {
        Element clonedFolderElement = (Element) folderElement.clone();
        AdhocWebService.removeChildElements(clonedFolderElement);
        systemDoc = DocumentHelper.createDocument((Element) clonedFolderElement.detach());
        systemDoc.setXMLEncoding(LocaleHelper.getSystemEncoding());
    } else {
        String msg = Messages.getInstance().getString("AdhocWebService.ERROR_0011_FAILED_TO_LOCATE_PATH", "/"); //$NON-NLS-1$
        throw new AdhocWebServiceException(msg);
    }

    writer.write(systemDoc);
    writer.flush();
    //    System.out.println(XmlDom4JHelper.docToString();
}