Example usage for org.jdom2.output XMLOutputter getFormat

List of usage examples for org.jdom2.output XMLOutputter getFormat

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter getFormat.

Prototype

public Format getFormat() 

Source Link

Document

Returns the current format in use by the XMLOutputter.

Usage

From source file:ilarkesto.integration.jdom.JDom.java

License:Open Source License

public static void save(Document doc, File file, String encoding) {
    IO.createDirectory(file.getParentFile());
    Writer out;/*from w  w w.  j  av a2  s.  co m*/
    try {
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex);
    }
    XMLOutputter outputter = new XMLOutputter();
    outputter.getFormat().setEncoding(encoding);
    try {
        outputter.output(doc, out);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    IO.close(out);
}

From source file:ilarkesto.integration.jdom.JDom.java

License:Open Source License

public static void write(Document doc, OutputStream out, String encoding) {
    XMLOutputter outputter = new XMLOutputter();
    outputter.getFormat().setEncoding(encoding);
    try {/*from   w  w  w .j  av  a  2s.  c  o  m*/
        outputter.output(doc, out);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    IO.close(out);
}

From source file:org.jpos.transaction.Context.java

License:Open Source License

protected void dumpEntry(PrintStream p, String indent, Map.Entry<String, Object> entry) {
    String key = entry.getKey();//  w  ww . j  av a2 s.  co  m
    if (key.startsWith(".") || key.startsWith("*"))
        return; // see jPOS-63

    p.printf("%s%s%s: ", indent, key, pmap != null && pmap.containsKey(key) ? "(P)" : "");
    Object value = entry.getValue();
    if (value instanceof Loggeable) {
        p.println("");
        ((Loggeable) value).dump(p, indent + " ");
        p.print(indent);
    } else if (value instanceof Element) {
        p.println("");
        p.println(indent + "<![CDATA[");
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        out.getFormat().setLineSeparator(System.lineSeparator());
        try {
            out.output((Element) value, p);
        } catch (IOException ex) {
            ex.printStackTrace(p);
        }
        p.println("");
        p.println(indent + "]]>");
    } else if (value instanceof byte[]) {
        byte[] b = (byte[]) value;
        p.println("");
        p.println(ISOUtil.hexdump(b));
        p.print(indent);
    } else if (value instanceof LogEvent) {
        ((LogEvent) value).dump(p, indent);
        p.print(indent);
    } else if (value != null) {
        try {
            p.print(ISOUtil.normalize(value.toString(), true));
        } catch (Exception e) {
            p.println(e.getMessage());
            p.print(indent);
        }
    }
    p.println();
}

From source file:org.jpos.util.LogEvent.java

License:Open Source License

public void dump(PrintStream p, String outer) {
    String indent = dumpHeader(p, outer);
    if (payLoad.isEmpty()) {
        if (tag != null)
            p.println(indent + "<" + tag + "/>");
    } else {//from www .  ja  va 2  s . co m
        String newIndent;
        if (tag != null) {
            p.println(indent + "<" + tag + ">");
            newIndent = indent + "  ";
        } else
            newIndent = "";
        synchronized (payLoad) {
            for (Object o : payLoad) {
                if (o instanceof Loggeable)
                    ((Loggeable) o).dump(p, newIndent);
                else if (o instanceof SQLException) {
                    SQLException e = (SQLException) o;
                    p.println(newIndent + "<SQLException>" + e.getMessage() + "</SQLException>");
                    p.println(newIndent + "<SQLState>" + e.getSQLState() + "</SQLState>");
                    p.println(newIndent + "<VendorError>" + e.getErrorCode() + "</VendorError>");
                    ((Throwable) o).printStackTrace(p);
                } else if (o instanceof Throwable) {
                    p.println(newIndent + "<exception name=\"" + ((Throwable) o).getMessage() + "\">");
                    p.print(newIndent);
                    ((Throwable) o).printStackTrace(p);
                    p.println(newIndent + "</exception>");
                } else if (o instanceof Object[]) {
                    Object[] oa = (Object[]) o;
                    p.print(newIndent + "[");
                    for (int j = 0; j < oa.length; j++) {
                        if (j > 0)
                            p.print(",");
                        p.print(oa[j].toString());
                    }
                    p.println("]");
                } else if (o instanceof Element) {
                    p.println("");
                    p.println(newIndent + "<![CDATA[");
                    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
                    out.getFormat().setLineSeparator("\n");
                    try {
                        out.output((Element) o, p);
                    } catch (IOException ex) {
                        ex.printStackTrace(p);
                    }
                    p.println("");
                    p.println(newIndent + "]]>");
                } else if (o != null) {
                    p.println(newIndent + o.toString());
                } else {
                    p.println(newIndent + "null");
                }
            }
        }
        if (tag != null)
            p.println(indent + "</" + tag + ">");
    }
    dumpTrailer(p, outer);
}

From source file:org.plasma.sdo.xml.DocumentMarshaller.java

License:Open Source License

@SuppressWarnings("deprecation")
public String getContent(java.lang.String indent, boolean newlines) {
    XMLOutputter outputter = new XMLOutputter();
    outputter.getFormat().setIndent(indent);
    return getContent(outputter);
}

From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java

License:Open Source License

@Override
@SuppressWarnings("deprecation")
public String getContent(java.lang.String indent, boolean newlines) {
    XMLOutputter outputter = new XMLOutputter();

    outputter.getFormat().setIndent(indent);

    return getContent(outputter);
}

From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java

License:Open Source License

@Override
@SuppressWarnings("deprecation")
public void getContent(OutputStream stream, java.lang.String indent, boolean newlines) {
    XMLOutputter outputter = new XMLOutputter();
    outputter.getFormat().setIndent(indent);
    getContent(stream, outputter);/*w w  w . java  2  s  .co  m*/
}

From source file:scrum.server.ScrumEntityfilePreparator.java

License:Open Source License

private void save(Document doc, File file) throws IOException {
    LOG.info("Saving prepared entity file:", file);
    backup(file);/*from w  w  w.j  a  v a 2 s  .  c  o m*/
    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    XMLOutputter outputter = new XMLOutputter();
    outputter.getFormat().setEncoding(IO.UTF_8);
    outputter.output(doc, out);
    out.close();
}