Search in sources :

Example 96 with Document

use of org.apache.type_test.types1.Document in project JMRI by JMRI.

the class XmlFileTest method testWriteFile.

public void testWriteFile() throws java.io.IOException {
    XmlFile x = new XmlFile() {
    };
    // create a minimal XML file
    Element root = new Element("decoder-config");
    root.setAttribute("noNamespaceSchemaLocation", "http://jmri.org/xml/schema/decoder.xsd", org.jdom2.Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // write it out
    FileUtil.createDirectory("temp" + File.separator + "prefs");
    File f = new File("temp" + File.separator + "prefs" + File.separator + "test.xml");
    x.writeXML(f, doc);
    Assert.assertTrue("File expected to be present", f.exists());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) DocType(org.jdom2.DocType)

Example 97 with Document

use of org.apache.type_test.types1.Document in project JMRI by JMRI.

the class QualifierAdderTest method testSingleQualifierOk.

public void testSingleQualifierOk() {
    Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("one")).addContent(new Element("relation").addContent("eq")).addContent(new Element("value").addContent("3")));
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(e)));
    // test equal value qualifier
    processModifierElements(e, v2);
    v1.setIntValue(3);
    Assert.assertTrue("should be true for 3", v2.getAvailable());
    v1.setIntValue(5);
    Assert.assertFalse("should be false for 5", v2.getAvailable());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 98 with Document

use of org.apache.type_test.types1.Document in project JMRI by JMRI.

the class QualifierAdderTest method testExistsOk0.

public void testExistsOk0() {
    Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("none")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("0")));
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(e)));
    // test Exists
    processModifierElements(e, v2);
    Assert.assertTrue(v2.getAvailable());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 99 with Document

use of org.apache.type_test.types1.Document in project JMRI by JMRI.

the class ThrottlesPreferences method save.

public void save() {
    if (prefFile == null) {
        return;
    }
    XmlFile xf = new XmlFile() {
    };
    // odd syntax is due to XmlFile being abstract
    xf.makeBackupFile(prefFile);
    File file = new File(prefFile);
    try {
        //The file does not exist, create it before writing
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            if (// make directory, check result
            !parentDir.mkdir()) {
                log.error("failed to make parent directory");
            }
        }
        if (// create file, check result
        !file.createNewFile()) {
            log.error("createNewFile failed");
        }
    } catch (Exception exp) {
        log.error("Exception while writing the new throttles preferences file, may not be complete: " + exp);
    }
    try {
        Element root = new Element("throttles-preferences");
        Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttles-preferences.dtd");
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/throttle.xsl"?>
        /*TODO      java.util.Map<String,String> m = new java.util.HashMap<String,String>();
             m.put("type", "text/xsl");
             m.put("href", jmri.jmrit.XmlFile.xsltLocation+"throttles-preferences.xsl");
             ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
             doc.addContent(0,p);*/
        root.setContent(store());
        xf.writeXML(file, doc);
    } catch (Exception ex) {
        log.warn("Exception in storing throttles preferences xml: " + ex);
    }
    this.dirty = false;
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 100 with Document

use of org.apache.type_test.types1.Document in project JMRI by JMRI.

the class AbstractWiThrottlePreferences method save.

public void save() {
    if (fileName == null) {
        return;
    }
    XmlFile xmlFile = new XmlFile() {
    };
    xmlFile.makeBackupFile(fileName);
    File file = new File(fileName);
    try {
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            if (!parentDir.mkdir()) {
                log.warn("Could not create parent directory for prefs file :" + fileName);
                return;
            }
        }
        if (file.createNewFile()) {
            log.debug("Creating new WiThrottle prefs file: " + fileName);
        }
    } catch (Exception ea) {
        log.error("Could not create WiThrottle preferences file.");
    }
    try {
        Element root = new Element("withrottle-prefs");
        Document doc = XmlFile.newDocument(root);
        root.setContent(store());
        xmlFile.writeXML(file, doc);
    } catch (Exception eb) {
        log.warn("Exception in storing WiThrottle xml: " + eb);
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Aggregations

Document (org.jdom2.Document)109 Element (org.jdom2.Element)74 SAXBuilder (org.jdom2.input.SAXBuilder)34 File (java.io.File)32 Test (org.junit.Test)29 DocType (org.jdom2.DocType)23 IOException (java.io.IOException)22 XMLOutputter (org.jdom2.output.XMLOutputter)20 JDOMException (org.jdom2.JDOMException)14 ProcessingInstruction (org.jdom2.ProcessingInstruction)13 XmlFile (jmri.jmrit.XmlFile)11 Document (com.google.cloud.language.v1beta2.Document)10 ApiException (com.google.api.gax.grpc.ApiException)9 Document (com.google.cloud.language.v1.Document)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 FileOutputStream (java.io.FileOutputStream)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 ArrayList (java.util.ArrayList)7 EncodingType (com.google.cloud.language.v1.EncodingType)6