use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class VSDecoderPreferences method save.
public void save() {
if (prefFile == null) {
return;
}
XmlFile xf = new XmlFile() {
};
// odd syntax is due to XmlFile being abstract
xf.makeBackupFile(prefFile);
File file = new File(prefFile);
try {
//The file does not exist, create it before writing
File parentDir = file.getParentFile();
if (!parentDir.exists()) {
if (// make directory, check result
!parentDir.mkdir()) {
log.error("failed to make parent directory");
}
}
if (// create file, check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
} catch (Exception exp) {
log.error("Exception while writing the new VSDecoder preferences file, may not be complete: " + exp);
}
try {
Element root = new Element("vsdecoder-preferences");
//Document doc = XmlFile.newDocument(root, XmlFile.dtdLocation+"vsdecoder-preferences.dtd");
Document doc = XmlFile.newDocument(root);
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle.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+"throttles-preferences.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0,p);*/
root.setContent(store());
xf.writeXML(file, doc);
} catch (Exception ex) {
// TODO fix null value for Attribute
log.warn("Exception in storing vsdecoder preferences xml: " + ex);
}
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class LocationManagerXml 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-locations.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-locations.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
LocationManager.instance().store(root);
ScheduleManager.instance().store(root);
writeXML(file, doc);
// done - location file now stored, so can't be dirty
setDirty(false);
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class CarManagerXml 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-cars.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-cars.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// note all comments line feeds have been changed to processor directives
CarRoads.instance().store(root);
CarTypes.instance().store(root);
CarColors.instance().store(root);
CarLengths.instance().store(root);
CarOwners.instance().store(root);
CarLoads.instance().store(root);
CarManager.instance().store(root);
writeXML(file, doc);
// done - car file now stored, so can't be dirty
setDirty(false);
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class OptionsFile method writeDispatcherOptions.
/*
* Writes out Dispatcher options to a file in the user's preferences directory
*/
public void writeDispatcherOptions(DispatcherFrame f) throws java.io.IOException {
log.debug("Saving Dispatcher options to file {}", defaultFileName);
dispatcher = f;
root = new Element("dispatcheroptions");
doc = newDocument(root, dtdLocation + "dispatcher-options.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<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "dispatcheroptions.xsl");
org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// save Dispatcher Options in xml format
Element options = new Element("options");
LayoutEditor le = dispatcher.getLayoutEditor();
if (le != null) {
options.setAttribute("lename", le.getTitle());
}
options.setAttribute("useconnectivity", "" + (dispatcher.getUseConnectivity() ? "yes" : "no"));
options.setAttribute("trainsfromroster", "" + (dispatcher.getTrainsFromRoster() ? "yes" : "no"));
options.setAttribute("trainsfromtrains", "" + (dispatcher.getTrainsFromTrains() ? "yes" : "no"));
options.setAttribute("trainsfromuser", "" + (dispatcher.getTrainsFromUser() ? "yes" : "no"));
options.setAttribute("autoallocate", "" + (dispatcher.getAutoAllocate() ? "yes" : "no"));
options.setAttribute("autoturnouts", "" + (dispatcher.getAutoTurnouts() ? "yes" : "no"));
options.setAttribute("trustknownturnouts", "" + (dispatcher.getTrustKnownTurnouts() ? "yes" : "no"));
options.setAttribute("minthrottleinterval", "" + (dispatcher.getMinThrottleInterval()));
options.setAttribute("fullramptime", "" + (dispatcher.getFullRampTime()));
options.setAttribute("hasoccupancydetection", "" + (dispatcher.getHasOccupancyDetection() ? "yes" : "no"));
options.setAttribute("shortactivetrainnames", "" + (dispatcher.getShortActiveTrainNames() ? "yes" : "no"));
options.setAttribute("shortnameinblock", "" + (dispatcher.getShortNameInBlock() ? "yes" : "no"));
options.setAttribute("extracolorforallocated", "" + (dispatcher.getExtraColorForAllocated() ? "yes" : "no"));
options.setAttribute("nameinallocatedblock", "" + (dispatcher.getNameInAllocatedBlock() ? "yes" : "no"));
options.setAttribute("supportvsdecoder", "" + (dispatcher.getSupportVSDecoder() ? "yes" : "no"));
options.setAttribute("layoutscale", Scale.getShortScaleID(dispatcher.getScale()));
options.setAttribute("usescalemeters", "" + (dispatcher.getUseScaleMeters() ? "yes" : "no"));
options.setAttribute("userosterentryinblock", "" + (dispatcher.getRosterEntryInBlock() ? "yes" : "no"));
if (dispatcher.getSignalType() == 0x00) {
options.setAttribute("usesignaltype", "signalhead");
} else {
options.setAttribute("usesignaltype", "signalmast");
}
root.addContent(options);
// write out the file
try {
if (!checkFile(defaultFileName)) {
// file does not exist, create it
File file = new File(defaultFileName);
if (// create new file and check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
}
// write content to file
writeXML(findFile(defaultFileName), 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 ThrottlesPreferences method save.
public void save() {
if (prefFile == null) {
return;
}
XmlFile xf = new XmlFile() {
};
// odd syntax is due to XmlFile being abstract
xf.makeBackupFile(prefFile);
File file = new File(prefFile);
try {
//The file does not exist, create it before writing
File parentDir = file.getParentFile();
if (!parentDir.exists()) {
if (// make directory, check result
!parentDir.mkdir()) {
log.error("failed to make parent directory");
}
}
if (// create file, check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
} catch (Exception exp) {
log.error("Exception while writing the new throttles preferences file, may not be complete: " + exp);
}
try {
Element root = new Element("throttles-preferences");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttles-preferences.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle.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+"throttles-preferences.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0,p);*/
root.setContent(store());
xf.writeXML(file, doc);
} catch (Exception ex) {
log.warn("Exception in storing throttles preferences xml: " + ex);
}
this.dirty = false;
}
Aggregations