Search in sources :

Example 6 with Attribute

use of org.omegat.filters3.Attribute in project platform_frameworks_base by android.

the class ESTHandler method buildCSR.

private byte[] buildCSR(ByteBuffer octetBuffer, OMADMAdapter omadmAdapter, HTTPHandler httpHandler) throws IOException, GeneralSecurityException {
    //Security.addProvider(new BouncyCastleProvider());
    Log.d(TAG, "/csrattrs:");
    /*
        byte[] octets = new byte[octetBuffer.remaining()];
        octetBuffer.duplicate().get(octets);
        for (byte b : octets) {
            System.out.printf("%02x ", b & 0xff);
        }
        */
    Collection<Asn1Object> csrs = Asn1Decoder.decode(octetBuffer);
    for (Asn1Object asn1Object : csrs) {
        Log.d(TAG, asn1Object.toString());
    }
    if (csrs.size() != 1) {
        throw new IOException("Unexpected object count in CSR attributes response: " + csrs.size());
    }
    Asn1Object sequence = csrs.iterator().next();
    if (sequence.getClass() != Asn1Constructed.class) {
        throw new IOException("Unexpected CSR attribute container: " + sequence);
    }
    String keyAlgo = null;
    Asn1Oid keyAlgoOID = null;
    String sigAlgo = null;
    String curveName = null;
    Asn1Oid pubCrypto = null;
    int keySize = -1;
    Map<Asn1Oid, ASN1Encodable> idAttributes = new HashMap<>();
    for (Asn1Object child : sequence.getChildren()) {
        if (child.getTag() == Asn1Decoder.TAG_OID) {
            Asn1Oid oid = (Asn1Oid) child;
            OidMappings.SigEntry sigEntry = OidMappings.getSigEntry(oid);
            if (sigEntry != null) {
                sigAlgo = sigEntry.getSigAlgo();
                keyAlgoOID = sigEntry.getKeyAlgo();
                keyAlgo = OidMappings.getJCEName(keyAlgoOID);
            } else if (oid.equals(OidMappings.sPkcs9AtChallengePassword)) {
                byte[] tlsUnique = httpHandler.getTLSUnique();
                if (tlsUnique != null) {
                    idAttributes.put(oid, new DERPrintableString(Base64.encodeToString(tlsUnique, Base64.DEFAULT)));
                } else {
                    Log.w(TAG, "Cannot retrieve TLS unique channel binding");
                }
            }
        } else if (child.getTag() == Asn1Decoder.TAG_SEQ) {
            Asn1Oid oid = null;
            Set<Asn1Oid> oidValues = new HashSet<>();
            List<Asn1Object> values = new ArrayList<>();
            for (Asn1Object attributeSeq : child.getChildren()) {
                if (attributeSeq.getTag() == Asn1Decoder.TAG_OID) {
                    oid = (Asn1Oid) attributeSeq;
                } else if (attributeSeq.getTag() == Asn1Decoder.TAG_SET) {
                    for (Asn1Object value : attributeSeq.getChildren()) {
                        if (value.getTag() == Asn1Decoder.TAG_OID) {
                            oidValues.add((Asn1Oid) value);
                        } else {
                            values.add(value);
                        }
                    }
                }
            }
            if (oid == null) {
                throw new IOException("Invalid attribute, no OID");
            }
            if (oid.equals(OidMappings.sExtensionRequest)) {
                for (Asn1Oid subOid : oidValues) {
                    if (OidMappings.isIDAttribute(subOid)) {
                        if (subOid.equals(OidMappings.sMAC)) {
                            idAttributes.put(subOid, new DERIA5String(omadmAdapter.getMAC()));
                        } else if (subOid.equals(OidMappings.sIMEI)) {
                            idAttributes.put(subOid, new DERIA5String(omadmAdapter.getImei()));
                        } else if (subOid.equals(OidMappings.sMEID)) {
                            idAttributes.put(subOid, new DERBitString(omadmAdapter.getMeid()));
                        } else if (subOid.equals(OidMappings.sDevID)) {
                            idAttributes.put(subOid, new DERPrintableString(omadmAdapter.getDevID()));
                        }
                    }
                }
            } else if (OidMappings.getCryptoID(oid) != null) {
                pubCrypto = oid;
                if (!values.isEmpty()) {
                    for (Asn1Object value : values) {
                        if (value.getTag() == Asn1Decoder.TAG_INTEGER) {
                            keySize = (int) ((Asn1Integer) value).getValue();
                        }
                    }
                }
                if (oid.equals(OidMappings.sAlgo_EC)) {
                    if (oidValues.isEmpty()) {
                        throw new IOException("No ECC curve name provided");
                    }
                    for (Asn1Oid value : oidValues) {
                        curveName = OidMappings.getJCEName(value);
                        if (curveName != null) {
                            break;
                        }
                    }
                    if (curveName == null) {
                        throw new IOException("Found no ECC curve for " + oidValues);
                    }
                }
            }
        }
    }
    if (keyAlgoOID == null) {
        throw new IOException("No public key algorithm specified");
    }
    if (pubCrypto != null && !pubCrypto.equals(keyAlgoOID)) {
        throw new IOException("Mismatching key algorithms");
    }
    if (keyAlgoOID.equals(OidMappings.sAlgo_RSA)) {
        if (keySize < MinRSAKeySize) {
            if (keySize >= 0) {
                Log.i(TAG, "Upgrading suggested RSA key size from " + keySize + " to " + MinRSAKeySize);
            }
            keySize = MinRSAKeySize;
        }
    }
    Log.d(TAG, String.format("pub key '%s', signature '%s', ECC curve '%s', id-atts %s", keyAlgo, sigAlgo, curveName, idAttributes));
    /*
          Ruckus:
            SEQUENCE:
              OID=1.2.840.113549.1.1.11 (algo_id_sha256WithRSAEncryption)

          RFC-7030:
            SEQUENCE:
              OID=1.2.840.113549.1.9.7 (challengePassword)
              SEQUENCE:
                OID=1.2.840.10045.2.1 (algo_id_ecPublicKey)
                SET:
                  OID=1.3.132.0.34 (secp384r1)
              SEQUENCE:
                OID=1.2.840.113549.1.9.14 (extensionRequest)
                SET:
                  OID=1.3.6.1.1.1.1.22 (mac-address)
              OID=1.2.840.10045.4.3.3 (eccdaWithSHA384)

              1L, 3L, 6L, 1L, 1L, 1L, 1L, 22
         */
    // ECC Does not appear to be supported currently
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlgo);
    if (curveName != null) {
        AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(keyAlgo);
        algorithmParameters.init(new ECNamedCurveGenParameterSpec(curveName));
        kpg.initialize(algorithmParameters.getParameterSpec(ECNamedCurveGenParameterSpec.class));
    } else {
        kpg.initialize(keySize);
    }
    KeyPair kp = kpg.generateKeyPair();
    X500Principal subject = new X500Principal("CN=Android, O=Google, C=US");
    mClientKey = kp.getPrivate();
    // !!! Map the idAttributes into an ASN1Set of values to pass to
    // the PKCS10CertificationRequest - this code is using outdated BC classes and
    // has *not* been tested.
    ASN1Set attributes;
    if (!idAttributes.isEmpty()) {
        ASN1EncodableVector payload = new DEREncodableVector();
        for (Map.Entry<Asn1Oid, ASN1Encodable> entry : idAttributes.entrySet()) {
            DERObjectIdentifier type = new DERObjectIdentifier(entry.getKey().toOIDString());
            ASN1Set values = new DERSet(entry.getValue());
            Attribute attribute = new Attribute(type, values);
            payload.add(attribute);
        }
        attributes = new DERSet(payload);
    } else {
        attributes = null;
    }
    return new PKCS10CertificationRequest(sigAlgo, subject, kp.getPublic(), attributes, mClientKey).getEncoded();
}
Also used : DERSet(com.android.org.bouncycastle.asn1.DERSet) ASN1Set(com.android.org.bouncycastle.asn1.ASN1Set) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(com.android.org.bouncycastle.asn1.x509.Attribute) DERBitString(com.android.org.bouncycastle.asn1.DERBitString) DERPrintableString(com.android.org.bouncycastle.asn1.DERPrintableString) DERIA5String(com.android.org.bouncycastle.asn1.DERIA5String) DERSet(com.android.org.bouncycastle.asn1.DERSet) DERIA5String(com.android.org.bouncycastle.asn1.DERIA5String) Asn1Integer(com.android.hotspot2.asn1.Asn1Integer) DERPrintableString(com.android.org.bouncycastle.asn1.DERPrintableString) ASN1EncodableVector(com.android.org.bouncycastle.asn1.ASN1EncodableVector) List(java.util.List) ArrayList(java.util.ArrayList) ASN1Encodable(com.android.org.bouncycastle.asn1.ASN1Encodable) PKCS10CertificationRequest(com.android.org.bouncycastle.jce.PKCS10CertificationRequest) Asn1Oid(com.android.hotspot2.asn1.Asn1Oid) KeyPair(java.security.KeyPair) ECNamedCurveGenParameterSpec(com.android.org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec) DEREncodableVector(com.android.org.bouncycastle.asn1.DEREncodableVector) DERBitString(com.android.org.bouncycastle.asn1.DERBitString) IOException(java.io.IOException) KeyPairGenerator(java.security.KeyPairGenerator) DERObjectIdentifier(com.android.org.bouncycastle.asn1.DERObjectIdentifier) Asn1Object(com.android.hotspot2.asn1.Asn1Object) OidMappings(com.android.hotspot2.asn1.OidMappings) ASN1Set(com.android.org.bouncycastle.asn1.ASN1Set) X500Principal(javax.security.auth.x500.X500Principal) Map(java.util.Map) HashMap(java.util.HashMap) AlgorithmParameters(java.security.AlgorithmParameters)

