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.jogre.server.data.xml.ServerDataXML.java

License:Open Source License

/**
 * Constructor for a user connecting locally on a computer.
 *
 * Use dom4j instead of nanoXML as its much more powerful.  Size
 * isn't really a concern on the server side.
 *//* w ww  .  j a v a  2s.com*/
public ServerDataXML() {
    // Create formattor to be pretty printed
    format = OutputFormat.createPrettyPrint();

    // Load user / game documents
    loadDocuments();
}

From source file:org.miloss.fgsms.presentation.Helper.java

License:Mozilla Public License

public static String PrettyPrintXMLToHtml(String xml) {
        try {/*  w  ww.j  a  v a  2s . co  m*/
            Document doc = DocumentHelper.parseText(xml);
            StringWriter sw = new StringWriter();
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter xw = new XMLWriter(sw, format);
            xw.write(doc);
            return Utility.encodeHTML(sw.toString());

        } catch (Exception ex) {
            //LogHelper.getLog().log(Level.INFO, "error creating pretty print xml. It's probably not an xml message: " + ex.getLocalizedMessage());
        }

        try {
            Document doc = DocumentHelper.parseText(xml.substring(xml.indexOf("<")));
            StringWriter sw = new StringWriter();
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter xw = new XMLWriter(sw, format);
            xw.write(doc);
            return Utility.encodeHTML(sw.toString());

        } catch (Exception ex) {
            //LogHelper.getLog().log(Level.INFO, "error creating pretty print xml. It's probably not an xml message: " + ex.getLocalizedMessage());
        }
        LogHelper.getLog().log(Level.INFO,
                "error creating pretty print xml. It's probably not an xml message. No action is required.");
        return Utility.encodeHTML(xml);

    }

From source file:org.mitre.ace2004.callisto.ExportAPF5_0_2.java

License:Open Source License

/**
 *//*w w  w. ja v a 2 s  .  c  om*/
private boolean writeAPF(Document xmlDoc, URI uri) throws IOException {
    File apfFile = new File(uri);
    File backFile = new File(apfFile.toString() + "~");
    File tmpFile = ATLASHelper.createTempFile(uri);
    if (DEBUG > 0)
        System.err.println("Export APF File: " + apfFile + "\n       TMP File: " + tmpFile);

    FileOutputStream fileOut = new FileOutputStream(tmpFile);
    // always output APF as UTF-8, though the source file may be something else
    Writer writer = new OutputStreamWriter(fileOut, "UTF-8");
    writer = new BufferedWriter(writer);

    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    xmlWriter.write(xmlDoc);
    xmlWriter.close();

    if (apfFile.exists()) {
        if (backFile.exists())
            backFile.delete();
        apfFile.renameTo(backFile);
    }

    return tmpFile.renameTo(apfFile);
}

From source file:org.mitre.jawb.io.ATLASHelper.java

License:Open Source License

public static void dump(Document doc, OutputStream out) throws IOException {

    // Pretty print the document to System.out
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("US-ASCII");
    Writer writer = new OutputStreamWriter(out, "US-ASCII");
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    xmlWriter.write(doc);/*from  w w w  .ja  v  a  2  s. co  m*/
    xmlWriter.close();
}

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  w  ww  . j av  a  2 s  .c o  m*/
    writer.flush();
}

From source file:org.mule.intents.AppBuilder.java

License:Open Source License

protected String convertConfigToString() throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    StringWriter string = new StringWriter();
    XMLWriter writer = new XMLWriter(string, format);
    writer.write(getConfig());// w  w  w .  j  a  v  a2 s .  c o  m
    return string.toString();
}

From source file:org.mustangproject.ZUGFeRD.ZUGFeRD2PullProvider.java

License:Open Source License

@Override
public byte[] getXML() {

    byte[] res = zugferdData;

    StringWriter sw = new StringWriter();
    Document document = null;/*from   ww  w . ja v a 2  s  . c  o  m*/
    try {
        document = DocumentHelper.parseText(new String(zugferdData));
    } catch (DocumentException e1) {
        Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e1);
    }
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(sw, format);
        writer.write(document);
        res = sw.toString().getBytes("UTF-8");

    } catch (IOException e) {
        Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
    }

    return res;

}

From source file:org.napile.asm.io.xml.out.AsmXmlFileWriter.java

License:Apache License

@NotNull
@Override/*www  . j  av a2  s  .co m*/
protected File getResult() {
    File file = null;
    List<FqName> paths = fqName.path();
    for (int i = 0; i < paths.size(); i++) {
        FqName path = paths.get(i);
        file = new File(outputDir, path.getFqName().replace(".", File.separator));

        // last segment is original FqName
        if (i != paths.size() - 1)
            file.mkdirs();
    }

    assert file != null;

    file = new File(file.getAbsolutePath() + DOT_EXTENSION);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndent("\t");
    try {
        XMLWriter writer = new XMLWriter(new FileOutputStream(file), format);
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}

From source file:org.napile.asm.io.xml.out.AsmXmlTextWriter.java

License:Apache License

@NotNull
@Override//from ww w.  ja  va 2 s.com
protected String getResult() {
    StringWriter stringWriter = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndent("\t");
    try {
        XMLWriter writer = new XMLWriter(stringWriter, format);
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return stringWriter.toString();
}

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

License:Apache License

public static void save(Element pRoot, File pFile) {
    try {//from w ww  . ja  v a2s .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);
    }

}