Example usage for org.dom4j.io OutputFormat setLineSeparator

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

Introduction

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

Prototype

public void setLineSeparator(String separator) 

Source Link

Document

This will set the new-line separator.

Usage

From source file:au.com.acegi.xmlformat.XmlFormatPlugin.java

License:Apache License

private OutputFormat buildFormatter() {
    final OutputFormat fmt = createPrettyPrint();
    fmt.setAttributeQuoteCharacter(attributeQuoteChar);
    fmt.setEncoding(encoding);/*w  ww  . j  a v  a2s . c o  m*/
    fmt.setExpandEmptyElements(expandEmptyElements);
    fmt.setIndentSize(indentSize);
    fmt.setLineSeparator(determineLineSeparator());
    fmt.setNewLineAfterDeclaration(newLineAfterDeclaration);
    fmt.setNewLineAfterNTags(newLineAfterNTags);
    fmt.setNewlines(newlines);
    fmt.setOmitEncoding(omitEncoding);
    fmt.setPadText(padText);
    fmt.setSuppressDeclaration(suppressDeclaration);
    fmt.setTrimText(trimText);
    fmt.setXHTML(xhtml);
    return fmt;
}

From source file:com.ai.tools.generator.util.XMLFormatter.java

License:Open Source License

public static String toString(Branch branch, String indent, boolean expandEmptyElements) throws IOException {
    ByteArrayMaker bam = new ByteArrayMaker();

    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setExpandEmptyElements(expandEmptyElements);
    format.setIndent(indent);//www.j  a v a 2 s  .c  om
    format.setLineSeparator("\n");

    XMLWriter writer = new XMLWriter(bam, format);

    writer.write(branch);

    String content = bam.toString(StringPool.UTF8);

    // LEP-4257

    //content = StringUtil.replace(content, "\n\n\n", "\n\n");
    if (content.endsWith("\n\n")) {
        content = content.substring(0, content.length() - 2);
    }

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    while (content.indexOf(" \n") != -1) {
        content = StringUtil.replace(content, " \n", "\n");
    }

    return content;
}

From source file:com.augmentum.common.util.XMLFormatter.java

License:Open Source License

public static String toString(Branch branch, String indent, boolean expandEmptyElements) throws IOException {

    ByteArrayMaker bam = new ByteArrayMaker();

    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setExpandEmptyElements(expandEmptyElements);
    format.setIndent(indent);//from w w w.  j av  a2 s.  co  m
    format.setLineSeparator("\n");

    XMLWriter writer = new XMLWriter(bam, format);

    writer.write(branch);

    String content = bam.toString(StringPool.UTF8);

    // LEP-4257

    //content = StringUtil.replace(content, "\n\n\n", "\n\n");

    if (content.endsWith("\n\n")) {
        content = content.substring(0, content.length() - 2);
    }

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    while (content.indexOf(" \n") != -1) {
        content = StringUtil.replace(content, " \n", "\n");
    }

    return content;
}

From source file:com.liferay.petra.xml.Dom4jUtil.java

License:Open Source License

public static String toString(Node node, String indent, boolean expandEmptyElements, boolean trimText)
        throws IOException {

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    OutputFormat outputFormat = OutputFormat.createPrettyPrint();

    outputFormat.setExpandEmptyElements(expandEmptyElements);
    outputFormat.setIndent(indent);/*w  w  w . j  ava2s .c o  m*/
    outputFormat.setLineSeparator(StringPool.NEW_LINE);
    outputFormat.setTrimText(trimText);

    XMLWriter xmlWriter = new XMLWriter(unsyncByteArrayOutputStream, outputFormat);

    xmlWriter.write(node);

    String content = unsyncByteArrayOutputStream.toString(StringPool.UTF8);

    // LEP-4257

    //content = StringUtil.replace(content, "\n\n\n", "\n\n");

    if (content.endsWith("\n\n")) {
        content = content.substring(0, content.length() - 2);
    }

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    while (content.contains(" \n")) {
        content = StringUtil.replace(content, " \n", "\n");
    }

    if (content.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")) {
        content = StringUtil.replaceFirst(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
                "<?xml version=\"1.0\"?>");
    }

    return content;
}

