Search in sources :

Example 96 with Attribute

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

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

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

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

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

the class LocaleSelector method getAttribute.

/**
     * Return the value of an attribute for the current locale.
     * <p>
     * {@code <foo temp="a">}
     * {@code <temp xml:lang="hh">b</temp>}
     * {@code </foo>}
     * </p>
     * <p>
     * Say it's looking for the attribute ATT. For each possible suffix, it
     * first looks for a contained element named ATT with an XML 'lang'
     * attribute for the suffix. If so, it takes that value. If none are found,
     * the attribute value is taken from the original element</p>
     *
     * @param el   the element with the attribute or child element
     * @param name the name of the attribute or child element
     * @return the value of the attribute or null
     */
public static String getAttribute(Element el, String name) {
    String retval;
    // look for each suffix first
    for (String suffix : suffixes) {
        retval = checkElement(el, name, suffix);
        if (retval != null) {
            if (testLocale) {
                // the I18N test case, return string in upper case
                return retval.toUpperCase();
            }
            return retval;
        }
    }
    // try default element
    for (Object obj : el.getChildren(name)) {
        Element e = (Element) obj;
        Attribute a = e.getAttribute("lang", Namespace.XML_NAMESPACE);
        if (a == null) {
            // default element
            if (testLocale) {
                // the I18N test case, return string in upper case
                return e.getText().toUpperCase();
            }
            return e.getText();
        }
    }
    // failed, go back to original attribute
    Attribute a = el.getAttribute(name);
    if (a == null) {
        return null;
    }
    if (testLocale) {
        // the I18N test case, return string in upper case
        return a.getValue().toUpperCase();
    }
    return a.getValue();
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

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