use of org.jdom2.Text in project JMRI by JMRI.
the class OperationsSetupXml method readFile.
@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;
}
Setup.load(root);
// load manifest header text strings
TrainManifestHeaderText.load(root);
// load manifest text strings
TrainManifestText.load(root);
// load switch list text strings
TrainSwitchListText.load(root);
// load control settings
Control.load(root);
}
use of org.jdom2.Text in project JMRI by JMRI.
the class ConfigXmlManager method finalStore.
protected boolean finalStore(Element root, File file) {
try {
// Document doc = newDocument(root, dtdLocation+"layout-config-"+dtdVersion+".dtd");
Document doc = newDocument(root);
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/panelfile"+schemaVersion+".xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "panelfile" + schemaVersion + ".xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// add version at front
storeVersion(root);
writeXML(file, doc);
} catch (java.io.FileNotFoundException ex3) {
storingErrorEncountered(null, "storing to file " + file.getName(), "File not found " + file.getName(), null, null, ex3);
log.error("FileNotFound error writing file: " + ex3.getLocalizedMessage());
return false;
} catch (java.io.IOException ex2) {
storingErrorEncountered(null, "storing to file " + file.getName(), "IO error writing file " + file.getName(), null, null, ex2);
log.error("IO error writing file: " + ex2.getLocalizedMessage());
return false;
}
return true;
}
use of org.jdom2.Text in project JMRI by JMRI.
the class ThrottleFrame method saveThrottle.
private void saveThrottle(String sfile) {
// Save throttle: title / window position
// as strongly linked to extended throttles and roster presence, do not save function buttons and background window as they're stored in the roster entry
XmlFile xf = new XmlFile() {
};
// odd syntax is due to XmlFile being abstract
xf.makeBackupFile(sfile);
File file = new File(sfile);
try {
//The file does not exist, create it before writing
File parentDir = file.getParentFile();
if (!parentDir.exists()) {
if (// make directory and check result
!parentDir.mkdir()) {
log.error("could not make parent directory");
}
}
if (// create file, check success
!file.createNewFile()) {
log.error("createNewFile failed");
}
} catch (Exception exp) {
log.error("Exception while writing the throttle file, may not be complete: " + exp);
}
try {
Element root = new Element("throttle-config");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttle-config.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle.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+"throttle.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0,p);*/
Element throttleElement = getXml();
// throttleElement.getChild("AddressPanel").removeChild("locoaddress");
if (// don't save function buttons labels, they're in roster entry
(this.getRosterEntry() != null) && (getDefaultThrottleFolder() + addressPanel.getRosterEntry().getId().trim() + ".xml").compareTo(sfile) == 0) {
throttleElement.getChild("FunctionPanel").removeChildren("FunctionButton");
}
root.setContent(throttleElement);
xf.writeXML(file, doc);
setLastUsedSaveFile(sfile);
} catch (Exception ex) {
log.warn("Exception while storing throttle xml: " + ex);
}
}
use of org.jdom2.Text in project JMRI by JMRI.
the class StoreXmlThrottlesLayoutAction method saveThrottlesLayout.
public void saveThrottlesLayout(java.io.File f) {
try {
Element root = new Element("throttle-layout-config");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttle-layout-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);
// 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);
}
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 throttle xml: " + ex);
} finally {
o.close();
}
} catch (FileNotFoundException ex) {
log.warn("Exception in storing throttle xml: " + ex);
} catch (IOException ex) {
log.warn("Exception in storing throttle xml: " + ex);
}
}
use of org.jdom2.Text in project gocd by gocd.
the class SvnCommandRemoteTest method shouldMaskPassword_remoteInfo.
@Test
public void shouldMaskPassword_remoteInfo() {
try {
badUserNameCommand().remoteInfo(new SAXBuilder());
fail("should have failed");
} catch (Exception e) {
assertThat("Plain text password detected!", e.getMessage().contains(HARRYS_PASSWORD), Is.is(false));
}
try {
badPasswordCommand().remoteInfo(new SAXBuilder());
fail("should have failed");
} catch (Exception e) {
assertThat("Plain text password detected!", e.getMessage().contains("some_bad_password"), Is.is(false));
}
try {
badUrlCommand().remoteInfo(new SAXBuilder());
fail("should have failed");
} catch (Exception e) {
assertThat("Plain text password detected!", e.getMessage().contains(HARRYS_PASSWORD), Is.is(false));
}
}
Aggregations