Search in sources :

Example 51 with Attribute

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

the class PaneProgFrame method loadProgrammerFile.

protected void loadProgrammerFile(RosterEntry r) {
    // Open and parse programmer file
    XmlFile pf = new XmlFile() {
    };
    // XmlFile is abstract
    try {
        programmerRoot = pf.rootFromName(filename);
        // get the showEmptyPanes attribute, if yes/no update our state
        if (programmerRoot.getChild("programmer").getAttribute("showEmptyPanes") != null) {
            if (log.isDebugEnabled()) {
                log.debug("Found in programmer " + programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue());
            }
            programmerShowEmptyPanes = programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue();
        } else {
            programmerShowEmptyPanes = "";
        }
        if (log.isDebugEnabled()) {
            log.debug("programmerShowEmptyPanes=" + programmerShowEmptyPanes);
        }
        // get extra any panes from the decoder file
        Attribute a;
        if ((a = programmerRoot.getChild("programmer").getAttribute("decoderFilePanes")) != null && a.getValue().equals("yes")) {
            if (decoderRoot != null) {
                decoderPaneList = decoderRoot.getChildren("pane");
            }
        }
        // load programmer config from programmer tree
        readConfig(programmerRoot, r);
    } catch (org.jdom2.JDOMException e) {
        log.error("exception parsing programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    } catch (java.io.IOException e) {
        log.error("exception reading programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Attribute(org.jdom2.Attribute)

Example 52 with Attribute

use of org.omegat.filters3.Attribute in project tika by apache.

the class NetCDFParser method parse.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.tika.parser.Parser#parse(java.io.InputStream,
     * org.xml.sax.ContentHandler, org.apache.tika.metadata.Metadata,
     * org.apache.tika.parser.ParseContext)
     */
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    TemporaryResources tmp = TikaInputStream.isTikaInputStream(stream) ? null : new TemporaryResources();
    TikaInputStream tis = TikaInputStream.get(stream, tmp);
    NetcdfFile ncFile = null;
    try {
        ncFile = NetcdfFile.open(tis.getFile().getAbsolutePath());
        metadata.set("File-Type-Description", ncFile.getFileTypeDescription());
        // first parse out the set of global attributes
        for (Attribute attr : ncFile.getGlobalAttributes()) {
            Property property = resolveMetadataKey(attr.getFullName());
            if (attr.getDataType().isString()) {
                metadata.add(property, attr.getStringValue());
            } else if (attr.getDataType().isNumeric()) {
                int value = attr.getNumericValue().intValue();
                metadata.add(property, String.valueOf(value));
            }
        }
        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();
        xhtml.newline();
        xhtml.element("h1", "dimensions");
        xhtml.startElement("ul");
        xhtml.newline();
        for (Dimension dim : ncFile.getDimensions()) {
            xhtml.element("li", dim.getFullName() + " = " + dim.getLength());
        }
        xhtml.endElement("ul");
        xhtml.element("h1", "variables");
        xhtml.startElement("ul");
        xhtml.newline();
        for (Variable var : ncFile.getVariables()) {
            xhtml.startElement("li");
            xhtml.characters(var.getDataType() + " " + var.getNameAndDimensions());
            xhtml.newline();
            List<Attribute> attributes = var.getAttributes();
            if (!attributes.isEmpty()) {
                xhtml.startElement("ul");
                for (Attribute element : attributes) {
                    xhtml.element("li", element.toString());
                }
                xhtml.endElement("ul");
            }
            xhtml.endElement("li");
        }
        xhtml.endElement("ul");
        xhtml.endDocument();
    } catch (IOException e) {
        throw new TikaException("NetCDF parse error", e);
    } finally {
        if (ncFile != null) {
            ncFile.close();
        }
        if (tmp != null) {
            tmp.dispose();
        }
    }
}
Also used : NetcdfFile(ucar.nc2.NetcdfFile) Variable(ucar.nc2.Variable) TikaException(org.apache.tika.exception.TikaException) Attribute(ucar.nc2.Attribute) TemporaryResources(org.apache.tika.io.TemporaryResources) TikaInputStream(org.apache.tika.io.TikaInputStream) Dimension(ucar.nc2.Dimension) IOException(java.io.IOException) XHTMLContentHandler(org.apache.tika.sax.XHTMLContentHandler) Property(org.apache.tika.metadata.Property)

Example 53 with Attribute

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

the class DefaultCatalogTreeManagerXml method loadNode.

/**
     * Recursively load a CatalogTree.
     *
     * @param element element containing the node to load
     * @param parent  the parent node of the node in element
     * @param model   the tree model containing the tree to add the node to
     */
public void loadNode(Element element, CatalogTreeNode parent, DefaultTreeModel model) {
    List<Element> nodeList = element.getChildren("node");
    if (log.isDebugEnabled()) {
        log.debug("Found " + nodeList.size() + " CatalogTreeNode objects");
    }
    for (int i = 0; i < nodeList.size(); i++) {
        Element elem = nodeList.get(i);
        Attribute attr = elem.getAttribute("nodeName");
        if (attr == null) {
            log.warn("unexpected null nodeName. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String nodeName = attr.getValue();
        CatalogTreeNode n = new CatalogTreeNode(nodeName);
        addLeaves(elem, n);
        model.insertNodeInto(n, parent, parent.getChildCount());
        loadNode(elem, n, model);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 54 with Attribute

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

the class SlipTurnoutIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    SlipTurnoutIcon l = new SlipTurnoutIcon(p);
    int rotation = 0;
    try {
        Attribute a = element.getAttribute("rotate");
        rotation = a.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    String nameEast = loadTurnout(element, "turnoutEast");
    /*try {
         nameEast=element.getAttribute("turnoutEast").getValue();
         } catch ( NullPointerException e) { 
         log.error("incorrect information for turnout; must use turnout name");
         return;
         }*/
    String nameWest = loadTurnout(element, "turnoutWest");
    /*try {
         nameWest=element.getAttribute("turnoutWest").getValue();
         } catch ( NullPointerException e) { 
         log.error("incorrect information for turnout; must use turnout name");
         return;
         }*/
    Attribute a = element.getAttribute("turnoutType");
    if (a != null) {
        if (a.getValue().equals("doubleSlip")) {
            l.setTurnoutType(SlipTurnoutIcon.DOUBLESLIP);
        } else if (a.getValue().equals("singleSlip")) {
            l.setTurnoutType(SlipTurnoutIcon.SINGLESLIP);
            a = element.getAttribute("singleSlipRoute");
            if ((a == null) || a.getValue().equals("upperWestToUpperEast")) {
                l.setSingleSlipRoute(true);
            } else {
                l.setSingleSlipRoute(false);
            }
        } else if (a.getValue().equals("threeWay")) {
            l.setTurnoutType(SlipTurnoutIcon.THREEWAY);
            a = element.getAttribute("firstTurnoutExit");
            if ((a == null) || a.getValue().equals("lower")) {
                l.setSingleSlipRoute(false);
            } else {
                l.setSingleSlipRoute(true);
            }
        } else if (a.getValue().equals("scissor")) {
            l.setTurnoutType(SlipTurnoutIcon.SCISSOR);
            if (loadTurnout(element, "turnoutLowerWest") == null) {
                l.setSingleSlipRoute(true);
            } else {
                //loadTurnout(element, "turnoutLowerEast");
                l.setSingleSlipRoute(false);
                l.setTurnout(loadTurnout(element, "turnoutLowerEast"), SlipTurnoutIcon.LOWEREAST);
                l.setTurnout(loadTurnout(element, "turnoutLowerWest"), SlipTurnoutIcon.LOWERWEST);
            }
        }
    }
    loadTurnoutIcon("lowerWestToUpperEast", rotation, l, element, p);
    loadTurnoutIcon("upperWestToLowerEast", rotation, l, element, p);
    switch(l.getTurnoutType()) {
        case SlipTurnoutIcon.DOUBLESLIP:
            loadTurnoutIcon("lowerWestToLowerEast", rotation, l, element, p);
            loadTurnoutIcon("upperWestToUpperEast", rotation, l, element, p);
            break;
        default:
            loadTurnoutIcon("lowerWestToLowerEast", rotation, l, element, p);
            break;
    }
    loadTurnoutIcon("unknown", rotation, l, element, p);
    loadTurnoutIcon("inconsistent", rotation, l, element, p);
    a = element.getAttribute("tristate");
    if ((a == null) || a.getValue().equals("true")) {
        l.setTristate(true);
    } else {
        l.setTristate(false);
    }
    l.setTurnout(nameEast, SlipTurnoutIcon.EAST);
    l.setTurnout(nameWest, SlipTurnoutIcon.WEST);
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : Attribute(org.jdom2.Attribute) SlipTurnoutIcon(jmri.jmrit.display.SlipTurnoutIcon) Editor(jmri.jmrit.display.Editor)

Example 55 with Attribute

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

the class TurnoutIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    TurnoutIcon l = new TurnoutIcon(p);
    String name;
    try {
        name = element.getAttribute("turnout").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for turnout; must use turnout name");
        p.loadFailed();
        return;
    }
    l.setTurnout(name);
    Attribute a = element.getAttribute("tristate");
    if ((a == null) || a.getValue().equals("true")) {
        l.setTristate(true);
    } else {
        l.setTristate(false);
    }
    a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("directControl");
    if ((a != null) && a.getValue().equals("true")) {
        l.setDirectControl(true);
    } else {
        l.setDirectControl(false);
    }
    List<Element> states = element.getChildren();
    if (states.size() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Main element has" + states.size() + " items");
        }
        // the element containing the icons
        Element elem = element;
        Element icons = element.getChild("icons");
        if (icons != null) {
            List<Element> s = icons.getChildren();
            states = s;
            // the element containing the icons
            elem = icons;
            if (log.isDebugEnabled()) {
                log.debug("icons element has" + states.size() + " items");
            }
        }
        for (int i = 0; i < states.size(); i++) {
            String state = states.get(i).getName();
            if (log.isDebugEnabled()) {
                log.debug("setIcon for state \"" + state + "\" and " + _nameMap.get(state));
            }
            NamedIcon icon = loadIcon(l, state, elem, "TurnoutIcon \"" + name + "\": icon \"" + state + "\" ", p);
            if (icon != null) {
                l.setIcon(_nameMap.get(state), icon);
            } else {
                log.info("TurnoutIcon \"" + name + "\": icon \"" + state + "\" removed");
                return;
            }
        }
        log.debug(states.size() + " icons loaded for " + l.getNameString());
    } else {
        // case when everything was attributes
        int rotation = 0;
        try {
            rotation = element.getAttribute("rotate").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
        } catch (NullPointerException e) {
        // considered normal if the attributes are not present
        }
        if (loadTurnoutIcon("thrown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("closed", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("unknown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("inconsistent", rotation, l, element, name, p) == null) {
            return;
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) TurnoutIcon(jmri.jmrit.display.TurnoutIcon)

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