Search in sources :

Example 81 with Attribute

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

the class PaneProgPane method newVariable.

/**
     * Add the representation of a single variable. The variable is defined by a
     * JDOM variable Element from the XML file.
     *
     * @param var         element containing variable
     * @param col         column to insert label into
     * @param g           panel layout manager
     * @param cs          constraints on layout manager
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     */
public void newVariable(Element var, JComponent col, GridBagLayout g, GridBagConstraints cs, boolean showStdName) {
    // get the name
    String name = var.getAttribute("item").getValue();
    // if it doesn't exist, do nothing
    int i = _varModel.findVarIndex(name);
    if (i < 0) {
        log.trace("Variable \"{}\" not found, omitted", name);
        return;
    }
    //        Leave here for now. Need to track pre-existing corner-case issue
    //        log.info("Entry item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
    // check label orientation
    Attribute attr;
    // this default is also set in the DTD
    String layout = "left";
    if ((attr = var.getAttribute("layout")) != null && attr.getValue() != null) {
        layout = attr.getValue();
    }
    // load label if specified, else use name
    String label = name;
    if (!showStdName) {
        // get name attribute from variable, as that's the mfg name
        label = _varModel.getLabel(i);
    }
    String temp = LocaleSelector.getAttribute(var, "label");
    if (temp != null) {
        label = temp;
    }
    // get representation; store into the list to be programmed
    JComponent rep = getRepresentation(name, var);
    varList.add(i);
    // create the paired label
    JLabel l = new WatchingLabel(label, rep);
    int spaceWidth = getFontMetrics(l.getFont()).stringWidth(" ");
    // assemble v from label, rep
    switch(layout) {
        case "left":
            cs.anchor = GridBagConstraints.EAST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        //        log.info("Exit item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
        case "right":
            cs.anchor = GridBagConstraints.EAST;
            g.setConstraints(rep, cs);
            col.add(rep);
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "below":
            // variable in center of upper line
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            // label aligned like others
            cs.gridy++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "above":
            // label aligned like others
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            // variable in center of lower line
            cs.gridy++;
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        default:
            log.error("layout internally inconsistent: " + layout);
    }
}
Also used : Attribute(org.jdom2.Attribute) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel)

Example 82 with Attribute

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

the class WiThrottlePreferences method load.

