Search in sources :

Example 46 with Attribute

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

the class NameCheckAction method actionPerformed.

@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
    if (fci == null) {
        fci = jmri.jmrit.XmlFile.userFileChooser("XML files", "xml");
    }
    // request the filename from an open dialog
    fci.rescanCurrentDirectory();
    int retVal = fci.showOpenDialog(_who);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = fci.getSelectedFile();
        if (log.isDebugEnabled()) {
            log.debug("located file " + file + " for XML processing");
        }
        // handle the file (later should be outside this thread?)
        try {
            Element root = readFile(file);
            if (log.isDebugEnabled()) {
                log.debug("parsing complete");
            }
            // check to see if there's a decoder element
            if (root.getChild("decoder") == null) {
                log.warn("Does not appear to be a decoder file");
                return;
            }
            Iterator<Element> iter = root.getChild("decoder").getChild("variables").getDescendants(new ElementFilter("variable"));
            jmri.jmrit.symbolicprog.NameFile nfile = jmri.jmrit.symbolicprog.NameFile.instance();
            String warnings = "";
            while (iter.hasNext()) {
                Element varElement = iter.next();
                // for each variable, see if can find in names file
                Attribute labelAttr = varElement.getAttribute("label");
                String label = null;
                if (labelAttr != null) {
                    label = labelAttr.getValue();
                }
                Attribute itemAttr = varElement.getAttribute("item");
                String item = null;
                if (itemAttr != null) {
                    item = itemAttr.getValue();
                }
                if (log.isDebugEnabled()) {
                    log.debug("Variable called \"" + ((label != null) ? label : "<none>") + "\" \"" + ((item != null) ? item : "<none>"));
                }
                if (!(label == null ? false : nfile.checkName(label)) && !(item == null ? false : nfile.checkName(item))) {
                    log.warn("Variable not found: label=\"" + ((label != null) ? label : "<none>") + "\" item=\"" + ((item != null) ? label : "<none>") + "\"");
                    warnings += "Variable not found: label=\"" + ((label != null) ? label : "<none>") + "\" item=\"" + ((item != null) ? item : "<none>") + "\"\n";
                }
            }
            if (!warnings.equals("")) {
                JOptionPane.showMessageDialog(_who, warnings);
            } else {
                JOptionPane.showMessageDialog(_who, "No mismatched items found");
            }
        } catch (HeadlessException | IOException | JDOMException ex) {
            JOptionPane.showMessageDialog(_who, "Error parsing decoder file: " + ex);
        }
    } else {
        log.debug("XmlFileCheckAction cancelled in open dialog");
    }
}
Also used : HeadlessException(java.awt.HeadlessException) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) ElementFilter(org.jdom2.filter.ElementFilter) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 47 with Attribute

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

the class BlockContentsIconXml method load.

/**
     * Load, starting with the BlockContentsIcon element, then all the
     * value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    BlockContentsIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new BlockContentsIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("blockcontents");
    if (attr == null) {
        log.error("incorrect information for a block contents; must use block name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    if (m != null) {
        l.setBlock(name);
    } else {
        log.error("Block named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("blockstate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) BlockContentsIcon(jmri.jmrit.display.BlockContentsIcon) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) Block(jmri.Block) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 48 with Attribute

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

the class IndicatorTrackIconXml method load.

/**
     * Create a IndicatorTrackIcon, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    IndicatorTrackIcon l = new IndicatorTrackIcon(p);
    Element elem = element.getChild("iconmap");
    if (elem != null) {
        List<Element> status = elem.getChildren();
        if (status.size() > 0) {
            for (int i = 0; i < status.size(); i++) {
                String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
                NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
                if (icon != null) {
                    l.setIcon(status.get(i).getName(), icon);
                } else {
                    log.info(msg + " removed for url= " + status.get(i).getName());
                    return;
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Element name = element.getChild("occupancyblock");
    if (name != null) {
        l.setOccBlock(name.getText());
    } else {
        // only write sensor if no OBlock, don't write double sensing
        name = element.getChild("occupancysensor");
        if (name != null) {
            l.setOccSensor(name.getText());
        }
    }
    l.setShowTrain(false);
    name = element.getChild("showTrainName");
    if (name != null) {
        if ("yes".equals(name.getText())) {
            l.setShowTrain(true);
        }
    }
    elem = element.getChild("paths");
    if (elem != null) {
        ArrayList<String> paths = new ArrayList<String>();
        List<Element> pth = elem.getChildren();
        for (int i = 0; i < pth.size(); i++) {
            paths.add(pth.get(i).getText());
        }
        l.setPaths(paths);
    }
    l.displayState(l.getStatus());
    l.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Editor(jmri.jmrit.display.Editor)

Example 49 with Attribute

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

the class MemoryComboIconXml method load.

/**
     * Load, starting with the memoryComboIcon element, then all the value-icon
     * pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        Element e = list.get(i);
        String item = e.getText();
        try {
            int idx = e.getAttribute("index").getIntValue();
            items[idx] = item;
        } catch (org.jdom2.DataConversionException ex) {
            log.error("failed to convert ComboBoxIcon index attribute");
            if (items[i] == null) {
                items[i] = item;
            }
        }
    }
    MemoryComboIcon l = new MemoryComboIcon(p, items);
    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        p.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        p.loadFailed();
        return;
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon)

Example 50 with Attribute

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

the class LinkingLabelXml method load.

/**
     * Create LinkingLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LinkingLabel l = null;
    String url = element.getChild("url").getText();
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    if (element.getAttribute("icon") != null) {
        NamedIcon icon = null;
        String name = element.getAttribute("icon").getValue();
        //            if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
        if (name.equals("yes")) {
            icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
        } else {
            icon = NamedIcon.getIconByName(name);
            if (icon == null) {
                icon = editor.loadFailed("LinkingLabel", name);
                if (icon == null) {
                    log.info("LinkingLabel icon removed for url= " + name);
                    return;
                }
            }
        }
        // abort if name != yes and have null icon
        if (icon == null && !name.equals("yes")) {
            log.info("LinkingLabel icon removed for url= " + name);
            return;
        }
        l = new LinkingLabel(icon, editor, url);
        // no text
        l.setPopupUtility(null);
        try {
            Attribute a = element.getAttribute("rotate");
            if (a != null && icon != null) {
                int rotation = element.getAttribute("rotate").getIntValue();
                icon.setRotation(rotation, l);
            }
        } catch (org.jdom2.DataConversionException e) {
        }
        if (name.equals("yes")) {
            NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
            if (nIcon != null) {
                l.updateIcon(nIcon);
            } else {
                log.info("LinkingLabel icon removed for url= " + name);
                return;
            }
        } else {
            l.updateIcon(icon);
        }
    //l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
    } else if (element.getAttribute("text") != null) {
        l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
        loadTextInfo(l, element);
    } else {
        log.error("LinkingLabel is null!");
        if (log.isDebugEnabled()) {
            java.util.List<Attribute> attrs = element.getAttributes();
            log.debug("\tElement Has " + attrs.size() + " Attributes:");
            for (int i = 0; i < attrs.size(); i++) {
                Attribute a = attrs.get(i);
                log.debug("\t\t" + a.getName() + " = " + a.getValue());
            }
            java.util.List<Element> kids = element.getChildren();
            log.debug("\tElementHas " + kids.size() + " children:");
            for (int i = 0; i < kids.size(); i++) {
                Element e = kids.get(i);
                log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
            }
        }
        editor.loadFailed();
        return;
    }
    editor.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.LABELS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) LinkingLabel(jmri.jmrit.display.LinkingLabel) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

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