Example 7 with Attribute

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

the class XLIFFDialect method constructShortcuts.

@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
    protectedParts.clear();
    // create shortcuts
    InlineTagHandler tagHandler = new InlineTagHandler();
    StringBuilder r = new StringBuilder();
    for (Element el : elements) {
        if (el instanceof XMLContentBasedTag) {
            XMLContentBasedTag tag = (XMLContentBasedTag) el;
            String shortcut = null;
            int shortcutLetter;
            int tagIndex;
            boolean tagProtected;
            if ("bpt".equals(tag.getTag())) {
                // XLIFF specification requires 'rid' and 'id' attributes,
                // but some tools uses 'i' attribute like for TMX
                tagHandler.startBPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
                shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForBptTags);
                tagHandler.setTagShortcutLetter(shortcutLetter);
                tagIndex = tagHandler.endBPT();
                shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
                tagProtected = false;
            } else if ("ept".equals(tag.getTag())) {
                tagHandler.startEPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
                tagIndex = tagHandler.endEPT();
                shortcutLetter = tagHandler.getTagShortcutLetter();
                shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
                tagProtected = false;
            } else if ("it".equals(tag.getTag())) {
                tagHandler.startOTHER();
                tagHandler.setCurrentPos(tag.getAttribute("pos"));
                tagIndex = tagHandler.endOTHER();
                // XLIFF specification requires 'open/close' values,
                // but some tools may use 'begin/end' values like for TMX
                shortcutLetter = calcTagShortcutLetter(tag);
                if ("close".equals(tagHandler.getCurrentPos()) || "end".equals(tagHandler.getCurrentPos())) {
                    // for better compatibility with corresponding TMX files
                    if (forceShortCutToF) {
                        shortcutLetter = 'f';
                    }
                    shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
                } else {
                    shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
                }
                tagProtected = false;
            } else if ("ph".equals(tag.getTag())) {
                tagHandler.startOTHER();
                tagIndex = tagHandler.endOTHER();
                shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForPhTags);
                shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + "/>";
                tagProtected = false;
            } else if ("mrk".equals(tag.getTag())) {
                tagHandler.startOTHER();
                tagIndex = tagHandler.endOTHER();
                shortcutLetter = 'm';
                shortcut = "<m" + tagIndex + ">" + tag.getIntactContents().sourceToOriginal() + "</m" + tagIndex + ">";
                tagProtected = true;
            } else {
                shortcutLetter = 'f';
                tagIndex = -1;
                tagProtected = false;
            }
            tag.setShortcutLetter(shortcutLetter);
            tag.setShortcutIndex(tagIndex);
            tag.setShortcut(shortcut);
            r.append(shortcut);
            ProtectedPart pp = new ProtectedPart();
            pp.setTextInSourceSegment(shortcut);
            pp.setDetailsFromSourceFile(tag.toOriginal());
            if (tagProtected) {
                // protected text with related tags, like <m0>Acme</m0>
                if (StatisticsSettings.isCountingProtectedText()) {
                    // Protected texts are counted, but related tags are not counted in the word count
                    pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT + tag.getIntactContents().sourceToOriginal() + StaticUtils.TAG_REPLACEMENT);
                } else {
                    // All protected parts are not counted in the word count(default)
                    pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
                }
                pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
                pp.setReplacementMatchCalculation(tag.getIntactContents().sourceToOriginal());
            } else {
                // simple tag, like <i0>
                if (StatisticsSettings.isCountingStandardTags()) {
                    pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
                } else {
                    pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
                }
                pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
                pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
            }
            protectedParts.add(pp);
        } else if (el instanceof Tag) {
            Tag tag = (Tag) el;
            int tagIndex = tagHandler.paired(tag.getTag(), tag.getType());
            tag.setIndex(tagIndex);
            String shortcut = tag.toShortcut();
            r.append(shortcut);
            ProtectedPart pp = new ProtectedPart();
            pp.setTextInSourceSegment(shortcut);
            pp.setDetailsFromSourceFile(tag.toOriginal());
            if (StatisticsSettings.isCountingStandardTags()) {
                pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
            } else {
                pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
            }
            pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
            pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
            protectedParts.add(pp);
        } else {
            r.append(el.toShortcut());
        }
    }
    return r.toString();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) XMLContentBasedTag(org.omegat.filters3.xml.XMLContentBasedTag) Element(org.omegat.filters3.Element) InlineTagHandler(org.omegat.util.InlineTagHandler) Tag(org.omegat.filters3.Tag) XMLContentBasedTag(org.omegat.filters3.xml.XMLContentBasedTag)

