Search in sources :

Example 56 with Attribute

use of org.omegat.filters3.Attribute 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 57 with Attribute

use of org.omegat.filters3.Attribute 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 58 with Attribute

use of org.omegat.filters3.Attribute in project JMRI by JMRI.

the class EngineManager method load.

public void load(Element root) {
    // new format using elements starting version 3.3.1
    if (root.getChild(Xml.NEW_CONSISTS) != null) {
        @SuppressWarnings("unchecked") List<Element> consists = root.getChild(Xml.NEW_CONSISTS).getChildren(Xml.CONSIST);
        log.debug("Engine manager sees {} consists", consists.size());
        Attribute a;
        for (Element consist : consists) {
            if ((a = consist.getAttribute(Xml.NAME)) != null) {
                newConsist(a.getValue());
            }
        }
    } else // old format
    if (root.getChild(Xml.CONSISTS) != null) {
        String names = root.getChildText(Xml.CONSISTS);
        if (!names.equals(NONE)) {
            // NOI18N
            String[] consistNames = names.split("%%");
            log.debug("consists: {}", names);
            for (String name : consistNames) {
                newConsist(name);
            }
        }
    }
    if (root.getChild(Xml.ENGINES) != null) {
        @SuppressWarnings("unchecked") List<Element> engines = root.getChild(Xml.ENGINES).getChildren(Xml.ENGINE);
        log.debug("readFile sees {} engines", engines.size());
        for (Element e : engines) {
            register(new Engine(e));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 59 with Attribute

use of org.omegat.filters3.Attribute in project JMRI by JMRI.

the class TrainManifestText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.MANIFEST_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.MANIFEST_FOR_TRAIN) != null) {
        if ((a = emts.getChild(Xml.MANIFEST_FOR_TRAIN).getAttribute(Xml.TEXT)) != null) {
            setStringManifestForTrain(a.getValue());
        }
    }
    if (emts.getChild(Xml.VALID) != null) {
        if ((a = emts.getChild(Xml.VALID).getAttribute(Xml.TEXT)) != null) {
            setStringValid(a.getValue());
        }
    }
    if (emts.getChild(Xml.SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_DEPARTURE_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_DEPARTURE_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkDepartureTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_ARRIVAL_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_ARRIVAL_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkArrivalTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWorkWithRouteComment(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPART_TIME) != null) {
        if ((a = emts.getChild(Xml.DEPART_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringDepartTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsCars(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsLoads(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_TERMINATES) != null) {
        if ((a = emts.getChild(Xml.TRAIN_TERMINATES).getAttribute(Xml.TEXT)) != null) {
            setStringTrainTerminates(a.getValue());
        }
    }
    if (emts.getChild(Xml.DESTINATION) != null) {
        if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
            setStringDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.TO) != null) {
        if ((a = emts.getChild(Xml.TO).getAttribute(Xml.TEXT)) != null) {
            setStringTo(a.getValue());
        }
    }
    if (emts.getChild(Xml.FROM) != null) {
        if ((a = emts.getChild(Xml.FROM).getAttribute(Xml.TEXT)) != null) {
            setStringFrom(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEST) != null) {
        if ((a = emts.getChild(Xml.DEST).getAttribute(Xml.TEXT)) != null) {
            setStringDest(a.getValue());
        }
    }
    if (emts.getChild(Xml.FINAL_DEST) != null) {
        if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
            setStringFinalDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.ADD_HELPERS) != null) {
        if ((a = emts.getChild(Xml.ADD_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringAddHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.REMOVE_HELPERS) != null) {
        if ((a = emts.getChild(Xml.REMOVE_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringRemoveHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringCabooseChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoAndCabooseChange(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 60 with Attribute

use of org.omegat.filters3.Attribute in project JMRI by JMRI.

the class RosterEntry method loadFunctions.

/**
     * Loads function names from a JDOM element. Does not change values that are
     * already present!
     *
     * @param e3     the XML element containing the functions
     * @param source "family" if source is the decoder definition, or "model" if
     *               source is the roster entry itself
     */
public void loadFunctions(Element e3, String source) {
    /*Load flag once, means that when the roster entry is edited only the first set of function labels are displayed 
         ie those saved in the roster file, rather than those being left blank
         rather than being over-written by the defaults linked to the decoder def*/
    if (loadedOnce) {
        return;
    }
    if (e3 != null) {
        // load function names
        List<Element> l = e3.getChildren(RosterEntry.FUNCTION_LABEL);
        for (Element fn : l) {
            int num = Integer.parseInt(fn.getAttribute("num").getValue());
            String lock = fn.getAttribute("lockable").getValue();
            String val = fn.getText();
            if ((this.getFunctionLabel(num) == null) || (source.equalsIgnoreCase("model"))) {
                this.setFunctionLabel(num, val);
                this.setFunctionLockable(num, lock.equals("true"));
                Attribute a;
                if ((a = fn.getAttribute("functionImage")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionImage(num, null);
                        }
                    }
                }
                if ((a = fn.getAttribute("functionImageSelected")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionSelectedImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionSelectedImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionSelectedImage(num, null);
                        }
                    }
                }
            }
        }
    }
    if (source.equalsIgnoreCase("RosterEntry")) {
        loadedOnce = true;
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Attribute (org.jdom2.Attribute)148 Element (org.jdom2.Element)104 Document (org.jdom2.Document)18 ArrayList (java.util.ArrayList)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 Test (org.junit.Test)15 IOException (java.io.IOException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 List (java.util.List)9 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)7 Attribute (ucar.nc2.Attribute)7 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5