From source file:com.liferay.util.xml.XMLFormatter.java

License:Open Source License

public static String toString(Document doc, String indent) throws IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setIndent(indent);//  www. j a va 2 s.  co m
    format.setLineSeparator("\n");

    XMLWriter writer = new XMLWriter(baos, format);

    writer.write(doc);

    String content = baos.toString();

    content = StringUtil.replace(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
            "<?xml version=\"1.0\"?>");

    int x = content.indexOf("<!DOCTYPE");
    if (x != -1) {
        x = content.indexOf(">", x) + 1;
        content = content.substring(0, x) + "\n" + content.substring(x, content.length());
    }

    content = StringUtil.replace(content, "\n\n\n", "\n\n");

    if (content.endsWith("\n\n")) {
        content = content.substring(0, content.length() - 2);
    }

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    return content;
}

From source file:com.liferay.util.xml.XMLMergerRunner.java

License:Open Source License

private String _documentToString(Document doc, String docType) throws IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setIndent("\t");
    format.setLineSeparator("\n");

    XMLWriter writer = new XMLWriter(baos, format);

    writer.write(doc);//from   w w w  . j  av  a2 s . co  m

    String xml = baos.toString();

    int pos = xml.indexOf("<?");

    String header = xml.substring(pos, xml.indexOf("?>", pos) + 2);

    xml = StringUtil.replace(xml, header, "");
    xml = header + "\n" + docType + "\n" + xml;

    return xml;
}

From source file:de.hasait.eclipse.common.xml.XDocument.java

License:Apache License

public String asFormattedXml(final String lineSeparator, final String indent, final boolean newlines,
        final boolean trimText) {
    StringWriter sw = new StringWriter();
    try {//from  ww w  .jav  a 2 s.co m
        OutputFormat outputFormat = new OutputFormat(indent, newlines);
        outputFormat.setTrimText(trimText);
        outputFormat.setLineSeparator(lineSeparator);
        new XMLWriter(sw, outputFormat).write(_document);
    } catch (IOException e) {
        // Should not happen for StringWriter
        throw new RuntimeException(e);
    }
    return sw.getBuffer().toString();
}

From source file:de.hasait.eclipse.common.xml.XElement.java

License:Apache License

public String asFormattedXml(final String lineSeparator, final String indent, final boolean newlines,
        final boolean trimText) {
    StringWriter sw = new StringWriter();
    try {/*from w  w  w.  ja  v  a 2 s.c  o  m*/
        OutputFormat outputFormat = new OutputFormat(indent, newlines);
        outputFormat.setTrimText(trimText);
        outputFormat.setLineSeparator(lineSeparator);
        new XMLWriter(sw, outputFormat).write(_element);
    } catch (IOException e) {
        // Should not happen for StringWriter
        throw new RuntimeException(e);
    }
    return sw.getBuffer().toString();
}

From source file:fullyMeshedNet.FullyMeshedNet.java

License:Open Source License

