Search in sources :

Example 91 with Attribute

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

the class AbstractServerPreferences method load.

public void load(Element child) {
    Attribute a;
    a = child.getAttribute(PORT);
    if (a != null) {
        try {
            this.setPort(a.getIntValue());
            this.asLoadedPort = this.getPort();
        } catch (DataConversionException e) {
            this.setPort(getDefaultPort());
            log.error("Unable to read port. Setting to default value.", e);
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 92 with Attribute

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

the class DecoderIndexFile method readFamily.

@SuppressWarnings("unchecked")
void readFamily(Element family) {
    Attribute attr;
    String filename = family.getAttribute("file").getValue();
    String parentLowVersID = ((attr = family.getAttribute("lowVersionID")) != null ? attr.getValue() : null);
    String parentHighVersID = ((attr = family.getAttribute("highVersionID")) != null ? attr.getValue() : null);
    String replacementFamilyName = ((attr = family.getAttribute("replacementFamily")) != null ? attr.getValue() : null);
    String familyName = ((attr = family.getAttribute("name")) != null ? attr.getValue() : null);
    String mfg = ((attr = family.getAttribute("mfg")) != null ? attr.getValue() : null);
    String developer = ((attr = family.getAttribute("developerID")) != null ? attr.getValue() : null);
    String mfgID = null;
    if (mfg != null) {
        mfgID = mfgIdFromName(mfg);
    } else {
        log.error("Did not find required mfg attribute, may not find proper manufacturer");
    }
    List<Element> l = family.getChildren("model");
    if (log.isDebugEnabled()) {
        log.trace("readFamily sees " + l.size() + " children");
    }
    Element modelElement;
    if (l.size() <= 0) {
        log.error("Did not find at least one model in the " + familyName + " family");
        modelElement = null;
    } else {
        modelElement = l.get(0);
    }
    // Record the family as a specific model, which allows you to select the
    // family as a possible thing to program
    DecoderFile vFamilyDecoderFile = new DecoderFile(mfg, mfgID, familyName, parentLowVersID, parentHighVersID, familyName, filename, (developer != null) ? developer : "-1", -1, -1, modelElement, replacementFamilyName, // numFns, numOuts, XML element equal
    replacementFamilyName);
    // to the first decoder
    decoderList.add(vFamilyDecoderFile);
    // record each of the decoders
    for (int i = 0; i < l.size(); i++) {
        // handle each entry by creating a DecoderFile object containing all it knows
        Element decoder = l.get(i);
        String loVersID = ((attr = decoder.getAttribute("lowVersionID")) != null ? attr.getValue() : parentLowVersID);
        String hiVersID = ((attr = decoder.getAttribute("highVersionID")) != null ? attr.getValue() : parentHighVersID);
        String replacementModelName = ((attr = decoder.getAttribute("replacementModel")) != null ? attr.getValue() : null);
        replacementFamilyName = ((attr = decoder.getAttribute("replacementFamily")) != null ? attr.getValue() : replacementFamilyName);
        int numFns = ((attr = decoder.getAttribute("numFns")) != null ? Integer.parseInt(attr.getValue()) : -1);
        int numOuts = ((attr = decoder.getAttribute("numOuts")) != null ? Integer.parseInt(attr.getValue()) : -1);
        String devId = ((attr = decoder.getAttribute("developerId")) != null ? attr.getValue() : "-1");
        DecoderFile df = new DecoderFile(mfg, mfgID, ((attr = decoder.getAttribute("model")) != null ? attr.getValue() : null), loVersID, hiVersID, familyName, filename, devId, numFns, numOuts, decoder, replacementModelName, replacementFamilyName);
        // and store it
        decoderList.add(df);
        // if there are additional version numbers defined, handle them too
        List<Element> vcodes = decoder.getChildren("versionCV");
        for (int j = 0; j < vcodes.size(); j++) {
            // for each versionCV element
            Element vcv = vcodes.get(j);
            String vLoVersID = ((attr = vcv.getAttribute("lowVersionID")) != null ? attr.getValue() : loVersID);
            String vHiVersID = ((attr = vcv.getAttribute("highVersionID")) != null ? attr.getValue() : hiVersID);
            df.setVersionRange(vLoVersID, vHiVersID);
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 93 with Attribute

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

the class DecoderIndexFile method readMfgSection.

@SuppressWarnings("unchecked")
void readMfgSection(Element decoderIndex) {
    Element mfgList = decoderIndex.getChild("mfgList");
    if (mfgList != null) {
        Attribute a;
        a = mfgList.getAttribute("nmraListDate");
        if (a != null) {
            nmraListDate = a.getValue();
        }
        a = mfgList.getAttribute("updated");
        if (a != null) {
            updated = a.getValue();
        }
        a = mfgList.getAttribute("lastadd");
        if (a != null) {
            lastAdd = a.getValue();
        }
        List<Element> l = mfgList.getChildren("manufacturer");
        if (log.isDebugEnabled()) {
            log.debug("readMfgSection sees " + l.size() + " children");
        }
        for (int i = 0; i < l.size(); i++) {
            // handle each entry
            Element el = l.get(i);
            String mfg = el.getAttribute("mfg").getValue();
            mMfgNameList.add(mfg);
            Attribute attr = el.getAttribute("mfgID");
            if (attr != null) {
                _mfgIdFromNameHash.put(mfg, attr.getValue());
                _mfgNameFromIdHash.put(attr.getValue(), mfg);
            }
        }
    } else {
        log.warn("no mfgList found in decoderIndexFile");
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 94 with Attribute

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

the class ConsistFile method consistFromXml.

/**
     * Load a Consist from the consist elements in the file.
     *
     * @param consist a JDOM element containing a consist
     */
@SuppressWarnings("unchecked")
private void consistFromXml(Element consist) {
    Attribute type, cnumber, isCLong, cID;
    Consist newConsist;
    // Read the consist address from the file and create the
    // consisit in memory if it doesn't exist already.
    cnumber = consist.getAttribute("consistNumber");
    isCLong = consist.getAttribute("longAddress");
    DccLocoAddress consistAddress;
    if (isCLong != null) {
        log.debug("adding consist {} with longAddress set to {}.", cnumber, isCLong.getValue());
        try {
            int number = Integer.parseInt(cnumber.getValue());
            consistAddress = new DccLocoAddress(number, isCLong.getValue().equals("yes"));
        } catch (NumberFormatException e) {
            log.debug("Consist number not an integer");
            return;
        }
    } else {
        log.debug("adding consist {} with default long address setting.", cnumber);
        consistAddress = new DccLocoAddress(Integer.parseInt(cnumber.getValue()), false);
    }
    newConsist = consistMan.getConsist(consistAddress);
    if (!(newConsist.getConsistList().isEmpty())) {
        log.debug("Consist {} is not empty.  Using version in memory.", consistAddress.toString());
        return;
    }
    // read and set the consist type
    type = consist.getAttribute("type");
    if (type != null) {
        // use the value read from the file
        newConsist.setConsistType((type.getValue().equals("CSAC")) ? Consist.CS_CONSIST : Consist.ADVANCED_CONSIST);
    } else {
        // use the default (DAC)
        newConsist.setConsistType(Consist.ADVANCED_CONSIST);
    }
    // Read the consist ID from the file;
    cID = consist.getAttribute("id");
    if (cID != null) {
        // use the value read from the file
        newConsist.setConsistID(cID.getValue());
    }
    // read each child of locomotive in the consist from the file
    // and restore it's information to memory.
    Iterator<Element> childIterator = consist.getDescendants(new ElementFilter("loco"));
    try {
        Element e;
        do {
            e = childIterator.next();
            Attribute number, isLong, direction, position, rosterId;
            number = e.getAttribute("dccLocoAddress");
            isLong = e.getAttribute("longAddress");
            direction = e.getAttribute("locoDir");
            position = e.getAttribute("locoName");
            rosterId = e.getAttribute("locoRosterId");
            log.debug("adding Loco {}", number);
            // Use restore so we DO NOT cause send any commands
            // to the command station as we recreate the consist.
            DccLocoAddress address;
            if (isLong != null && direction != null) {
                // use the values from the file
                log.debug("using direction from file {}", direction.getValue());
                address = new DccLocoAddress(Integer.parseInt(number.getValue()), isLong.getValue().equals("yes"));
                newConsist.restore(address, direction.getValue().equals("normal"));
            } else if (isLong == null && direction != null) {
                // use the direction from the file
                // but set as long address
                log.debug("using direction from file {}", direction.getValue());
                address = new DccLocoAddress(Integer.parseInt(number.getValue()), true);
                newConsist.restore(address, direction.getValue().equals("normal"));
            } else if (isLong != null && direction == null) {
                // use the default direction
                // but the long/short value from the file
                address = new DccLocoAddress(Integer.parseInt(number.getValue()), isLong.getValue().equals("yes"));
                newConsist.restore(address, true);
            } else {
                // use the default values long address
                // and normal direction
                address = new DccLocoAddress(Integer.parseInt(number.getValue()), true);
                newConsist.restore(address, true);
            }
            if (position != null && !position.getValue().equals("mid")) {
                if (position.getValue().equals("lead")) {
                    newConsist.setPosition(address, Consist.POSITION_LEAD);
                } else if (position.getValue().equals("rear")) {
                    newConsist.setPosition(address, Consist.POSITION_TRAIL);
                }
            } else {
                Attribute midNumber = e.getAttribute("locoMidNumber");
                if (midNumber != null) {
                    int pos = Integer.parseInt(midNumber.getValue());
                    newConsist.setPosition(address, pos);
                }
            }
            if (rosterId != null) {
                newConsist.setRosterId(address, rosterId.getValue());
            }
        } while (true);
    } catch (NoSuchElementException nse) {
        log.debug("end of loco list");
    }
}
Also used : Attribute(org.jdom2.Attribute) Consist(jmri.Consist) ElementFilter(org.jdom2.filter.ElementFilter) Element(org.jdom2.Element) NoSuchElementException(java.util.NoSuchElementException) DccLocoAddress(jmri.DccLocoAddress)

Example 95 with Attribute

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

the class RpsPositionIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = (Editor) o;
    RpsPositionIcon l = new RpsPositionIcon(ed);
    // create the objects
    String name = element.getAttribute("active").getValue();
    NamedIcon active = NamedIcon.getIconByName(name);
    if (active == null) {
        active = ed.loadFailed("RpsPositionIcon: icon \"active\" ", name);
        if (active == null) {
            log.info("RpsPositionIcon: icon \"active\" removed for url= " + name);
            return;
        }
    }
    l.setActiveIcon(active);
    name = element.getAttribute("error").getValue();
    NamedIcon error = NamedIcon.getIconByName(name);
    if (error == null) {
        error = ed.loadFailed("RpsPositionIcon: icon \"error\" ", name);
        if (error == null) {
            log.info("RpsPositionIcon: \"error\" removed for url= " + name);
            return;
        }
    }
    l.setErrorIcon(error);
    try {
        Attribute a = element.getAttribute("rotate");
        if (a != null) {
            int rotation = element.getAttribute("rotate").getIntValue();
            active.setRotation(rotation, l);
            error.setRotation(rotation, l);
        }
    } catch (org.jdom2.DataConversionException e) {
    }
    Attribute a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("showid");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowID(true);
    } else {
        l.setShowID(false);
    }
    a = element.getAttribute("filter");
    if (a != null) {
        l.setFilter(a.getValue());
    }
    double sxScale = 0.;
    double syScale = 0.;
    int sxOrigin = 0;
    int syOrigin = 0;
    try {
        sxScale = element.getAttribute("sxscale").getDoubleValue();
        syScale = element.getAttribute("syscale").getDoubleValue();
        sxOrigin = element.getAttribute("sxorigin").getIntValue();
        syOrigin = element.getAttribute("syorigin").getIntValue();
    } catch (NullPointerException e1) {
        log.error("missing transform attribute");
    } catch (org.jdom2.DataConversionException e2) {
        log.error("failed to convert transform attributes");
    }
    l.setTransform(sxScale, syScale, sxOrigin, syOrigin);
    NamedIcon icon = loadIcon(l, "active", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setActiveIcon(icon);
    }
    icon = loadIcon(l, "error", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setErrorIcon(icon);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SENSORS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Editor(jmri.jmrit.display.Editor) RpsPositionIcon(jmri.jmrit.display.RpsPositionIcon)

Aggregations

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)6 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 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5