Search in sources :

Example 66 with Text

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);
}
Also used : Element(org.jdom2.Element)

Example 67 with Text

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Document(org.jdom2.Document) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 68 with Text

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);
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 69 with Text

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);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom2.Document)

Example 70 with Text

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));
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Element (org.jdom2.Element)83 Document (org.jdom2.Document)36 File (java.io.File)21 ProcessingInstruction (org.jdom2.ProcessingInstruction)17 IOException (java.io.IOException)14 Text (org.jdom2.Text)12 Attribute (org.jdom2.Attribute)11 XMLOutputter (org.jdom2.output.XMLOutputter)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 XmlFile (jmri.jmrit.XmlFile)9 ArrayList (java.util.ArrayList)6 JDOMException (org.jdom2.JDOMException)6 StringWriter (java.io.StringWriter)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)5 FileOutputStream (java.io.FileOutputStream)4 LinkedHashMap (java.util.LinkedHashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 Locale (java.util.Locale)3