Search in sources :

Example 61 with Element

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

the class AutomationManager method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-trains.dtd.
     *
     * @param root Contents in a JDOM Element
     */
public void store(Element root) {
    Element values;
    root.addContent(values = new Element(Xml.AUTOMATIONS));
    // add entries
    for (Automation automation : getAutomationsByNameList()) {
        values.addContent(automation.store());
    }
}
Also used : Element(org.jdom2.Element)

Example 62 with Element

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

the class RollingStockAttribute method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-cars.dtd and operations-engines.dtd.
     * @param root Common Element for storage.
     * @param eNames New format Element group name
     * @param eName New format Element name
     * @param oldName Backwards compatibility Element name
     *
     */
public void store(Element root, String eNames, String eName, String oldName) {
    if (Control.backwardCompatible) {
        Element values = new Element(oldName);
        for (String name : getNames()) {
            // NOI18N
            values.addContent(name + "%%");
        }
        root.addContent(values);
    }
    // new format using elements
    Element names = new Element(eNames);
    for (String name : getNames()) {
        Element e = new Element(eName);
        if (eName.equals(Xml.LENGTH)) {
            e.setAttribute(new Attribute(Xml.VALUE, name));
        } else {
            e.setAttribute(new Attribute(Xml.NAME, name));
        }
        names.addContent(e);
    }
    root.addContent(names);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 63 with Element

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

the class RollingStockAttribute method load.

public void load(Element root, String eNames, String eName, String oldName) {
    // new format using elements starting version 3.3.1
    if (root.getChild(eNames) != null) {
        @SuppressWarnings("unchecked") List<Element> l = root.getChild(eNames).getChildren(eName);
        Attribute a;
        String[] names = new String[l.size()];
        for (int i = 0; i < l.size(); i++) {
            Element name = l.get(i);
            if ((a = name.getAttribute(Xml.NAME)) != null) {
                names[i] = a.getValue();
            }
            // lengths use "VALUE"
            if ((a = name.getAttribute(Xml.VALUE)) != null) {
                names[i] = a.getValue();
            }
        }
        setNames(names);
    } else // try old format
    if (root.getChild(oldName) != null) {
        // NOI18N
        String[] names = root.getChildText(oldName).split("%%");
        setNames(names);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 64 with Element

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

the class EngineManagerXml 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;
    }
    EngineModels.instance().load(root);
    EngineTypes.instance().load(root);
    EngineLengths.instance().load(root);
    EngineManager.instance().load(root);
    log.debug("Engines have been loaded!");
    RollingStockLogger.instance().enableEngineLogging(Setup.isEngineLoggerEnabled());
    // 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 65 with Element

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

the class EngineManagerXml 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-engines.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-engines.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    EngineModels.instance().store(root);
    EngineTypes.instance().store(root);
    EngineLengths.instance().store(root);
    EngineManager.instance().store(root);
    writeXML(file, doc);
    // done - engine file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)103 Document (org.jdom2.Document)64 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)28 IOException (java.io.IOException)27 DataConversionException (org.jdom2.DataConversionException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Editor (jmri.jmrit.display.Editor)22 DocType (org.jdom2.DocType)21 Turnout (jmri.Turnout)20 ProcessingInstruction (org.jdom2.ProcessingInstruction)16 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 SignalHead (jmri.SignalHead)15 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)15 Dimension (java.awt.Dimension)14