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());
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations