use of org.jdom2.JDOMException in project JMRI by JMRI.
the class WarrantPreferences method openFile.
public void openFile(String name) {
_fileName = name;
WarrantPreferencesXml prefsXml = new WarrantPreferencesXml();
File file = new File(_fileName);
Element root;
try {
root = prefsXml.rootFromFile(file);
} catch (java.io.FileNotFoundException ea) {
log.debug("Could not find Warrant preferences file. Normal if preferences have not been saved before.");
root = null;
} catch (IOException | JDOMException eb) {
log.error("Exception while loading warrant preferences: " + eb);
root = null;
}
if (root != null) {
// log.info("Found Warrant preferences file: {}", _fileName);
loadLayoutParams(root.getChild(LAYOUT_PARAMS));
if (!loadSpeedMap(root.getChild(SPEED_MAP_PARAMS))) {
loadSpeedMapFromOldXml();
log.error("Unable to read ramp parameters. Setting to default values.");
}
} else {
loadSpeedMapFromOldXml();
}
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class Roster method readFile.
/**
* Read the contents of a roster XML file into this object.
* <P>
* Note that this does not clear any existing entries.
*
* @param name filename of roster file
*/
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
// roster exists?
if (!(new File(name)).exists()) {
log.debug("no roster file found; this is normal if you haven't put decoders in your roster yet");
return;
}
// find root
Element root = rootFromName(name);
if (root == null) {
log.error("Roster file exists, but could not be read; roster not available");
return;
}
// decode type, invoke proper processing routine if a decoder file
if (root.getChild("roster") != null) {
// NOI18N
// NOI18N
List<Element> l = root.getChild("roster").getChildren("locomotive");
if (log.isDebugEnabled()) {
log.debug("readFile sees " + l.size() + " children");
}
l.stream().forEach((e) -> {
addEntry(new RosterEntry(e));
});
//any <?p?> processor directives and change them to back \n characters
synchronized (_list) {
_list.stream().map((entry) -> {
//Extract the Comment field and create a new string for output
String tempComment = entry.getComment();
String xmlComment = "";
//characters in tempComment.
for (int k = 0; k < tempComment.length(); k++) {
if (tempComment.startsWith("<?p?>", k)) {
// NOI18N
// NOI18N
xmlComment = xmlComment + "\n";
k = k + 4;
} else {
xmlComment = xmlComment + tempComment.substring(k, k + 1);
}
}
entry.setComment(xmlComment);
return entry;
}).forEachOrdered((r) -> {
//Now do the same thing for the decoderComment field
String tempDecoderComment = r.getDecoderComment();
String xmlDecoderComment = "";
for (int k = 0; k < tempDecoderComment.length(); k++) {
if (tempDecoderComment.startsWith("<?p?>", k)) {
// NOI18N
// NOI18N
xmlDecoderComment = xmlDecoderComment + "\n";
k = k + 4;
} else {
xmlDecoderComment = xmlDecoderComment + tempDecoderComment.substring(k, k + 1);
}
}
r.setDecoderComment(xmlDecoderComment);
});
}
} else {
log.error("Unrecognized roster file contents in file: " + name);
}
if (root.getChild("rosterGroup") != null) {
// NOI18N
// NOI18N
List<Element> groups = root.getChild("rosterGroup").getChildren("group");
groups.stream().forEach((group) -> {
addRosterGroup(group.getText());
});
}
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class NameFile method readFile.
/**
* Read the contents of a NameFile XML file into this object. Note that this
* does not clear any existing entries.
*/
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
if (log.isDebugEnabled()) {
log.debug("readFile " + name);
}
// read file, find root
Element root = rootFromName(name);
// decode type, invoke proper processing routine
readNames(root);
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class LoadXmlThrottlesLayoutAction method loadThrottlesLayout.
/**
* Parse the XML file and create ThrottleFrames. Returns true if throttle
* loaded successfully.
*
* @param f The XML file containing throttles.
*/
@SuppressWarnings("unchecked")
public boolean loadThrottlesLayout(java.io.File f) throws java.io.IOException {
try {
ThrottlePrefs prefs = new ThrottlePrefs();
Element root = prefs.rootFromFile(f);
List<Element> throttles = root.getChildren("ThrottleFrame");
if ((throttles != null) && (throttles.size() > 0)) {
// OLD FORMAT
for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
tf.setXml(i.next());
tf.toFront();
}
} else {
throttles = root.getChildren("ThrottleWindow");
for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
ThrottleWindow tw = ThrottleFrameManager.instance().createThrottleWindow();
tw.setXml(i.next());
tw.setVisible(true);
}
Element tlp = root.getChild("ThrottlesListPanel");
if (tlp != null) {
ThrottleFrameManager.instance().getThrottlesListPanel().setXml(tlp);
}
}
} catch (org.jdom2.JDOMException ex) {
log.warn("Loading Throttles exception", ex);
return false;
}
return true;
}
use of org.jdom2.JDOMException in project JMRI by JMRI.
the class LoadXmlVSDecoderAction method loadVSDecoderProfile.
/**
* Parse the XML file and create ThrottleFrames. Returns true if throttle
* loaded successfully.
*
* @param f The XML file containing throttles.
*/
public boolean loadVSDecoderProfile(java.io.File f) throws java.io.IOException {
try {
VSDecoderPrefs prefs = new VSDecoderPrefs();
Element root = prefs.rootFromFile(f);
// WARNING: This may be out of sync with the Store... the root element is <VSDecoderConfig>
// not sure, must investigate. See what XmlFile.rootFromFile(f) does...
List<Element> profiles = root.getChildren("VSDecoder");
if ((profiles != null) && (profiles.size() > 0)) {
// Create a new VSDecoder object for each Profile in the XML file.
for (java.util.Iterator<Element> i = profiles.iterator(); i.hasNext(); ) {
Element e = i.next();
log.debug(e.toString());
//VSDecoder vsd = VSDecoderManager.instance().getVSDecoder(e.getAttribute("name").getValue(), f.getPath());
}
}
} catch (org.jdom2.JDOMException ex) {
log.warn("Loading VSDecoder Profile exception", ex);
return false;
}
return true;
}
Aggregations