Example 8 with Attribute

use of org.omegat.filters3.Attribute in project archi by archimatetool.

the class ArchimateTemplateManager method isValidTemplateFile.

@Override
protected boolean isValidTemplateFile(File file) throws IOException {
    if (file == null || !file.exists()) {
        return false;
    }
    // Ensure the template is of the right kind
    String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST);
    if (xmlString == null) {
        return false;
    }
    // If the attribute doesn't exist it was from an older version (before 2.1)
    try {
        Document doc = JDOMUtils.readXMLString(xmlString);
        Element root = doc.getRootElement();
        Attribute attType = root.getAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE);
        if (attType != null) {
            return ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL.equals(attType.getValue());
        }
    } catch (JDOMException ex) {
        return false;
    }
    return true;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 9 with Attribute

use of org.omegat.filters3.Attribute in project coprhd-controller by CoprHD.

the class XmlDiff method compareAttributes.

/**
 * Compares all attributes of old/new element
 *
 * @param oldAttributes
 *            The old attribute list to compare
 * @param newAttributes
 *            The new attribute list to compare
 * @return true if two lists are same, else false
 */
public static boolean compareAttributes(List<Attribute> oldAttributes, List<Attribute> newAttributes) {
    Iterator<Attribute> oldIter = oldAttributes.iterator();
    while (oldIter.hasNext()) {
        Attribute oldAttr = oldIter.next();
        Iterator<Attribute> newIter = newAttributes.iterator();
        while (newIter.hasNext()) {
            Attribute newAttr = newIter.next();
            if (newAttr.getName().equals(oldAttr.getName())) {
                oldIter.remove();
                newIter.remove();
                break;
            }
        }
    }
    return oldAttributes.isEmpty() && newAttributes.isEmpty();
}
Also used : Attribute(org.jdom2.Attribute)

