Search in sources :

Example 21 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class NceConsistRoster method readFile.

/**
     * Read the contents of a roster XML file into this object. Note that this
     * does not clear any existing entries.
     * @param name file name for consist roster
     * @throws org.jdom2.JDOMException other errors
     * @throws java.io.IOException error accessing file
     */
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
    // find root
    Element root = rootFromName(name);
    if (root == null) {
        log.debug("ConsistRoster file could not be read");
        return;
    }
    // decode type, invoke proper processing routine if a decoder file
    if (root.getChild("roster") != null) {
        List<Element> l = root.getChild("roster").getChildren("consist");
        if (log.isDebugEnabled()) {
            log.debug("readFile sees " + l.size() + " children");
        }
        for (int i = 0; i < l.size(); i++) {
            addEntry(new NceConsistRosterEntry(l.get(i)));
        }
        //any <?p?> processor directives and change them to back \n characters
        for (int i = 0; i < numEntries(); i++) {
            //Get a RosterEntry object for this index
            NceConsistRosterEntry r = _list.get(i);
            //Extract the Comment field and create a new string for output
            String tempComment = r.getComment();
            StringBuffer buf = new StringBuffer();
            //characters in tempComment.
            for (int k = 0; k < tempComment.length(); k++) {
                if (tempComment.startsWith("<?p?>", k)) {
                    buf.append("\n");
                    k = k + 4;
                } else {
                    buf.append(tempComment.substring(k, k + 1));
                }
            }
            r.setComment(buf.toString());
        }
    } else {
        log.error("Unrecognized ConsistRoster file contents in file: " + name);
    }
}
Also used : Element(org.jdom2.Element)

Example 22 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class NceConsistRosterEntry method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in consist-roster-config.xml.
     *
     * @return Contents in a JDOM Element
     */