@Override
public void exportToFile(File saveFile) {
    String extension = FrevoMain.getExtension(saveFile);
    if (extension.equals("net")) {
        System.out.println("Exporting Pajek network file to " + saveFile.getName());
        try {/*from www  .  j a v a2  s. c  o m*/
            // Create file
            FileWriter fstream = new FileWriter(saveFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("*Vertices " + this.nodes);
            out.newLine();
            // input neurons
            for (int i = 1; i < input_nodes + 1; i++) {
                out.write(i + " \"I" + i + "\"");
                out.newLine();
            }
            for (int h = input_nodes + 1; h < nodes - output_nodes + 1; h++) {
                out.write(h + " \"H" + (h - input_nodes) + "\"");
                out.newLine();
            }
            int a = 1;
            for (int o = nodes - output_nodes + 1; o < nodes + 1; o++) {
                out.write(o + " \"O" + a + "\"");
                out.newLine();
                a++;
            }

            // Edges
            out.write("*Edges");
            out.newLine();
            for (int n = 0; n < input_nodes - 1; n++) {
                for (int p = n + 1; p < input_nodes; p++) {
                    if (n != p) {
                        out.write((n + 1) + " " + (p + 1) + " " + 0);
                        out.newLine();
                    }
                }
            }

            for (int n = input_nodes; n < nodes; n++) {
                for (int from = 0; from < nodes; from++) {
                    out.write((n + 1) + " " + (from + 1) + " " + weight[from][n]);
                    out.newLine();
                }
            }

            // Close the output stream
            out.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    } else if (extension.equals("xml")) {
        System.out.println("Saving to XML");

        Document doc = DocumentHelper.createDocument();
        doc.addDocType("CompleteNetwork", null, System.getProperty("user.dir")
                + "//Components//Representations//CompleteNetwork//src//CompleteNetwork.dtd");
        Element cnetwork = doc.addElement("CompleteNetwork");
        this.exportToXmlElement(cnetwork);

        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setLineSeparator(System.getProperty("line.separator"));

        try {
            saveFile.createNewFile();
            FileWriter out = new FileWriter(saveFile);
            BufferedWriter bw = new BufferedWriter(out);
            XMLWriter wr = new XMLWriter(bw, format);
            wr.write(doc);
            wr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:hebbNet.HebbNet.java

License:Open Source License

@Override
public void exportToFile(File saveFile) {
    String extension = FrevoMain.getExtension(saveFile);
    if (extension.equals("net")) {
        System.out.println("Exporting Pajek network file to " + saveFile.getName());
        try {//  w  w w  . j av  a 2 s. co m
            // Create file
            FileWriter fstream = new FileWriter(saveFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("*Vertices " + this.nodes);
            out.newLine();
            // input neurons
            for (int i = 1; i < input_nodes + 1; i++) {
                out.write(i + " \"I" + i + "\"");
                out.newLine();
            }
            for (int h = input_nodes + 1; h < nodes - output_nodes + 1; h++) {
                out.write(h + " \"H" + (h - input_nodes) + "\"");
                out.newLine();
            }
            int a = 1;
            for (int o = nodes - output_nodes + 1; o < nodes + 1; o++) {
                out.write(o + " \"O" + a + "\"");
                out.newLine();
                a++;
            }

            // Edges
            out.write("*Edges");
            out.newLine();
            for (int n = 0; n < input_nodes - 1; n++) {
                for (int p = n + 1; p < input_nodes; p++) {
                    if (n != p) {
                        out.write((n + 1) + " " + (p + 1) + " " + 0);
                        out.newLine();
                    }
                }
            }

            for (int n = input_nodes; n < nodes; n++) {
                for (int from = 0; from < nodes; from++) {
                    out.write((n + 1) + " " + (from + 1) + " " + weight[from][n]);
                    // out.write((n+1)+" "+(from+1)+" "+plasticity[from][n]);
                    out.newLine();
                }
            }

            // Close the output stream
            out.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    } else if (extension.equals("xml")) {
        System.out.println("Saving to XML");

        Document doc = DocumentHelper.createDocument();
        doc.addDocType("HebbNet", null,
                System.getProperty("user.dir") + "//Components//Representations//HebbNet//src//HebbNet.dtd");
        Element cnetwork = doc.addElement("HebbNet");
        this.exportToXmlElement(cnetwork);

        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setLineSeparator(System.getProperty("line.separator"));

        try {
            saveFile.createNewFile();
            FileWriter out = new FileWriter(saveFile);
            BufferedWriter bw = new BufferedWriter(out);
            XMLWriter wr = new XMLWriter(bw, format);
            wr.write(doc);
            wr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}