@Override
public void load(Element child) {
    Attribute a;
    if ((a = child.getAttribute("isUseEStop")) != null) {
        setUseEStop(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseEStop = this.isUseEStop();
    }
    if ((a = child.getAttribute("getEStopDelay")) != null) {
        try {
            setEStopDelay(Integer.valueOf(a.getValue()));
            this.asLoadedEStopDelay = this.getEStopDelay();
        } catch (NumberFormatException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    if ((a = child.getAttribute("isUseMomF2")) != null) {
        setUseMomF2(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseMomF2 = this.isUseMomF2();
    }
    if ((a = child.getAttribute("getPort")) != null) {
        try {
            setPort(a.getIntValue());
        } catch (DataConversionException ex) {
            log.error("Port {} is invalid.", a.getValue());
        }
        this.asLoadedPort = this.getPort();
    }
    if ((a = child.getAttribute("isAllowTrackPower")) != null) {
        setAllowTrackPower(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTrackPower = this.isAllowTrackPower();
    }
    if ((a = child.getAttribute("isAllowTurnout")) != null) {
        setAllowTurnout(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTurnout = this.isAllowTurnout();
    }
    if ((a = child.getAttribute("isAllowRoute")) != null) {
        setAllowRoute(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowRoute = this.isAllowRoute();
    }
    if ((a = child.getAttribute("isAllowConsist")) != null) {
        setAllowConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowConsist = this.isAllowConsist();
    }
    if ((a = child.getAttribute("isUseWiFiConsist")) != null) {
        setUseWiFiConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseWiFiConsist = this.isUseWiFiConsist();
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 83 with Attribute

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

the class GuiLafConfigPaneXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
    java.util.Hashtable<String, String> installedLAFs = new java.util.Hashtable<String, String>(plafs.length);
    for (int i = 0; i < plafs.length; i++) {
        installedLAFs.put(plafs[i].getName(), plafs[i].getClassName());
    }
    String name = shared.getAttribute("LAFclass").getValue();
    String className = installedLAFs.get(name);
    log.debug("GUI selection: " + name + " class name: " + className);
    // set the GUI
    if (className != null) {
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setLookAndFeel(name);
        try {
            if (!className.equals(UIManager.getLookAndFeel().getClass().getName())) {
                log.debug("set GUI to " + name + "," + className);
                updateLookAndFeel(name, className);
            } else {
                log.debug("skip updateLAF as already has className==" + className);
            }
        } catch (Exception ex) {
            log.error("Exception while setting GUI look & feel: " + ex);
            result = false;
        }
    }
    Attribute langAttr = shared.getAttribute("LocaleLanguage");
    Attribute countryAttr = shared.getAttribute("LocaleCountry");
    Attribute varAttr = shared.getAttribute("LocaleVariant");
    if (countryAttr != null && langAttr != null && varAttr != null) {
        Locale locale = new Locale(langAttr.getValue(), countryAttr.getValue(), varAttr.getValue());
        Locale.setDefault(locale);
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setLocale(locale);
    }
    Attribute clickAttr = shared.getAttribute("nonStandardMouseEvent");
    if (clickAttr != null) {
        boolean nonStandardMouseEvent = clickAttr.getValue().equals("yes");
        jmri.util.swing.SwingSettings.setNonStandardMouseEvent(nonStandardMouseEvent);
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setNonStandardMouseEvent(nonStandardMouseEvent);
    }
    Attribute graphicAttr = shared.getAttribute("graphicTableState");
    if (graphicAttr != null) {
        boolean graphicTableState = graphicAttr.getValue().equals("yes");
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(graphicTableState);
    }
    GuiLafConfigPane g = new GuiLafConfigPane();
    ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerPref(g);
    }
    Attribute fontsize = shared.getAttribute("fontsize");
    if (fontsize != null) {
        int size = Integer.parseInt(fontsize.getValue());
        InstanceManager.getDefault(GuiLafPreferencesManager.class).setFontSize(size);
        this.setUIFontSize(size);
    }
    return result;
}
Also used : Locale(java.util.Locale) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) Attribute(org.jdom2.Attribute) GuiLafConfigPane(apps.GuiLafConfigPane) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) ConfigureManager(jmri.ConfigureManager)

Example 84 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project athenz by yahoo.

the class Crypto method extractX509CSREmail.

public static String extractX509CSREmail(PKCS10CertificationRequest certReq) {
    String rfc822 = null;
    Attribute[] attributes = certReq.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
    for (Attribute attribute : attributes) {
        for (ASN1Encodable value : attribute.getAttributeValues()) {
            Extensions extensions = Extensions.getInstance(value);
            GeneralNames gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
            for (GeneralName name : gns.getNames()) {
                if (name.getTagNo() == GeneralName.rfc822Name) {
                    rfc822 = (((DERIA5String) name.getName()).getString());
                    break;
                }
            }
        }
    }
    return rfc822;
}
Also used : DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) Attribute(org.bouncycastle.asn1.pkcs.Attribute) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) GeneralName(org.bouncycastle.asn1.x509.GeneralName) Extensions(org.bouncycastle.asn1.x509.Extensions)

Example 85 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project athenz by yahoo.

the class Crypto method extractX509CSRDnsNames.

public static List<String> extractX509CSRDnsNames(PKCS10CertificationRequest certReq) {
    List<String> dnsNames = new ArrayList<>();
    Attribute[] attributes = certReq.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest);
    for (Attribute attribute : attributes) {
        for (ASN1Encodable value : attribute.getAttributeValues()) {
            Extensions extensions = Extensions.getInstance(value);
            GeneralNames gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
            for (GeneralName name : gns.getNames()) {
                if (name.getTagNo() == GeneralName.dNSName) {
                    dnsNames.add(((DERIA5String) name.getName()).getString());
                }
            }
        }
    }
    return dnsNames;
}
Also used : GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) Attribute(org.bouncycastle.asn1.pkcs.Attribute) ArrayList(java.util.ArrayList) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) GeneralName(org.bouncycastle.asn1.x509.GeneralName) Extensions(org.bouncycastle.asn1.x509.Extensions)

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