org.jdom2.Element store() {
    org.jdom2.Element e = new org.jdom2.Element("consist");
    e.setAttribute("id", getId());
    e.setAttribute("consistNumber", getConsistNumber());
    e.setAttribute("roadNumber", getRoadNumber());
    e.setAttribute("roadName", getRoadName());
    e.setAttribute("model", getModel());
    e.setAttribute("comment", getComment());
    org.jdom2.Element loco1 = new org.jdom2.Element("loco");
    loco1.setAttribute("locoName", "lead");
    loco1.setAttribute("dccLocoAddress", getLoco1DccAddress());
    loco1.setAttribute("longAddress", isLoco1LongAddress() ? "yes" : "no");
    loco1.setAttribute("locoDir", getLoco1Direction());
    e.addContent(loco1);
    org.jdom2.Element loco2 = new org.jdom2.Element("loco");
    loco2.setAttribute("locoName", "rear");
    loco2.setAttribute("dccLocoAddress", getLoco2DccAddress());
    loco2.setAttribute("longAddress", isLoco2LongAddress() ? "yes" : "no");
    loco2.setAttribute("locoDir", getLoco2Direction());
    e.addContent(loco2);
    if (!getLoco3DccAddress().equals("")) {
        org.jdom2.Element loco3 = new org.jdom2.Element("loco");
        loco3.setAttribute("locoName", "mid");
        loco3.setAttribute("locoMidNumber", "1");
        loco3.setAttribute("dccLocoAddress", getLoco3DccAddress());
        loco3.setAttribute("longAddress", isLoco3LongAddress() ? "yes" : "no");
        loco3.setAttribute("locoDir", getLoco3Direction());
        e.addContent(loco3);
    }
    if (!getLoco4DccAddress().equals("")) {
        org.jdom2.Element loco4 = new org.jdom2.Element("loco");
        loco4.setAttribute("locoName", "mid");
        loco4.setAttribute("locoMidNumber", "2");
        loco4.setAttribute("dccLocoAddress", getLoco4DccAddress());
        loco4.setAttribute("longAddress", isLoco4LongAddress() ? "yes" : "no");
        loco4.setAttribute("locoDir", getLoco4Direction());
        e.addContent(loco4);
    }
    if (!getLoco5DccAddress().equals("")) {
        org.jdom2.Element loco5 = new org.jdom2.Element("loco");
        loco5.setAttribute("locoName", "mid");
        loco5.setAttribute("locoMidNumber", "3");
        loco5.setAttribute("dccLocoAddress", getLoco5DccAddress());
        loco5.setAttribute("longAddress", isLoco5LongAddress() ? "yes" : "no");
        loco5.setAttribute("locoDir", getLoco5Direction());
        e.addContent(loco5);
    }
    if (!getLoco6DccAddress().equals("")) {
        org.jdom2.Element loco6 = new org.jdom2.Element("loco");
        loco6.setAttribute("locoName", "mid");
        loco6.setAttribute("locoMidNumber", "4");
        loco6.setAttribute("dccLocoAddress", getLoco6DccAddress());
        loco6.setAttribute("longAddress", isLoco6LongAddress() ? "yes" : "no");
        loco6.setAttribute("locoDir", getLoco6Direction());
        e.addContent(loco6);
    }
    return e;
}
Also used : Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 23 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // loop over contained signalgroup elements
    List<Element> list = shared.getChildren("signalgroup");
    SignalGroupManager sgm = InstanceManager.getDefault(jmri.SignalGroupManager.class);
    for (int i = 0; i < list.size(); i++) {
        SignalGroup m;
        Element e = list.get(i);
        String primary;
        String yesno;
        boolean inverse = false;
        int state = 0x00;
        String sys = getSystemName(e);
        m = sgm.newSignalGroup(sys);
        if (getUserName(e) != null) {
            m.setUserName(getUserName(e));
        }
        //loadCommon(m, e); // would store comment, now a separate element
        loadComment(m, e);
        primary = e.getAttribute("signalMast").getValue();
        m.setSignalMast(primary);
        // deprecated 4.7.2 for aspect
        List<Element> appList = e.getChildren("appearance");
        for (int y = 0; y < appList.size(); y++) {
            String value = appList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> aspList = e.getChildren("aspect");
        for (int y = 0; y < aspList.size(); y++) {
            String value = aspList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> signalHeadList = list.get(i).getChildren("signalHead");
        if (signalHeadList.size() > 0) {
            for (int y = 0; y < signalHeadList.size(); y++) {
                String head = signalHeadList.get(y).getAttribute("name").getValue();
                SignalHead sigHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head);
                m.addSignalHead(sigHead);
                yesno = signalHeadList.get(y).getAttribute("sensorTurnoutLogic").getValue();
                inverse = false;
                if ((yesno != null) && (!yesno.equals(""))) {
                    if (yesno.equals("AND")) {
                        inverse = true;
                    } else if (yesno.equals("OR")) {
                        inverse = false;
                    }
                }
                m.setSensorTurnoutOper(sigHead, inverse);
                try {
                    m.setHeadOnState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("onAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                try {
                    m.setHeadOffState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("offAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                List<Element> signalTurnoutList = signalHeadList.get(y).getChildren("turnout");
                if (signalTurnoutList.size() > 0) {
                    for (int k = 0; k < signalTurnoutList.size(); k++) {
                        String tName = signalTurnoutList.get(k).getAttribute("name").getValue();
                        jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(tName);
                        state = 0;
                        try {
                            state = signalTurnoutList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid state attribute value");
                        }
                        m.setHeadAlignTurnout(sigHead, turnout, state);
                    }
                }
                List<Element> signalSensorList = signalHeadList.get(y).getChildren("sensor");
                if (signalSensorList.size() > 0) {
                    for (int k = 0; k < signalSensorList.size(); k++) {
                        String sName = signalSensorList.get(k).getAttribute("name").getValue();
                        jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
                        state = 0;
                        try {
                            state = signalSensorList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid style attribute value");
                        }
                        m.setHeadAlignSensor(sigHead, sensor, state);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SignalGroup(jmri.SignalGroup) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalGroupManager(jmri.SignalGroupManager)

Example 24 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DefaultSignalGroupManagerXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalGroupManager
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SignalGroupManager m = (SignalGroupManager) o;
    Element element = new Element("signalgroups");
    element.setAttribute("class", this.getClass().getName());
    // include contents
    List<String> names = m.getSystemNameList();
    for (int i = 0; i < names.size(); i++) {
        Element e = new Element("signalgroup");
        SignalGroup p = m.getSignalGroup(names.get(i));
        e.addContent(new Element("systemName").addContent(p.getSystemName()));
        e.addContent(new Element("userName").addContent(p.getUserName()));
        //storeCommon(p, e); would store comment, now a separate element
        storeComment(p, e);
        element.addContent(e);
        for (int x = 0; x < p.getNumSignalMastAspects(); x++) {
            Element app = new Element("aspect").setAttribute("valid", p.getSignalMastAspectByIndex(x));
            e.addContent(app);
        }
        e.setAttribute("signalMast", p.getSignalMastName());
        for (int x = 0; x < p.getNumHeadItems(); x++) {
            storeSignalHead(e, p, x);
        }
    }
    return element;
}
Also used : SignalGroup(jmri.SignalGroup) SignalGroupManager(jmri.SignalGroupManager) Element(org.jdom2.Element)

Example 25 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DefaultSignalMastLogicManagerXml method loadSignalMastLogic.

public boolean loadSignalMastLogic(Element signalMastLogic) {
    List<Element> logicList = signalMastLogic.getChildren("signalmastlogic");
    if (log.isDebugEnabled()) {
        log.debug("Found " + logicList.size() + " signal mast logics");
    }
    SignalMastManager sm = InstanceManager.getDefault(jmri.SignalMastManager.class);
    SignalMastLogicManager sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class);
    try {
        String logicDelay = signalMastLogic.getChild("logicDelay").getText();
        sml.setSignalLogicDelay(Long.parseLong(logicDelay));
    } catch (java.lang.NullPointerException e) {
    //Considered normal if it doesn't exists
    }
    boolean loadOk = true;
    for (Element so : logicList) {
        String source = so.getChild("sourceSignalMast").getText();
        SignalMast sourceMast = sm.getSignalMast(source);
        if (sourceMast != null) {
            SignalMastLogic logic = sml.newSignalMastLogic(sourceMast);
            List<Element> destList = so.getChildren("destinationMast");
            for (Element s : destList) {
                String destination = s.getChild("destinationSignalMast").getText();
                SignalMast dest = sm.getSignalMast(destination);
                if (dest != null) {
                    logic.setDestinationMast(dest);
                    if (s.getChild("comment") != null) {
                        logic.setComment(s.getChild("comment").getText(), dest);
                    }
                    if (s.getChild("enabled") != null) {
                        if (s.getChild("enabled").getText().equals("yes")) {
                            logic.setEnabled(dest);
                        } else {
                            logic.setDisabled(dest);
                        }
                    }
                    if (s.getChild("allowAutoMaticSignalMastGeneration") != null) {
                        if (s.getChild("allowAutoMaticSignalMastGeneration").getText().equals("no")) {
                            logic.allowAutoMaticSignalMastGeneration(false, dest);
                        } else {
                            logic.allowAutoMaticSignalMastGeneration(true, dest);
                        }
                    }
                    boolean useLayoutEditorTurnout = true;
                    boolean useLayoutEditorBlock = true;
                    if (s.getChild("useLayoutEditorTurnouts") != null) {
                        if (s.getChild("useLayoutEditorTurnouts").getText().equals("no")) {
                            useLayoutEditorTurnout = false;
                        }
                    }
                    if (s.getChild("useLayoutEditorBlocks") != null) {
                        if (s.getChild("useLayoutEditorBlocks").getText().equals("no")) {
                            useLayoutEditorBlock = false;
                        }
                    }
                    try {
                        logic.useLayoutEditorDetails(useLayoutEditorTurnout, useLayoutEditorBlock, dest);
                    } catch (jmri.JmriException ex) {
                    }
                    if (s.getChild("useLayoutEditor") != null) {
                        try {
                            if (s.getChild("useLayoutEditor").getText().equals("yes")) {
                                logic.useLayoutEditor(true, dest);
                            } else {
                                logic.useLayoutEditor(false, dest);
                            }
                        } catch (jmri.JmriException e) {
                        //Considered normal if layout editor hasn't yet been set up.
                        }
                    }
                    if (s.getChild("associatedSection") != null) {
                        Section sect = InstanceManager.getDefault(jmri.SectionManager.class).getSection(s.getChild("associatedSection").getText());
                        logic.setAssociatedSection(sect, dest);
                    }
                    Element turnoutElem = s.getChild("turnouts");
                    if (turnoutElem != null) {
                        List<Element> turnoutList = turnoutElem.getChildren("turnout");
                        if (turnoutList.size() > 0) {
                            Hashtable<NamedBeanHandle<Turnout>, Integer> list = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
                            for (Element t : turnoutList) {
                                String turnout = t.getChild("turnoutName").getText();
                                String state = t.getChild("turnoutState").getText();
                                int value = Turnout.CLOSED;
                                if (state.equals("thrown")) {
                                    value = Turnout.THROWN;
                                }
                                Turnout turn = InstanceManager.turnoutManagerInstance().getTurnout(turnout);
                                if (turn != null) {
                                    NamedBeanHandle<Turnout> namedTurnout = nbhm.getNamedBeanHandle(turnout, turn);
                                    list.put(namedTurnout, value);
                                }
                                log.debug("Unable to add Turnout {} as it does not exist in the panel file", turnout);
                            }
                            logic.setTurnouts(list, dest);
                        }
                    }
                    Element sensorElem = s.getChild("sensors");
                    if (sensorElem != null) {
                        List<Element> sensorList = sensorElem.getChildren("sensor");
                        if (sensorList.size() > 0) {
                            Hashtable<NamedBeanHandle<Sensor>, Integer> list = new Hashtable<NamedBeanHandle<Sensor>, Integer>();
                            for (Element sl : sensorList) {
                                String sensorName = sl.getChild("sensorName").getText();
                                String state = sl.getChild("sensorState").getText();
                                int value = Sensor.INACTIVE;
                                if (state.equals("active")) {
                                    value = Sensor.ACTIVE;
                                }
                                Sensor sen = InstanceManager.sensorManagerInstance().getSensor(sensorName);
                                if (sen != null) {
                                    NamedBeanHandle<Sensor> namedSensor = nbhm.getNamedBeanHandle(sensorName, sen);
                                    list.put(namedSensor, value);
                                }
                                log.debug("Unable to add sensor {} as it does not exist in the panel file", sensorName);
                            }
                            logic.setSensors(list, dest);
                        }
                    }
                    Element blockElem = s.getChild("blocks");
                    if (blockElem != null) {
                        List<Element> blockList = blockElem.getChildren("block");
                        if (blockList.size() > 0) {
                            Hashtable<Block, Integer> list = new Hashtable<Block, Integer>();
                            for (Element b : blockList) {
                                String block = b.getChild("blockName").getText();
                                String state = b.getChild("blockState").getText();
                                int value = 0x03;
                                if (state.equals("occupied")) {
                                    value = Block.OCCUPIED;
                                } else if (state.equals("unoccupied")) {
                                    value = Block.UNOCCUPIED;
                                }
                                Block blk = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(block);
                                if (blk != null) {
                                    list.put(blk, value);
                                }
                                log.debug("Unable to add Block {} as it does not exist in the panel file", block);
                            }
                            logic.setBlocks(list, dest);
                        }
                    }
                    Element mastElem = s.getChild("masts");
                    if (mastElem != null) {
                        List<Element> mastList = mastElem.getChildren("mast");
                        if (mastList.size() > 0) {
                            Hashtable<SignalMast, String> list = new Hashtable<SignalMast, String>();
                            for (Element m : mastList) {
                                String mast = m.getChild("mastName").getText();
                                String state = m.getChild("mastState").getText();
                                SignalMast mst = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(mast);
                                if (mst != null) {
                                    list.put(mst, state);
                                }
                                log.debug("Unable to add Signal Mast {} as it does not exist in the panel file", mast);
                            }
                            logic.setMasts(list, dest);
                        }
                    }
                } else {
                    log.error("Destination Mast " + destination + " Not found, logic not loaded");
                    loadOk = false;
                }
            }
        } else {
            log.error("Source Mast " + source + " Not found, logic not loaded");
            loadOk = false;
        }
    }
    sml.initialise();
    return loadOk;
}
Also used : Element(org.jdom2.Element) SignalMastLogicManager(jmri.SignalMastLogicManager) SignalMast(jmri.SignalMast) NamedBeanHandle(jmri.NamedBeanHandle) Hashtable(java.util.Hashtable) SignalMastManager(jmri.SignalMastManager) Section(jmri.Section) SignalMastLogic(jmri.SignalMastLogic) Block(jmri.Block) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Aggregations

Element (org.jdom2.Element)33 Attribute (org.jdom2.Attribute)10 Document (org.jdom2.Document)6 ArrayList (java.util.ArrayList)4 File (java.io.File)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ProcessingInstruction (org.jdom2.ProcessingInstruction)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 BindView (butterknife.BindView)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 JButton (javax.swing.JButton)2 Block (jmri.Block)2 NamedBeanHandle (jmri.NamedBeanHandle)2 SignalGroup (jmri.SignalGroup)2 SignalGroupManager (jmri.SignalGroupManager)2 SignalMast (jmri.SignalMast)2 SignalMastLogic (jmri.SignalMastLogic)2