Search in sources :

Example 66 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class BlockBossLogicXml method store.

/**
     * Default implementation for storing the contents of all the BLockBossLogic
     * elements.
     * <P>
     * Static members in the BlockBossLogic class record the complete set of
     * items. This function writes those out as a single XML element.
     *
     * @param o Object to start process, but not actually used
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Enumeration<BlockBossLogic> e = BlockBossLogic.entries();
    if (!e.hasMoreElements()) {
        // nothing to write!
        return null;
    }
    Element blocks = new Element("signalelements");
    blocks.setAttribute("class", this.getClass().getName());
    while (e.hasMoreElements()) {
        BlockBossLogic p = e.nextElement();
        Element block = new Element("signalelement");
        block.setAttribute("signal", p.getDrivenSignal());
        block.setAttribute("mode", "" + p.getMode());
        if (p.getApproachSensor1() != null) {
            block.setAttribute("approachsensor1", p.getApproachSensor1());
        }
        if (p.getSensor1() != null) {
            block.addContent(storeSensor(p.getSensor1()));
        }
        if (p.getSensor2() != null) {
            block.addContent(storeSensor(p.getSensor2()));
        }
        if (p.getSensor3() != null) {
            block.addContent(storeSensor(p.getSensor3()));
        }
        if (p.getSensor4() != null) {
            block.addContent(storeSensor(p.getSensor4()));
        }
        if (p.getSensor5() != null) {
            block.addContent(storeSensor(p.getSensor5()));
        }
        if (p.getTurnout() != null) {
            block.setAttribute("watchedturnout", p.getTurnout());
        }
        if (p.getWatchedSignal1() != null) {
            block.setAttribute("watchedsignal1", p.getWatchedSignal1());
        }
        if (p.getWatchedSignal1Alt() != null) {
            block.setAttribute("watchedsignal1alt", p.getWatchedSignal1Alt());
        }
        if (p.getWatchedSignal2() != null) {
            block.setAttribute("watchedsignal2", p.getWatchedSignal2());
        }
        if (p.getWatchedSignal2Alt() != null) {
            block.setAttribute("watchedsignal2alt", p.getWatchedSignal2Alt());
        }
        if (p.getWatchedSensor1() != null) {
            block.setAttribute("watchedsensor1", p.getWatchedSensor1());
        }
        if (p.getWatchedSensor1Alt() != null) {
            block.setAttribute("watchedsensor1alt", p.getWatchedSensor1Alt());
        }
        if (p.getWatchedSensor2() != null) {
            block.setAttribute("watchedsensor2", p.getWatchedSensor2());
        }
        if (p.getWatchedSensor2Alt() != null) {
            block.setAttribute("watchedsensor2alt", p.getWatchedSensor2Alt());
        }
        block.setAttribute("limitspeed1", "" + p.getLimitSpeed1());
        block.setAttribute("limitspeed2", "" + p.getLimitSpeed2());
        block.setAttribute("useflashyellow", "" + p.getUseFlash());
        block.setAttribute("distantsignal", "" + p.getDistantSignal());
        // add comment, if present
        if (p.getComment() != null) {
            Element c = new Element("comment");
            c.addContent(p.getComment());
            block.addContent(c);
        }
        blocks.addContent(block);
    }
    return blocks;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Element(org.jdom2.Element)

Example 67 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method writeCatalogTrees.

/*
     *  Writes out tree values to a file in the user's preferences directory
     */
public void writeCatalogTrees() throws java.io.IOException {
    if (log.isDebugEnabled()) {
        log.debug("entered writeCatalogTreeValues");
    }
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> trees = manager.getSystemNameList();
    boolean found = false;
    Iterator<String> iter = manager.getSystemNameList().iterator();
    while (iter.hasNext()) {
        String sname = iter.next();
        CatalogTree tree = manager.getBySystemName(sname);
        if (log.isDebugEnabled()) {
            log.debug("Tree: sysName= " + sname + ", userName= " + tree.getUserName());
            CatalogTreeNode root = tree.getRoot();
            log.debug("enumerateTree called for root= " + root.toString() + ", has " + root.getChildCount() + " children");
            // root.depthFirstEnumeration isn't fully typed in JDOM2
            @SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = root.depthFirstEnumeration();
            while (e.hasMoreElements()) {
                CatalogTreeNode n = e.nextElement();
                log.debug("nodeName= " + n.getUserObject() + " has " + n.getLeaves().size() + " leaves and " + n.getChildCount() + " subnodes.");
            }
        }
        if (sname != null && sname.charAt(1) == CatalogTree.XML) {
            found = true;
            break;
        }
    }
    if (found) {
        // there are trees defined, create root element
        Element root = new Element("catalogTrees");
        Document doc = newDocument(root, dtdLocation + "catalogTree.dtd");
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/tree-values.xsl"?>
        java.util.Map<String, String> m = new java.util.HashMap<>();
        m.put("type", "text/xsl");
        m.put("href", xsltLocation + "panelfile.xsl");
        org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
        doc.addContent(0, p);
        store(root, trees);
        try {
            if (!checkFile(DEFAULT_FILE_NAME)) {
                // file does not exist, create it
                File file = new File(DEFAULT_FILE_NAME);
                if (!file.createNewFile()) {
                    log.error("createNewFile failed");
                }
            }
            // write content to file
            writeXML(findFile(DEFAULT_FILE_NAME), doc);
            // memory consistent with file
            jmri.jmrit.catalog.ImageIndexEditor.indexChanged(false);
        } catch (java.io.IOException ioe) {
            log.error("IO Exception " + ioe);
            throw (ioe);
        }
    }
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode) CatalogTree(jmri.CatalogTree) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 68 with Element

