Search in sources :

Example 1 with Format

use of org.jdom2.output.Format in project k-9 by k9mail.

the class SettingsExporterTest method exportPreferences_setsFormatTo1.

@Test
public void exportPreferences_setsFormatTo1() throws Exception {
    Document document = exportPreferences(false, Collections.<String>emptySet());
    assertEquals("1", document.getRootElement().getAttributeValue("format"));
}
Also used : Document(org.jdom2.Document) Test(org.junit.Test)

Example 2 with Format

use of org.jdom2.output.Format in project pcgen by PCGen.

the class DiceBagModel method saveToFile.

/**
	 * <p>Saves the dicebag to the specified file as a UTF-8 xml file, with the format
	 * specified above in {@code loadFromFile()}</p>
	 *
	 * @param file File to save to.
	 */
void saveToFile(File file) {
    try {
        Document doc = new Document();
        saveToDocument(doc);
        XMLOutputter xmlOut = new XMLOutputter();
        xmlOut.setFormat(Format.getPrettyFormat());
        FileWriter fr = new FileWriter(file);
        xmlOut.output(doc, fr);
        fr.flush();
        fr.close();
        m_filePath = file.getPath();
        m_changed = false;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(GMGenSystem.inst, "File load error: " + file.getName());
        Logging.errorPrint("File Load Error" + file.getName());
        Logging.errorPrint(e.getMessage(), e);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) FileWriter(java.io.FileWriter) Document(org.jdom2.Document)

Example 3 with Format

use of org.jdom2.output.Format in project gocd by gocd.

the class GoControlLog method writeLogFile.

protected void writeLogFile(File file, Element element) throws IOException {
    // Write the log file out, let jdom care about the encoding by using
    // an OutputStream instead of a Writer.
    OutputStream logStream = null;
    try {
        Format format = Format.getPrettyFormat();
        XMLOutputter outputter = new XMLOutputter(format);
        IO.mkdirFor(file);
        file.setWritable(true);
        logStream = new BufferedOutputStream(new FileOutputStream(file));
        outputter.output(new Document(element), logStream);
    } finally {
        IO.close(logStream);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with Format

use of org.jdom2.output.Format in project archi by archimatetool.

the class JDOMUtils method write2XMLString.

/**
 * Convert a JDOM Document to a String format
 * @param doc The JDOM Document
 * @return The resulting String
 * @throws IOException
 */
public static String write2XMLString(Document doc) throws IOException {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    StringWriter out = new StringWriter();
    outputter.output(doc, out);
    out.close();
    return out.toString();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter)

Example 5 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class PaneProgFrameTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("programmer-config");
    doc = new Document(root);
    doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
    // add some elements
    root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "yes").setAttribute("showRosterMediaPane", "yes").addContent(new Element("pane").setAttribute("name", "Basic").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Start voltage")).addContent(new Element("display").setAttribute("item", "Normal direction of motion"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "checkbox")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "radiobuttons")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "Other").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Aggregations

Element (org.jdom2.Element)58 XMLOutputter (org.jdom2.output.XMLOutputter)22 Document (org.jdom2.Document)19 IOException (java.io.IOException)15 Format (org.jdom2.output.Format)10 StringWriter (java.io.StringWriter)9 Attribute (org.jdom2.Attribute)9 ArrayList (java.util.ArrayList)7 File (java.io.File)5 FileWriter (java.io.FileWriter)5 Test (org.junit.Test)5 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)5 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)5 JsonWriter (com.google.gson.stream.JsonWriter)4 Date (java.util.Date)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 JDOMException (org.jdom2.JDOMException)3 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2