use of org.jdom2.JDOMException in project JMRI by JMRI.
the class XmlFileTest method testReadFile.
public void testReadFile() throws org.jdom2.JDOMException, java.io.IOException {
// ensure file present
testWriteFile();
// try to read
XmlFile x = new XmlFile() {
};
// not a real file
x.setValidate(XmlFile.Validate.None);
Element e = x.rootFromName("temp" + File.separator + "prefs" + File.separator + "test.xml");
Assert.assertTrue("Element found", e != null);
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class XmlFileTest method testNotVoid.
public void testNotVoid() throws org.jdom2.JDOMException, java.io.IOException {
// XmlFile is abstract, so can't check ctor directly; use local class
XmlFile x = new XmlFile() {
};
// get Element from non-existant file
try {
Element e = x.rootFromFile(new File("nothingwerelikelytofind.xml"));
Assert.assertTrue("Never returns void", e != null);
Assert.assertTrue("Never returns if file not found", false);
} catch (java.io.FileNotFoundException e) {
/* OK, desired exit */
}
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class CarManagerXml method readFile.
/**
* Read the contents of a roster XML file into this object. Note that this
* does not clear any existing entries.
*/
@Override
public void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
// suppress rootFromName(name) warning message by checking to see if file exists
if (findFile(name) == null) {
log.debug("{} file could not be found", name);
return;
}
// find root
Element root = rootFromName(name);
if (root == null) {
log.debug("{} file could not be read", name);
return;
}
CarRoads.instance().load(root);
CarTypes.instance().load(root);
CarColors.instance().load(root);
CarLengths.instance().load(root);
CarOwners.instance().load(root);
CarLoads.instance().load(root);
CarManager.instance().load(root);
log.debug("Cars have been loaded!");
RollingStockLogger.instance().enableCarLogging(Setup.isCarLoggerEnabled());
// clear dirty bit
setDirty(false);
// clear location dirty flag, locations get modified during the loading of cars and locos
LocationManagerXml.instance().setDirty(false);
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class RouteManagerXml method readFile.
/**
* Read the contents of a roster XML file into this object. Note that this
* does not clear any existing entries.
*/
@Override
public void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
// suppress rootFromName(name) warning message by checking to see if file exists
if (findFile(name) == null) {
log.debug("{} file could not be found", name);
return;
}
// find root
Element root = rootFromName(name);
if (root == null) {
log.debug("{} file could not be read", name);
return;
}
RouteManager.instance().load(root);
// clear dirty bit
setDirty(false);
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class PaneProgFrame method loadProgrammerFile.
protected void loadProgrammerFile(RosterEntry r) {
// Open and parse programmer file
XmlFile pf = new XmlFile() {
};
// XmlFile is abstract
try {
programmerRoot = pf.rootFromName(filename);
// get the showEmptyPanes attribute, if yes/no update our state
if (programmerRoot.getChild("programmer").getAttribute("showEmptyPanes") != null) {
if (log.isDebugEnabled()) {
log.debug("Found in programmer " + programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue());
}
programmerShowEmptyPanes = programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue();
} else {
programmerShowEmptyPanes = "";
}
if (log.isDebugEnabled()) {
log.debug("programmerShowEmptyPanes=" + programmerShowEmptyPanes);
}
// get extra any panes from the decoder file
Attribute a;
if ((a = programmerRoot.getChild("programmer").getAttribute("decoderFilePanes")) != null && a.getValue().equals("yes")) {
if (decoderRoot != null) {
decoderPaneList = decoderRoot.getChildren("pane");
}
}
// load programmer config from programmer tree
readConfig(programmerRoot, r);
} catch (org.jdom2.JDOMException e) {
log.error("exception parsing programmer file: " + filename, e);
// provide traceback too
e.printStackTrace();
} catch (java.io.IOException e) {
log.error("exception reading programmer file: " + filename, e);
// provide traceback too
e.printStackTrace();
}
}
Aggregations