use of org.jdom2.Element in project JMRI by JMRI.
the class AutomationManager method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-trains.dtd.
*
* @param root Contents in a JDOM Element
*/
public void store(Element root) {
Element values;
root.addContent(values = new Element(Xml.AUTOMATIONS));
// add entries
for (Automation automation : getAutomationsByNameList()) {
values.addContent(automation.store());
}
}
use of org.jdom2.Element in project JMRI by JMRI.
the class RollingStockAttribute method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-cars.dtd and operations-engines.dtd.
* @param root Common Element for storage.
* @param eNames New format Element group name
* @param eName New format Element name
* @param oldName Backwards compatibility Element name
*
*/
public void store(Element root, String eNames, String eName, String oldName) {
if (Control.backwardCompatible) {
Element values = new Element(oldName);
for (String name : getNames()) {
// NOI18N
values.addContent(name + "%%");
}
root.addContent(values);
}
// new format using elements
Element names = new Element(eNames);
for (String name : getNames()) {
Element e = new Element(eName);
if (eName.equals(Xml.LENGTH)) {
e.setAttribute(new Attribute(Xml.VALUE, name));
} else {
e.setAttribute(new Attribute(Xml.NAME, name));
}
names.addContent(e);
}
root.addContent(names);
}
use of org.jdom2.Element in project JMRI by JMRI.
the class RollingStockAttribute method load.
public void load(Element root, String eNames, String eName, String oldName) {
// new format using elements starting version 3.3.1
if (root.getChild(eNames) != null) {
@SuppressWarnings("unchecked") List<Element> l = root.getChild(eNames).getChildren(eName);
Attribute a;
String[] names = new String[l.size()];
for (int i = 0; i < l.size(); i++) {
Element name = l.get(i);
if ((a = name.getAttribute(Xml.NAME)) != null) {
names[i] = a.getValue();
}
// lengths use "VALUE"
if ((a = name.getAttribute(Xml.VALUE)) != null) {
names[i] = a.getValue();
}
}
setNames(names);
} else // try old format
if (root.getChild(oldName) != null) {
// NOI18N
String[] names = root.getChildText(oldName).split("%%");
setNames(names);
}
}
use of org.jdom2.Element in project JMRI by JMRI.
the class EngineManagerXml 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;
}
EngineModels.instance().load(root);
EngineTypes.instance().load(root);
EngineLengths.instance().load(root);
EngineManager.instance().load(root);
log.debug("Engines have been loaded!");
RollingStockLogger.instance().enableEngineLogging(Setup.isEngineLoggerEnabled());
// 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.Element in project JMRI by JMRI.
the class EngineManagerXml method writeFile.
@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
log.debug("writeFile {}", name);
// This is taken in large part from "Java and XML" page 368
File file = findFile(name);
if (file == null) {
file = new File(name);
}
// create root element
// NOI18N
Element root = new Element("operations-config");
// NOI18N
Document doc = newDocument(root, dtdLocation + "operations-engines.dtd");
// add XSLT processing instruction
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
// NOI18N
m.put("type", "text/xsl");
// NOI18N
m.put("href", xsltLocation + "operations-engines.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
EngineModels.instance().store(root);
EngineTypes.instance().store(root);
EngineLengths.instance().store(root);
EngineManager.instance().store(root);
writeXML(file, doc);
// done - engine file now stored, so can't be dirty
setDirty(false);
}
Aggregations