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:edu.ku.brc.specify.tasks.services.CollectingEventLocalityKMLGenerator.java

License:Open Source License

private String XMLtoString(Element el) {
    OutputFormat format = OutputFormat.createPrettyPrint();
    Writer writer = new StringWriter();
    try {// w w  w .j av a 2s. c  om
        new XMLWriter(writer, format).write(el);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return writer.toString();
}

From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java

License:Open Source License

/**
 * @param file/*from  www  .  j  a v  a 2 s . c o m*/
 */
public void process(final File fileArg, final boolean doDiffs) {
    try {
        String dirName = RES_PATH + "values-" + destLocale.getLanguage();
        String path = dirName + File.separator + fileArg.getName();

        File file = fileArg;
        if (doDiffs) {
            file = new File(path);
        }
        Document doc = readFileToDOM4J(new FileInputStream(file));
        Node root = doc.getRootElement();

        for (Object nodeObj : root.selectNodes("/resources/string")) {
            Node node = (Node) nodeObj;
            String name = XMLHelper.getAttr((Element) node, "name", null);

            if (doDiffs) {
                if (baseHash.get(name) != null) {
                    continue;
                }
            }

            String text = node.getText();
            String transText = translate(text);
            if (transText != null) {
                node.setText(transText);
            }
            System.out.println(name + "[" + text + "][" + transText + "]");
        }

        File dir = new File(dirName);
        if (!dir.exists()) {
            dir.mkdir();
        }

        FileOutputStream fos = new FileOutputStream(path);
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(fos, format);
        writer.write(doc);
        writer.flush();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.ku.brc.util.services.GenericKMLGenerator.java

License:Open Source License

/**
 * Generates KML output based on the current points, names and descriptions given to the generator.
 * //from ww w. ja va 2 s.co  m
 * @param out a stream to which the KML is written
 * @throws IOException if an I/O error occurs
 */
public void generateKML(final FileWriter out) throws IOException {
    Document kml = generateKML();
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(out, format);
    writer.write(kml);
    writer.close();
}

From source file:edu.scripps.fl.pubchem.promiscuity.XMLDocument.java

License:Apache License

public void write(Document doc, File toFile) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(toFile), format);
    writer.write(doc);//from   w  w w.j ava2 s .  c o  m
    writer.close();
}

From source file:edu.scripps.fl.pubchem.xml.PubChemXMLDoc.java

License:Apache License

public void write(Document doc, File toFile) throws IOException {
    fixAttribute(doc);/* w w  w .j a  va 2s  .  com*/
    organizeXMLDoc(doc);

    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(toFile), format);
    writer.write(doc);
    writer.close();
}

From source file:edu.ucsd.library.xdre.web.CollectionOperationController.java

/**
 * Serialize xml document to file/*ww w . j  av  a 2 s. c  om*/
 * @param destFile
 * @param doc
 * @throws IOException
 */
public static void writeXml(File destFile, Document doc) throws IOException {
    OutputStreamWriter out = null;
    XMLWriter writer = null;
    OutputFormat pretty = OutputFormat.createPrettyPrint();
    try {
        out = new FileWriter(destFile);
        writer = new XMLWriter(out, pretty);
        writer.write(doc);
    } finally {
        CollectionHandler.close(out);
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            writer = null;
        }
    }
}

From source file:edu.umd.cs.findbugs.AddMessages.java

License:Open Source License

@SuppressFBWarnings("DM_EXIT")
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.err.println("Usage: " + AddMessages.class.getName() + " <input collection> <output collection>");
        System.exit(1);// w  w w. ja v a2  s .  c om
    }

    // Load plugins, in order to get message files
    DetectorFactoryCollection.instance();

    String inputFile = args[0];
    String outputFile = args[1];
    Project project = new Project();

    SortedBugCollection inputCollection = new SortedBugCollection(project);
    inputCollection.readXML(inputFile);

    Document document = inputCollection.toDocument();

    AddMessages addMessages = new AddMessages(inputCollection, document);
    addMessages.execute();

    XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(outputFile)),
            OutputFormat.createPrettyPrint());
    writer.write(document);
    writer.close();
}

From source file:edu.umd.cs.findbugs.ml.GenerateUIDs.java

License:Open Source License

@SuppressWarnings("unchecked")
public void execute() throws IOException, DocumentException {
    InputStream in = null;//from ww  w  .j  a  v a  2 s .co  m
    try {
        if (inputFilename.equals("-")) {
            in = System.in;
        } else {
            in = new BufferedInputStream(new FileInputStream(inputFilename));
            if (inputFilename.endsWith(".gz"))
                in = new GZIPInputStream(in);
        }

        bugCollection.readXML(in);
        in = null;
    } finally {
        if (in != null)
            in.close();
    }
    Document document = DocumentFactory.getInstance().createDocument();
    Dom4JXMLOutput xmlOutput = new Dom4JXMLOutput(document);
    bugCollection.writeXML(xmlOutput);

    int count = 0;

    List<Element> bugInstanceList = document.selectNodes("/BugCollection/BugInstance");
    for (Element element : bugInstanceList) {
        Attribute uidAttr = element.attribute("uid");
        if (uidAttr == null) {
            element.addAttribute("uid", Integer.toString(count++));
        }
    }

    OutputStream out;
    if (outputFilename.equals("-")) {
        out = System.out;
    } else {
        out = new BufferedOutputStream(new FileOutputStream(outputFilename));
    }

    XMLWriter xmlWriter = new XMLWriter(out, OutputFormat.createPrettyPrint());
    try {
        xmlWriter.write(document);
    } finally {
        xmlWriter.close();
    }
}

From source file:edu.umd.cs.findbugs.XDocsBugReporter.java

License:Open Source License

private void writeXML(Writer out, Project project) throws IOException {
    Document document = endDocument(project);

    XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
    writer.write(document);//from   w ww  .  j a  va 2s . c om
}

From source file:edu.upenn.cis.orchestra.workloadgenerator.GeneratorJournal.java

License:Apache License

/**
 * Write this <code>GeneratorJournal</code> out to <code>writer</code>.
 * See <code>serialize(...)</code> for the format.
 * /*from  w  w  w.j a  v a  2  s.  co  m*/
 * @param writer
 *            to which to write this <code>GeneratorJournal</code>.
 * @param params
 *            run parameters, see <code>Generator</code>.
 * @throws IOException
 *             if such is thrown whilst writing this
 *             <code>GeneratorJournal</code>.
 */
public void write(Writer writer, Map<String, Object> params) throws IOException {
    XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
    xmlWriter.write(serialize(params));
    xmlWriter.flush();
    xmlWriter.close();
}