Search in sources :

Example 1 with Document

use of com.google.cloud.language.v1beta2.Document 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 Document

use of com.google.cloud.language.v1beta2.Document in project k-9 by k9mail.

the class SettingsExporterTest method exportPreferences_setsVersionToLatest.

@Test
public void exportPreferences_setsVersionToLatest() throws Exception {
    Document document = exportPreferences(false, Collections.<String>emptySet());
    assertEquals(Integer.toString(Settings.VERSION), document.getRootElement().getAttributeValue("version"));
}
Also used : Document(org.jdom2.Document) Test(org.junit.Test)

Example 3 with Document

use of com.google.cloud.language.v1beta2.Document in project k-9 by k9mail.

the class SettingsExporterTest method exportPreferences_ignoresGlobalSettingsWhenRequested.

@Test
public void exportPreferences_ignoresGlobalSettingsWhenRequested() throws Exception {
    Document document = exportPreferences(false, Collections.<String>emptySet());
    assertNull(document.getRootElement().getChild("global"));
}
Also used : Document(org.jdom2.Document) Test(org.junit.Test)

Example 4 with Document

use of com.google.cloud.language.v1beta2.Document in project pcgen by PCGen.

the class NameGenPanel method loadData.

private void loadData(File path) {
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        GeneratorDtdResolver resolver = new GeneratorDtdResolver(path);
        builder.setEntityResolver(resolver);
        for (File dataFile : dataFiles) {
            try {
                URL url = dataFile.toURI().toURL();
                Document nameSet = builder.build(url);
                DocType dt = nameSet.getDocType();
                if (dt.getElementName().equals("GENERATOR")) {
                    loadFromDocument(nameSet);
                }
            } catch (Exception e) {
                Logging.errorPrint(e.getMessage(), e);
                JOptionPane.showMessageDialog(this, "XML Error with file " + dataFile.getName());
            }
        }
        loadDropdowns();
    } else {
        JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document) File(java.io.File) URL(java.net.URL) DocType(org.jdom2.DocType) FileNotFoundException(java.io.FileNotFoundException) DataConversionException(org.jdom2.DataConversionException)

Example 5 with Document

use of com.google.cloud.language.v1beta2.Document 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)

Aggregations

Document (org.jdom2.Document)396 Element (org.jdom2.Element)244 Test (org.junit.Test)108 SAXBuilder (org.jdom2.input.SAXBuilder)89 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)23 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 MCRException (org.mycore.common.MCRException)21 HashMap (java.util.HashMap)20 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 StringReader (java.io.StringReader)18