Search in sources :

Example 46 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class TrainCustomCommon method load.

public void load(Element mc) {
    if (mc != null) {
        Attribute a;
        Element directory = mc.getChild(Xml.DIRECTORY);
        if (directory != null && (a = directory.getAttribute(Xml.NAME)) != null) {
            setDirectoryName(a.getValue());
        }
        Element file = mc.getChild(Xml.RUN_FILE);
        if (file != null && (a = file.getAttribute(Xml.NAME)) != null) {
            mcAppName = a.getValue();
        }
        Element common = mc.getChild(Xml.COMMON_FILE);
        if (common != null && (a = common.getAttribute(Xml.NAME)) != null) {
            csvNamesFileName = a.getValue();
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 47 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class PaneProgFrame method pickProgrammerMode.

protected void pickProgrammerMode(@Nonnull Element programming) {
    log.debug("pickProgrammerMode starts");
    boolean paged = true;
    boolean directbit = true;
    boolean directbyte = true;
    boolean register = true;
    Attribute a;
    // set the programming attributes for DCC
    if ((a = programming.getAttribute("paged")) != null) {
        if (a.getValue().equals("no")) {
            paged = false;
        }
    }
    if ((a = programming.getAttribute("direct")) != null) {
        if (a.getValue().equals("no")) {
            directbit = false;
            directbyte = false;
        } else if (a.getValue().equals("bitOnly")) {
            directbit = true;
            directbyte = false;
        } else if (a.getValue().equals("byteOnly")) {
            directbit = false;
            directbyte = true;
        } else {
            directbit = true;
            directbyte = true;
        }
    }
    if ((a = programming.getAttribute("register")) != null) {
        if (a.getValue().equals("no")) {
            register = false;
        }
    }
    // find an accepted mode to set it to
    List<ProgrammingMode> modes = mProgrammer.getSupportedModes();
    if (log.isDebugEnabled()) {
        log.debug("XML specifies modes: P " + paged + " DBi " + directbit + " Dby " + directbyte + " R " + register + " now " + mProgrammer.getMode());
        log.debug("Programmer supports:");
        for (ProgrammingMode m : modes) {
            log.debug("   {} {}", m.getStandardName(), m.toString());
        }
    }
    // first try specified modes
    for (Element el1 : programming.getChildren("mode")) {
        String name = el1.getText();
        if (log.isDebugEnabled())
            log.debug(" mode {} was specified", name);
        for (ProgrammingMode m : modes) {
            if (name.equals(m.getStandardName())) {
                log.info("Programming mode selected: {} ({})", m.toString(), m.getStandardName());
                mProgrammer.setMode(m);
                return;
            }
        }
    }
    if (modes.contains(DefaultProgrammerManager.DIRECTMODE) && directbit && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTMODE);
        log.debug("Set to DIRECTMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBITMODE) && directbit) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBITMODE);
        log.debug("Set to DIRECTBITMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBYTEMODE) && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBYTEMODE);
        log.debug("Set to DIRECTBYTEMODE");
    } else if (modes.contains(DefaultProgrammerManager.PAGEMODE) && paged) {
        mProgrammer.setMode(DefaultProgrammerManager.PAGEMODE);
        log.debug("Set to PAGEMODE");
    } else if (modes.contains(DefaultProgrammerManager.REGISTERMODE) && register) {
        mProgrammer.setMode(DefaultProgrammerManager.REGISTERMODE);
        log.debug("Set to REGISTERMODE");
    } else {
        log.warn("No acceptable mode found, leave as found");
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ProgrammingMode(jmri.ProgrammingMode)

Example 48 with Attribute

use of ucar.nc2.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 49 with Attribute

use of ucar.nc2.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 50 with Attribute

use of ucar.nc2.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)

Aggregations

Attribute (org.jdom2.Attribute)106 Element (org.jdom2.Element)75 Editor (jmri.jmrit.display.Editor)15 DataConversionException (org.jdom2.DataConversionException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 List (java.util.List)7 Color (java.awt.Color)6 File (java.io.File)6 HashMap (java.util.HashMap)6 ConfigureManager (jmri.ConfigureManager)6 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 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5