Example usage for org.dom4j.io OutputFormat createPrettyPrint

List of usage examples for org.dom4j.io OutputFormat createPrettyPrint

Introduction

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

Prototype

public static OutputFormat createPrettyPrint() 

Source Link

Document

A static helper method to create the default pretty printing format.

Usage

From source file:org.panopticode.doclet.PanopticodeDoclet.java

License:Open Source License

void dumpXMLReport(PanopticodeProject theProject) throws IOException {
    PrintStream output;/*from  ww w . ja va 2  s.co  m*/
    String outputFile;
    XMLWriter xmlWriter;

    outputFile = readOption("outputFile");

    if (outputFile == null) {
        output = System.out;
    } else {
        output = new PrintStream(outputFile);
    }

    xmlWriter = new XMLWriter(output, OutputFormat.createPrettyPrint());
    xmlWriter.write(theProject.generateXMLDocument());
}

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  w ww.  j  a v  a 2  s.co m*/
}

From source file:org.panopticode.report.treemap.BaseTreemap.java

License:Open Source License

public void runReport(PanopticodeProject project, String[] arguments) {
    String outputFile = arguments[0];

    PrintStream output;/*from   w  ww.ja v a2 s  .c o m*/
    XMLWriter xmlWriter;

    boolean interactive = false;

    if (arguments.length == 2 && "-interactive".equals(arguments[1]))
        interactive = true;

    try {
        if (outputFile == null)
            output = System.out;
        else
            output = new PrintStream(outputFile);

        xmlWriter = new XMLWriter(output, OutputFormat.createPrettyPrint());
        xmlWriter.write(generateXMLDocument(project, interactive));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

/**
 * saves and environment to the output file
 * /*  ww w .  java  2s  .  co  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//from   w w w  .j a  va2 s .  com
 * 
 * @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/*  ww w  .java  2  s  .c o 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/*from ww w.  j av a2s .  co  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  ww . j a  v  a 2  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.peerfact.impl.analyzer.visualization2d.util.Config.java

License:Open Source License

/**
 * Writes the existing structure in the XML config file
 *//* w ww  .j a v a  2s .  c om*/
public static void writeXMLFile() {

    if (config != null) { // Write file only if the XML tree exists in
        // memory
        try {
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter writer = new XMLWriter(new FileWriter(configFile), format);
            writer.write(Config.config);
            writer.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.peerfact.impl.network.gnp.topology.HostMap.java

License:Open Source License

/**
 * saves host postion location, GNP position, groups, GNP Space, PingER
 * Lookup table in an xml file used within the simulation
 * /*www . ja  v  a  2s . com*/
 * @param file
 */
public void exportToXml(File file) {
    log.debug("Export Hosts to an XML File");
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        XMLWriter writer = new XMLWriter(out, format);
        writer.write(getDocument());
        writer.close();
    } catch (IOException e) {
        log.debug(e);
    }
}