use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class XmlFile method processOneInstruction.
Document processOneInstruction(ProcessingInstruction p, Document doc) throws org.jdom2.transform.XSLTransformException, org.jdom2.JDOMException, java.io.IOException {
log.trace("handling ", p);
// check target
String target = p.getTarget();
if (!target.equals("transform-xslt")) {
return doc;
}
String href = p.getPseudoAttributeValue("href");
// we expect this to start with http://jmri.org/ and refer to the JMRI file tree
if (!href.startsWith("http://jmri.org/")) {
return doc;
}
href = href.substring(16);
// if starts with 'xml/' we remove that; findFile will put it back
if (href.startsWith("xml/")) {
href = href.substring(4);
}
// read the XSLT transform into a Document to get XInclude done
SAXBuilder builder = getBuilder(Validate.None);
Document xdoc = builder.build(new BufferedInputStream(new FileInputStream(findFile(href))));
org.jdom2.transform.XSLTransformer transformer = new org.jdom2.transform.XSLTransformer(xdoc);
return transformer.transform(doc);
}
use of org.jdom2.ProcessingInstruction 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.ProcessingInstruction 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);
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class OperationsSetupXml 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-config.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-config.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// add top-level elements
root.addContent(Setup.store());
// add manifest header text strings
root.addContent(TrainManifestHeaderText.store());
// add manifest text strings
root.addContent(TrainManifestText.store());
// add switch list text strings
root.addContent(TrainSwitchListText.store());
// add control elements
root.addContent(Control.store());
writeXML(file, doc);
// done, so can't be dirty
setDirty(false);
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class TrainManagerXml 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-trains.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-trains.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
TrainManager.instance().store(root);
TrainScheduleManager.instance().store(root);
AutomationManager.instance().store(root);
writeXML(file, doc);
// done - train file now stored, so can't be dirty
setDirty(false);
}
Aggregations