Search in sources :

Example 26 with Attribute

use of org.bouncycastle.asn1.x509.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 27 with Attribute

use of org.bouncycastle.asn1.x509.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 28 with Attribute

use of org.bouncycastle.asn1.x509.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)

Example 29 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class AbstractAudioManagerConfigXML method loadAudio.

/**
     * Utility method to load the individual Audio objects. If there's no
     * additional info needed for a specific Audio type, invoke this with the
     * parent of the set of Audio elements.
     *
     * @param audio Element containing the Audio elements to load.
     */
@SuppressWarnings("unchecked")
public void loadAudio(Element audio) {
    AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
    // Count number of loaded Audio objects
    int loadedObjects = 0;
    // Load buffers first
    List<Element> audioList = audio.getChildren("audiobuffer");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Buffer objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioBuffer ab = (AudioBuffer) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(ab, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("url")) != null) {
                ab.setURL(ce.getValue());
            }
            if ((ce = e.getChild("looppoint")) != null) {
                if ((value = ce.getAttributeValue("start")) != null) {
                    ab.setStartLoopPoint(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("end")) != null) {
                    ab.setEndLoopPoint(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("streamed")) != null) {
                ab.setStreamed(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioBuffer (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Now load sources
    audioList = audio.getChildren("audiosource");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Source objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioSource as = (AudioSource) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(as, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("position")) != null) {
                as.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("velocity")) != null) {
                as.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("assignedbuffer")) != null) {
                if (ce.getValue().length() != 0 && !ce.getValue().equals("null")) {
                    as.setAssignedBuffer(ce.getValue());
                }
            }
            if ((ce = e.getChild("gain")) != null && ce.getValue().length() != 0) {
                as.setGain(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("pitch")) != null && ce.getValue().length() != 0) {
                as.setPitch(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("distances")) != null) {
                if ((value = ce.getAttributeValue("ref")) != null) {
                    as.setReferenceDistance(Float.parseFloat(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaximumDistance(Float.parseFloat(value));
                }
            }
            if ((ce = e.getChild("loops")) != null) {
                if ((value = ce.getAttributeValue("min")) != null) {
                    as.setMinLoops(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaxLoops(Integer.parseInt(value));
                }
            //                    if ((value = ce.getAttributeValue("mindelay"))!=null)
            //                        as.setMinLoopDelay(Integer.parseInt(value));
            //                    if ((value = ce.getAttributeValue("maxdelay"))!=null)
            //                        as.setMaxLoopDelay(Integer.parseInt(value));
            }
            if ((ce = e.getChild("fadetimes")) != null) {
                if ((value = ce.getAttributeValue("in")) != null) {
                    as.setFadeIn(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("out")) != null) {
                    as.setFadeOut(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("dopplerfactor")) != null && ce.getValue().length() != 0) {
                as.setDopplerFactor(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("positionrelative")) != null) {
                as.setPositionRelative(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioSource (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Finally, load Listeners if needed
    if (loadedObjects > 0) {
        audioList = audio.getChildren("audiolistener");
        if (log.isDebugEnabled()) {
            log.debug("Found " + audioList.size() + " Audio Listener objects");
        }
        for (int i = 0; i < audioList.size(); i++) {
            Element e = audioList.get(i);
            String sysName = getSystemName(e);
            if (sysName == null) {
                log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
                break;
            }
            String userName = getUserName(e);
            if (log.isDebugEnabled()) {
                log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
            }
            try {
                AudioListener al = (AudioListener) am.newAudio(sysName, userName);
                // load common parts
                loadCommon(al, e);
                // load sub-type specific parts
                // Transient object for reading child elements
                Element ce;
                if ((ce = e.getChild("position")) != null) {
                    al.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("velocity")) != null) {
                    al.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("orientation")) != null) {
                    al.setOrientation(new Vector3f(Float.parseFloat(ce.getAttributeValue("atX")), Float.parseFloat(ce.getAttributeValue("atY")), Float.parseFloat(ce.getAttributeValue("atZ"))), new Vector3f(Float.parseFloat(ce.getAttributeValue("upX")), Float.parseFloat(ce.getAttributeValue("upY")), Float.parseFloat(ce.getAttributeValue("upZ"))));
                }
                if ((ce = e.getChild("gain")) != null) {
                    al.setGain(Float.parseFloat(ce.getValue()));
                }
                if ((ce = e.getChild("metersperunit")) != null) {
                    al.setMetersPerUnit(Float.parseFloat((ce.getValue())));
                }
            } catch (AudioException ex) {
                log.error("Error loading AudioListener (" + sysName + "): " + ex);
            }
        }
        Attribute a;
        if ((a = audio.getAttribute("distanceattenuated")) != null) {
            am.getActiveAudioFactory().setDistanceAttenuated(a.getValue().equals("yes"));
        }
    }
}
Also used : AudioSource(jmri.jmrit.audio.AudioSource) AudioManager(jmri.AudioManager) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) AudioException(jmri.AudioException) Vector3f(javax.vecmath.Vector3f) AudioListener(jmri.jmrit.audio.AudioListener) AudioBuffer(jmri.jmrit.audio.AudioBuffer)

Example 30 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method addLeaves.

private void addLeaves(Element element, CatalogTreeNode node) {
    List<Element> leafList = element.getChildren("leaf");
    for (int i = 0; i < leafList.size(); i++) {
        Element elem = leafList.get(i);
        Attribute attr = elem.getAttribute("name");
        if (attr == null) {
            log.error("unexpected null leaf name. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String name = attr.getValue();
        attr = elem.getAttribute("path");
        if (attr == null) {
            log.error("unexpected null leaf path. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String path = attr.getValue();
        // use the method that maintains the same order
        node.addLeaf(new CatalogTreeLeaf(name, path, 0));
    }
}
Also used : CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)149 Element (org.jdom2.Element)104 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)33 Attribute (org.bouncycastle.asn1.cms.Attribute)29 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)26 X509Certificate (java.security.cert.X509Certificate)25 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)23 Test (org.junit.Test)22 DERSequence (org.bouncycastle.asn1.DERSequence)20 DERSet (org.bouncycastle.asn1.DERSet)20 List (java.util.List)19 Attribute (org.bouncycastle.asn1.pkcs.Attribute)18 Document (org.jdom2.Document)18 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 CertificateEncodingException (java.security.cert.CertificateEncodingException)14 ASN1Set (org.bouncycastle.asn1.ASN1Set)14