use of org.neo4j.ogm.domain.gh806.Element 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)

Example 69 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class DecoderIndexFile method readFile.

/**
     * Read the contents of a decoderIndex XML file into this object. Note that
     * this does not clear any existing entries; reset the instance to do that.
     *
     * @param name the name of the decoder index file
     * @throws org.jdom2.JDOMException if unable to parse to decoder index file
     * @throws java.io.IOException     if unable to read decoder index file
     */
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
    if (log.isDebugEnabled()) {
        log.debug("readFile " + name);
    }
    // read file, find root
    Element root = rootFromName(name);
    // decode type, invoke proper processing routine if a decoder file
    if (root.getChild("decoderIndex") != null) {
        if (root.getChild("decoderIndex").getAttribute("version") != null) {
            fileVersion = Integer.parseInt(root.getChild("decoderIndex").getAttribute("version").getValue());
        }
        log.debug("found fileVersion of " + fileVersion);
        readMfgSection(root.getChild("decoderIndex"));
        readFamilySection(root.getChild("decoderIndex"));
    } else {
        log.error("Unrecognized decoderIndex file contents in file: " + name);
    }
}
Also used : Element(org.jdom2.Element)

Example 70 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class DecoderIndexFile method writeFile.

public void writeFile(String name, DecoderIndexFile oldIndex, String[] files) throws java.io.IOException {
    if (log.isDebugEnabled()) {
        log.debug("writeFile " + name);
    }
    // This is taken in large part from "Java and XML" page 368
    File file = new File(FileUtil.getUserFilesPath() + name);
    // create root element and document
    Element root = new Element("decoderIndex-config");
    root.setAttribute("noNamespaceSchemaLocation", "http://jmri.org/xml/schema/decoder.xsd", org.jdom2.Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));
    Document doc = newDocument(root);
    // add XSLT processing instruction
    // <?xml-stylesheet type="text/xsl" href="XSLT/DecoderID.xsl"?>
    java.util.Map<String, String> m = new java.util.HashMap<>();
    m.put("type", "text/xsl");
    m.put("href", xsltLocation + "DecoderID.xsl");
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    // add top-level elements
    Element index;
    root.addContent(index = new Element("decoderIndex"));
    index.setAttribute("version", Integer.toString(fileVersion));
    log.debug("version written to file as " + fileVersion);
    // add mfg list from existing DecoderIndexFile item
    Element mfgList = new Element("mfgList");
    // copy dates from original mfgList element
    if (oldIndex.nmraListDate != null) {
        mfgList.setAttribute("nmraListDate", oldIndex.nmraListDate);
    }
    if (oldIndex.updated != null) {
        mfgList.setAttribute("updated", oldIndex.updated);
    }
    if (oldIndex.lastAdd != null) {
        mfgList.setAttribute("lastadd", oldIndex.lastAdd);
    }
    // We treat "NMRA" special...
    Element mfg = new Element("manufacturer");
    mfg.setAttribute("mfg", "NMRA");
    mfg.setAttribute("mfgID", "999");
    mfgList.addContent(mfg);
    // start working on the rest of the entries
    List<String> keys = new ArrayList<>(oldIndex._mfgIdFromNameHash.keySet());
    Collections.sort(keys);
    for (Object item : keys) {
        String mfgName = (String) item;
        if (!mfgName.equals("NMRA")) {
            mfg = new Element("manufacturer");
            mfg.setAttribute("mfg", mfgName);
            mfg.setAttribute("mfgID", oldIndex._mfgIdFromNameHash.get(mfgName));
            mfgList.addContent(mfg);
        }
    }
    // add family list by scanning files
    Element familyList = new Element("familyList");
    for (String fileName : files) {
        DecoderFile d = new DecoderFile();
        try {
            Element droot = d.rootFromName(DecoderFile.fileLocation + fileName);
            Element family = droot.getChild("decoder").getChild("family").clone();
            family.setAttribute("file", fileName);
            familyList.addContent(family);
        } catch (org.jdom2.JDOMException exj) {
            log.error("could not parse " + fileName + ": " + exj.getMessage());
        } catch (java.io.FileNotFoundException exj) {
            log.error("could not read " + fileName + ": " + exj.getMessage());
        } catch (IOException exj) {
            log.error("other exception while dealing with " + fileName + ": " + exj.getMessage());
        }
    }
    index.addContent(mfgList);
    index.addContent(familyList);
    writeXML(file, doc);
    // force a read of the new file next time
    resetInstance();
}
Also used : HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) File(java.io.File) XmlFile(jmri.jmrit.XmlFile) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Aggregations

Element (org.jdom2.Element)3339 Document (org.jdom2.Document)508 Test (org.junit.Test)457 ArrayList (java.util.ArrayList)331 IOException (java.io.IOException)275 Attribute (org.jdom2.Attribute)213 JDOMException (org.jdom2.JDOMException)205 Element (org.osate.aadl2.Element)143 Namespace (org.jdom2.Namespace)140 List (java.util.List)135 Test (org.junit.jupiter.api.Test)131 File (java.io.File)128 SAXBuilder (org.jdom2.input.SAXBuilder)128 HashMap (java.util.HashMap)120 XMLOutputter (org.jdom2.output.XMLOutputter)105 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 NamedElement (org.osate.aadl2.NamedElement)77 StringReader (java.io.StringReader)67 Iterator (java.util.Iterator)63