Search in sources :

Example 26 with JDOMException

use of org.jdom2.JDOMException in project JMRI by JMRI.

the class XmlFileTest method testReadFile.

public void testReadFile() throws org.jdom2.JDOMException, java.io.IOException {
    // ensure file present
    testWriteFile();
    // try to read
    XmlFile x = new XmlFile() {
    };
    // not a real file
    x.setValidate(XmlFile.Validate.None);
    Element e = x.rootFromName("temp" + File.separator + "prefs" + File.separator + "test.xml");
    Assert.assertTrue("Element found", e != null);
}
Also used : Element(org.jdom2.Element)

Example 27 with JDOMException

use of org.jdom2.JDOMException in project JMRI by JMRI.

the class XmlFileTest method testNotVoid.

public void testNotVoid() throws org.jdom2.JDOMException, java.io.IOException {
    // XmlFile is abstract, so can't check ctor directly; use local class
    XmlFile x = new XmlFile() {
    };
    // get Element from non-existant file
    try {
        Element e = x.rootFromFile(new File("nothingwerelikelytofind.xml"));
        Assert.assertTrue("Never returns void", e != null);
        Assert.assertTrue("Never returns if file not found", false);
    } catch (java.io.FileNotFoundException e) {
    /* OK, desired exit */
    }
}
Also used : Element(org.jdom2.Element) File(java.io.File)

Example 28 with JDOMException

use of org.jdom2.JDOMException in project JMRI by JMRI.

the class CarManagerXml method readFile.

/**
     * Read the contents of a roster XML file into this object. Note that this
     * does not clear any existing entries.
     */
@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;
    }
    CarRoads.instance().load(root);
    CarTypes.instance().load(root);
    CarColors.instance().load(root);
    CarLengths.instance().load(root);
    CarOwners.instance().load(root);
    CarLoads.instance().load(root);
    CarManager.instance().load(root);
    log.debug("Cars have been loaded!");
    RollingStockLogger.instance().enableCarLogging(Setup.isCarLoggerEnabled());
    // clear dirty bit
    setDirty(false);
    // clear location dirty flag, locations get modified during the loading of cars and locos
    LocationManagerXml.instance().setDirty(false);
}
Also used : Element(org.jdom2.Element)

Example 29 with JDOMException

use of org.jdom2.JDOMException in project JMRI by JMRI.

the class RouteManagerXml method readFile.

/**
     * Read the contents of a roster XML file into this object. Note that this
     * does not clear any existing entries.
     */
@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;
    }
    RouteManager.instance().load(root);
    // clear dirty bit
    setDirty(false);
}
Also used : Element(org.jdom2.Element)

Example 30 with JDOMException

use of org.jdom2.JDOMException in project JMRI by JMRI.

the class PaneProgFrame method loadProgrammerFile.

protected void loadProgrammerFile(RosterEntry r) {
    // Open and parse programmer file
    XmlFile pf = new XmlFile() {
    };
    // XmlFile is abstract
    try {
        programmerRoot = pf.rootFromName(filename);
        // get the showEmptyPanes attribute, if yes/no update our state
        if (programmerRoot.getChild("programmer").getAttribute("showEmptyPanes") != null) {
            if (log.isDebugEnabled()) {
                log.debug("Found in programmer " + programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue());
            }
            programmerShowEmptyPanes = programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue();
        } else {
            programmerShowEmptyPanes = "";
        }
        if (log.isDebugEnabled()) {
            log.debug("programmerShowEmptyPanes=" + programmerShowEmptyPanes);
        }
        // get extra any panes from the decoder file
        Attribute a;
        if ((a = programmerRoot.getChild("programmer").getAttribute("decoderFilePanes")) != null && a.getValue().equals("yes")) {
            if (decoderRoot != null) {
                decoderPaneList = decoderRoot.getChildren("pane");
            }
        }
        // load programmer config from programmer tree
        readConfig(programmerRoot, r);
    } catch (org.jdom2.JDOMException e) {
        log.error("exception parsing programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    } catch (java.io.IOException e) {
        log.error("exception reading programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Attribute(org.jdom2.Attribute)

Aggregations

Element (org.jdom2.Element)154 Document (org.jdom2.Document)113 JDOMException (org.jdom2.JDOMException)89 IOException (java.io.IOException)75 SAXBuilder (org.jdom2.input.SAXBuilder)67 Test (org.junit.Test)36 File (java.io.File)32 ArrayList (java.util.ArrayList)22 InputStream (java.io.InputStream)17 Attribute (org.jdom2.Attribute)16 StringReader (java.io.StringReader)15 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)14 HashMap (java.util.HashMap)13 XMLOutputter (org.jdom2.output.XMLOutputter)13 SAXException (org.xml.sax.SAXException)13 URL (java.net.URL)12 XmlFile (jmri.jmrit.XmlFile)12 List (java.util.List)11 MCRObject (org.mycore.datamodel.metadata.MCRObject)11 MCRException (org.mycore.common.MCRException)10