use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class SymbolicProgFrame method writeFile.
// dead class doesn't need this fixed right now
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION")
void writeFile() {
log.warn("SymbolicProgFrame writeFile invoked - is this still right, or should the LocoFile method be used?");
log.warn("Note use of VersionID attribute...");
try {
// get the file
int retVal = fco.showSaveDialog(this);
// handle selection or cancel
if (retVal != JFileChooser.APPROVE_OPTION) {
// leave early
return;
}
File file = fco.getSelectedFile();
// This is taken in large part from "Java and XML" page 368
// create root element
Element root = new Element("locomotive-config");
Document doc = jmri.jmrit.XmlFile.newDocument(root, jmri.jmrit.XmlFile.getDefaultDtdLocation() + "locomotive-config.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/locomotive.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", jmri.jmrit.XmlFile.xsltLocation + "locomotive.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// add top-level elements
Element values;
root.addContent(// locomotive values are first item
new Element("locomotive").setAttribute("roadNumber", locoRoadNumber.getText()).setAttribute("roadName", locoRoadName.getText()).setAttribute("mfg", locoMfg.getText()).setAttribute("model", locoModel.getText()).addContent(new Element("decoder").setAttribute("model", decoderModel.getText()).setAttribute("mfg", decoderMfg.getText()).setAttribute("versionID", "").setAttribute("mfgID", "")).addContent(values = new Element("values")));
// Append a decoderDef element to values
Element decoderDef;
values.addContent(decoderDef = new Element("decoderDef"));
// add the variable values to the decoderDef Element
for (int i = 0; i < variableModel.getRowCount(); i++) {
decoderDef.addContent(new Element("varValue").setAttribute("item", variableModel.getLabel(i)).setAttribute("value", variableModel.getValString(i)));
}
// add the CV values to the values Element
for (int i = 0; i < cvModel.getRowCount(); i++) {
values.addContent(new Element("CVvalue").setAttribute("name", cvModel.getName(i)).setAttribute("value", cvModel.getValString(i)));
}
// write the result to selected file
java.io.FileOutputStream o = new java.io.FileOutputStream(file);
try {
XMLOutputter fmt = new XMLOutputter();
fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.PRESERVE));
fmt.output(doc, o);
} finally {
o.close();
}
// mark file as OK
variableModel.setFileDirty(false);
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
}
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class PollingFile method prepare.
/**
* Initialize for writing information.
* <P>
* This is followed by multiple "set" calls, then a "store"
*/
public void prepare() {
root = new Element("rpsfile");
doc = newDocument(root, dtdLocation + "rpsroster-2-3-8.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/rpsroster.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "rpsroster.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class PositionFile method prepare.
/**
* Initialize for writing information.
* <P>
* This is followed by multiple "set" calls, then a "store"
*/
public void prepare() {
root = new Element("rpsfile");
doc = newDocument(root, dtdLocation + "rpsfile.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/rpsfile.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "rpsfile.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
}
use of org.jdom2.ProcessingInstruction 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.ProcessingInstruction 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);
}
}
Aggregations