use of org.jdom2.Text in project JMRI by JMRI.
the class RouteManagerXml 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-routes.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-routes.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
RouteManager.instance().store(root);
writeXML(file, doc);
// done - route file now stored, so can't be dirty
setDirty(false);
}
use of org.jdom2.Text in project JMRI by JMRI.
the class StoreXmlVSDecoderAction method saveVSDecoderProfile.
public void saveVSDecoderProfile(java.io.File f) {
try {
Element root = new Element("VSDecoderConfig");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "vsdecoder-config.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle-layout-config.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 + "throttle-layout-config.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p); */
java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(5);
for (java.util.Iterator<VSDecoder> i = VSDecoderManager.instance().getVSDecoderList().iterator(); i.hasNext(); ) {
VSDecoder vsd = i.next();
children.add(vsd.getXml());
}
// Throttle-specific stuff below. Kept for reference
/*
// throttle list window
children.add(ThrottleFrameManager.instance().getThrottlesListPanel().getXml() );
// throttle windows
for (Iterator<ThrottleWindow> i = ThrottleFrameManager.instance().getThrottleWindows(); i.hasNext();) {
ThrottleWindow tw = i.next();
Element throttleElement = tw.getXml();
children.add(throttleElement);
}
*/
// End Throttle-specific stuff.
root.setContent(children);
FileOutputStream o = new java.io.FileOutputStream(f);
try {
XMLOutputter fmt = new XMLOutputter();
fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.PRESERVE));
fmt.output(doc, o);
} catch (IOException ex) {
log.warn("Exception in storing VSDecoder xml: " + ex);
} finally {
o.close();
}
} catch (FileNotFoundException ex) {
log.warn("Exception in storing VSDecoder xml: " + ex);
} catch (IOException ex) {
log.warn("Exception in storing VSDecoder xml: " + ex);
}
}
use of org.jdom2.Text in project JMRI by JMRI.
the class TrainInfoFile method writeTrainInfo.
/*
* Writes out Dispatcher options to a file in the user's preferences directory
*/
public void writeTrainInfo(TrainInfo tf, String name) throws java.io.IOException {
log.debug("entered writeTrainInfo");
root = new Element("traininfofile");
doc = newDocument(root, dtdLocation + "dispatcher-traininfo.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/block-values.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "dispatcher-traininfo.xsl");
org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// save Dispatcher TrainInfo in xml format
Element traininfo = new Element("traininfo");
traininfo.setAttribute("transitname", tf.getTransitName());
traininfo.setAttribute("trainname", tf.getTrainName());
traininfo.setAttribute("dccaddress", tf.getDCCAddress());
traininfo.setAttribute("trainintransit", "" + (tf.getTrainInTransit() ? "yes" : "no"));
traininfo.setAttribute("startblockname", tf.getStartBlockName());
traininfo.setAttribute("endblockname", tf.getDestinationBlockName());
traininfo.setAttribute("trainfromroster", "" + (tf.getTrainFromRoster() ? "yes" : "no"));
traininfo.setAttribute("trainfromtrains", "" + (tf.getTrainFromTrains() ? "yes" : "no"));
traininfo.setAttribute("trainfromuser", "" + (tf.getTrainFromUser() ? "yes" : "no"));
traininfo.setAttribute("priority", Integer.toString(tf.getPriority()));
traininfo.setAttribute("resetwhendone", "" + (tf.getResetWhenDone() ? "yes" : "no"));
switch(tf.getDelayedRestart()) {
case ActiveTrain.SENSORDELAY:
traininfo.setAttribute("delayedrestart", "sensor");
traininfo.setAttribute("delayedrestartsensor", tf.getRestartSensorName());
break;
case ActiveTrain.TIMEDDELAY:
traininfo.setAttribute("delayedrestart", "timed");
traininfo.setAttribute("delayedrestarttime", Integer.toString(tf.getRestartDelayMin()));
break;
default:
traininfo.setAttribute("delayedrestart", "no");
break;
}
traininfo.setAttribute("reverseatend", "" + (tf.getReverseAtEnd() ? "yes" : "no"));
if (tf.getDelayedStart() == ActiveTrain.TIMEDDELAY) {
traininfo.setAttribute("delayedstart", "timed");
} else if (tf.getDelayedStart() == ActiveTrain.SENSORDELAY) {
traininfo.setAttribute("delayedstart", "sensor");
if (tf.getDelaySensorName() != null) {
traininfo.setAttribute("delayedSensor", tf.getDelaySensorName());
}
}
traininfo.setAttribute("terminatewhendone", (tf.getTerminateWhenDone() ? "yes" : "no"));
traininfo.setAttribute("departuretimehr", Integer.toString(tf.getDepartureTimeHr()));
traininfo.setAttribute("departuretimemin", Integer.toString(tf.getDepartureTimeMin()));
traininfo.setAttribute("traintype", tf.getTrainType());
traininfo.setAttribute("autorun", "" + (tf.getAutoRun() ? "yes" : "no"));
traininfo.setAttribute("loadatstartup", "" + (tf.getLoadAtStartup() ? "yes" : "no"));
traininfo.setAttribute("allocatealltheway", "" + (tf.getAllocateAllTheWay() ? "yes" : "no"));
// here save items related to automatically running active trains
traininfo.setAttribute("speedfactor", Float.toString(tf.getSpeedFactor()));
traininfo.setAttribute("maxspeed", Float.toString(tf.getMaxSpeed()));
traininfo.setAttribute("ramprate", tf.getRampRate());
traininfo.setAttribute("resistancewheels", "" + (tf.getResistanceWheels() ? "yes" : "no"));
traininfo.setAttribute("runinreverse", "" + (tf.getRunInReverse() ? "yes" : "no"));
traininfo.setAttribute("sounddecoder", "" + (tf.getSoundDecoder() ? "yes" : "no"));
traininfo.setAttribute("maxtrainlength", Float.toString(tf.getMaxTrainLength()));
root.addContent(traininfo);
// write out the file
try {
if (!checkFile(fileLocation + name)) {
// file does not exist, create it
File file = new File(fileLocation + name);
if (// create file and check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
}
// write content to file
writeXML(findFile(fileLocation + name), doc);
} catch (java.io.IOException ioe) {
log.error("IO Exception " + ioe);
throw (ioe);
}
}
use of org.jdom2.Text in project JMRI by JMRI.
the class SlipTurnoutIconXml method storeIcon.
Element storeIcon(String elemName, NamedIcon icon, String text) {
Element element = super.storeIcon(elemName, icon);
element.addContent(new Element("text").addContent(text));
return element;
}
use of org.jdom2.Text 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