Example 10 with Attribute

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

the class AbstractTurnoutManagerConfigXML method loadTurnouts.

/**
     * Utility method to load the individual Turnout objects. If there's no
     * additional info needed for a specific turnout type, invoke this with the
     * parent of the set of Turnout elements.
     *
     * @param shared Element containing the Turnout elements to load.
     * @param perNode Element containing per-node Turnout data.
     * @return true if succeeded
     */
@SuppressWarnings("unchecked")
public boolean loadTurnouts(Element shared, Element perNode) {
    boolean result = true;
    List<Element> operationList = shared.getChildren("operations");
    if (operationList.size() > 1) {
        log.warn("unexpected extra elements found in turnout operations list");
        result = false;
    }
    if (operationList.size() > 0) {
        TurnoutOperationManagerXml tomx = new TurnoutOperationManagerXml();
        tomx.load(operationList.get(0), null);
    }
    List<Element> turnoutList = shared.getChildren("turnout");
    if (log.isDebugEnabled()) {
        log.debug("Found " + turnoutList.size() + " turnouts");
    }
    TurnoutManager tm = InstanceManager.turnoutManagerInstance();
    try {
        if (shared.getChild("defaultclosedspeed") != null) {
            String closedSpeed = shared.getChild("defaultclosedspeed").getText();
            if (closedSpeed != null && !closedSpeed.equals("")) {
                tm.setDefaultClosedSpeed(closedSpeed);
            }
        }
    } catch (jmri.JmriException ex) {
        log.error(ex.toString());
    }
    try {
        if (shared.getChild("defaultthrownspeed") != null) {
            String thrownSpeed = shared.getChild("defaultthrownspeed").getText();
            if (thrownSpeed != null && !thrownSpeed.equals("")) {
                tm.setDefaultThrownSpeed(thrownSpeed);
            }
        }
    } catch (jmri.JmriException ex) {
        log.error(ex.toString());
    }
    for (int i = 0; i < turnoutList.size(); i++) {
        Element elem = turnoutList.get(i);
        String sysName = getSystemName(elem);
        if (sysName == null) {
            log.error("unexpected null in systemName " + elem);
            result = false;
            break;
        }
        String userName = getUserName(elem);
        checkNameNormalization(sysName, userName, tm);
        if (log.isDebugEnabled()) {
            log.debug("create turnout: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Turnout t = tm.getBySystemName(sysName);
        if (t == null) {
            t = tm.newTurnout(sysName, userName);
        //Nothing is logged in the console window as the newTurnoutFunction already does this.
        } else if (userName != null) {
            t.setUserName(userName);
        }
        // Load common parts
        loadCommon(t, elem);
        // now add feedback if needed
        Attribute a;
        a = elem.getAttribute("feedback");
        if (a != null) {
            try {
                t.setFeedbackMode(a.getValue());
            } catch (IllegalArgumentException e) {
                log.error("Can not set feedback mode: '" + a.getValue() + "' for turnout: '" + sysName + "' user name: '" + (userName == null ? "" : userName) + "'");
                result = false;
            }
        }
        a = elem.getAttribute("sensor1");
        if (a != null) {
            try {
                t.provideFirstFeedbackSensor(a.getValue());
            } catch (jmri.JmriException e) {
                result = false;
            }
        }
        a = elem.getAttribute("sensor2");
        if (a != null) {
            try {
                t.provideSecondFeedbackSensor(a.getValue());
            } catch (jmri.JmriException e) {
                result = false;
            }
        }
        // check for turnout inverted
        t.setInverted(getAttributeBool(elem, "inverted", false));
        // check for turnout decoder
        a = turnoutList.get(i).getAttribute("decoder");
        if (a != null) {
            t.setDecoderName(a.getValue());
        }
        // check for turnout lock mode
        a = turnoutList.get(i).getAttribute("lockMode");
        if (a != null) {
            if (a.getValue().equals("both")) {
                t.enableLockOperation(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, true);
            }
            if (a.getValue().equals("cab")) {
                t.enableLockOperation(Turnout.CABLOCKOUT, true);
                t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, false);
            }
            if (a.getValue().equals("pushbutton")) {
                t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, true);
                t.enableLockOperation(Turnout.CABLOCKOUT, false);
            }
        }
        // check for turnout locked
        a = turnoutList.get(i).getAttribute("locked");
        if (a != null) {
            t.setLocked(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, a.getValue().equals("true"));
        }
        // number of bits, if present - if not, defaults to 1
        a = turnoutList.get(i).getAttribute("numBits");
        if (a == null) {
            t.setNumberOutputBits(1);
        } else {
            int iNum = Integer.parseInt(a.getValue());
            if ((iNum == 1) || (iNum == 2)) {
                t.setNumberOutputBits(iNum);
            } else {
                log.warn("illegal number of output bits for control of turnout " + sysName);
                t.setNumberOutputBits(1);
                result = false;
            }
        }
        // control type, if present - if not, defaults to 0
        a = turnoutList.get(i).getAttribute("controlType");
        if (a == null) {
            t.setControlType(0);
        } else {
            int iType = Integer.parseInt(a.getValue());
            if (iType >= 0) {
                t.setControlType(iType);
            } else {
                log.warn("illegal control type for control of turnout " + sysName);
                t.setControlType(0);
                result = false;
            }
        }
        // operation stuff
        List<Element> myOpList = turnoutList.get(i).getChildren("operation");
        if (myOpList.size() > 0) {
            if (myOpList.size() > 1) {
                log.warn("unexpected extra elements found in turnout-specific operations");
                result = false;
            }
            TurnoutOperation toper = TurnoutOperationXml.loadOperation(myOpList.get(0));
            t.setTurnoutOperation(toper);
        } else {
            a = turnoutList.get(i).getAttribute("automate");
            if (a != null) {
                String str = a.getValue();
                if (str.equals("Off")) {
                    t.setInhibitOperation(true);
                } else if (!str.equals("Default")) {
                    t.setInhibitOperation(false);
                    TurnoutOperation toper = TurnoutOperationManager.getInstance().getOperation(str);
                    t.setTurnoutOperation(toper);
                } else {
                    t.setInhibitOperation(false);
                }
            }
        }
        //  set initial state from sensor feedback if appropriate
        t.setInitialKnownStateFromFeedback();
        try {
            t.setDivergingSpeed("Global");
            if (elem.getChild("divergingSpeed") != null) {
                String speed = elem.getChild("divergingSpeed").getText();
                if (speed != null && !speed.equals("") && !speed.contains("Global")) {
                    t.setDivergingSpeed(speed);
                }
            }
        } catch (jmri.JmriException ex) {
            log.error(ex.toString());
        }
        try {
            t.setStraightSpeed("Global");
            if (elem.getChild("straightSpeed") != null) {
                String speed = elem.getChild("straightSpeed").getText();
                if (speed != null && !speed.equals("") && !speed.contains("Global")) {
                    t.setStraightSpeed(speed);
                }
            }
        } catch (jmri.JmriException ex) {
            log.error(ex.toString());
        }
    }
    return result;
}
Also used : TurnoutOperation(jmri.TurnoutOperation) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) TurnoutManager(jmri.TurnoutManager) TurnoutOperationManagerXml(jmri.configurexml.TurnoutOperationManagerXml) Turnout(jmri.Turnout)

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