Search in sources :

Example 6 with Comment

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

the class MatrixSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * MatrixSignalMastManager
     *
     * @param o Object to store, of type MatrixSignalMast
     * @return e Element containing the complete info
     */
@Override
public Element store(Object o) {
    // from mast p to XML
    MatrixSignalMast p = (MatrixSignalMast) o;
    Element e = new Element("matrixsignalmast");
    e.setAttribute("class", this.getClass().getName());
    // include content
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    // username, comment & properties
    storeCommon(p, e);
    // mast properties:
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
        unlit.addContent(new Element("bitString").addContent(p.getUnLitChars()));
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    List<String> outputs = p.getOutputs();
    // convert char[] to xml-storable simple String
    // max. 5 outputs (either: turnouts (bean names) [or ToDo: DCC addresses (numbers)]
    // spotted by FindBugs as to never be null (check on creation of MatrixMast)
    Element outps = new Element("outputs");
    int i = 1;
    for (String _output : outputs) {
        String key = ("output" + i);
        Element outp = new Element("output");
        outp.setAttribute("matrixCol", key);
        // get name (Turnout)
        outp.addContent(p.getOutputName(i));
        outps.addContent(outp);
        i++;
    }
    if (outputs.size() != 0) {
        e.addContent(outps);
    }
    // string of max. 6 chars "001010" describing matrix row per aspect
    SignalAppearanceMap appMap = p.getAppearanceMap();
    if (appMap != null) {
        Element bss = new Element("bitStrings");
        java.util.Enumeration<String> aspects = appMap.getAspects();
        while (aspects.hasMoreElements()) {
            String key = aspects.nextElement();
            Element bs = new Element("bitString");
            bs.setAttribute("aspect", key);
            bs.addContent(p.getBitstring(key));
            bss.addContent(bs);
        }
        e.addContent(bss);
    }
    List<String> disabledAspects = p.getDisabledAspects();
    if (disabledAspects != null) {
        Element el = new Element("disabledAspects");
        for (String aspect : disabledAspects) {
            Element ele = new Element("disabledAspect");
            ele.addContent(aspect);
            el.addContent(ele);
        }
        if (disabledAspects.size() != 0) {
            e.addContent(el);
        }
    }
    return e;
}
Also used : Element(org.jdom2.Element) SignalAppearanceMap(jmri.SignalAppearanceMap) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 7 with Comment

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

the class XmlFile method addDefaultInfo.

/**
     * Add default information to the XML before writing it out.
     * <P>
     * Currently, this is identification information as an XML comment. This
     * includes: <UL>
     * <LI>The JMRI version used <LI>Date of writing <LI>A CVS id string, in
     * case the file gets checked in or out </UL>
     * <P>
     * It may be necessary to extend this to check whether the info is already
     * present, e.g. if re-writing a file.
     *
     * @param root The root element of the document that will be written.
     */
public static void addDefaultInfo(Element root) {
    String content = "Written by JMRI version " + jmri.Version.name() + " on " + (new Date()).toString() + " $Id$";
    Comment comment = new Comment(content);
    root.addContent(comment);
}
Also used : Comment(org.jdom2.Comment) Date(java.util.Date)

Example 8 with Comment

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

the class Setup method load.

public static void load(Element e) {
    if (e.getChild(Xml.OPERATIONS) == null) {
        log.debug("operation setup values missing");
        return;
    }
    Element operations = e.getChild(Xml.OPERATIONS);
    org.jdom2.Attribute a;
    if ((operations.getChild(Xml.RAIL_ROAD) != null) && (a = operations.getChild(Xml.RAIL_ROAD).getAttribute(Xml.NAME)) != null) {
        String name = a.getValue();
        log.debug("railroadName: {}", name);
        if (name.equals(Xml.USE_JMRI_RAILROAD_NAME)) {
            getDefault().railroadName = null;
        } else {
            // don't set the dirty bit
            getDefault().railroadName = name;
        }
    }
    if ((operations.getChild(Xml.SETUP) != null) && (a = operations.getChild(Xml.SETUP).getAttribute(Xml.COMMENT)) != null) {
        String comment = a.getValue();
        log.debug("setup comment: {}", comment);
        getDefault().setupComment = comment;
    }
    if (operations.getChild(Xml.SETTINGS) != null) {
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.MAIN_MENU)) != null) {
            String enabled = a.getValue();
            log.debug("mainMenu: {}", enabled);
            setMainMenuEnabled(enabled.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CLOSE_ON_SAVE)) != null) {
            String enabled = a.getValue();
            log.debug("closeOnSave: {}", enabled);
            setCloseWindowOnSaveEnabled(enabled.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_DIRECTION)) != null) {
            String dir = a.getValue();
            log.debug("direction: {}", dir);
            try {
                setTrainDirection(Integer.parseInt(dir));
            } catch (NumberFormatException ee) {
                log.error("Train direction ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_LENGTH)) != null) {
            String length = a.getValue();
            log.debug("Max train length: {}", length);
            try {
                setMaxTrainLength(Integer.parseInt(length));
            } catch (NumberFormatException ee) {
                log.error("Train maximum length ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.MAX_ENGINES)) != null) {
            String size = a.getValue();
            log.debug("Max number of engines: {}", size);
            try {
                setMaxNumberEngines(Integer.parseInt(size));
            } catch (NumberFormatException ee) {
                log.error("Maximum number of engines ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.HPT)) != null) {
            String value = a.getValue();
            log.debug("HPT: {}", value);
            try {
                setHorsePowerPerTon(Integer.parseInt(value));
            } catch (NumberFormatException ee) {
                log.error("Train HPT ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SCALE)) != null) {
            String scale = a.getValue();
            log.debug("scale: " + scale);
            try {
                setScale(Integer.parseInt(scale));
            } catch (NumberFormatException ee) {
                log.error("Scale ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_TYPES)) != null) {
            String types = a.getValue();
            log.debug("CarTypes: " + types);
            setCarTypes(types);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SWITCH_TIME)) != null) {
            String minutes = a.getValue();
            log.debug("switchTime: {}", minutes);
            try {
                setSwitchTime(Integer.parseInt(minutes));
            } catch (NumberFormatException ee) {
                log.error("Switch time ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAVEL_TIME)) != null) {
            String minutes = a.getValue();
            log.debug("travelTime: {}", minutes);
            try {
                setTravelTime(Integer.parseInt(minutes));
            } catch (NumberFormatException ee) {
                log.error("Travel time ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SHOW_VALUE)) != null) {
            String enable = a.getValue();
            log.debug("showValue: {}", enable);
            setValueEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.VALUE_LABEL)) != null) {
            String label = a.getValue();
            log.debug("valueLabel: {}", label);
            setValueLabel(label);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SHOW_RFID)) != null) {
            String enable = a.getValue();
            log.debug("showRfid: {}", enable);
            setRfidEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.RFID_LABEL)) != null) {
            String label = a.getValue();
            log.debug("rfidLabel: {}", label);
            setRfidLabel(label);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.LENGTH_UNIT)) != null) {
            String unit = a.getValue();
            log.debug("lengthUnit: {}", unit);
            setLengthUnit(unit);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.YEAR_MODELED)) != null) {
            String year = a.getValue();
            log.debug("yearModeled: {}", year);
            setYearModeled(year);
        }
        // next eight attributes are here for backward compatibility
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_LOC_COMMENTS)) != null) {
            String enable = a.getValue();
            log.debug("printLocComments: {}", enable);
            setPrintLocationCommentsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_ROUTE_COMMENTS)) != null) {
            String enable = a.getValue();
            log.debug("printRouteComments: {}", enable);
            setPrintRouteCommentsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_LOADS_EMPTIES)) != null) {
            String enable = a.getValue();
            log.debug("printLoadsEmpties: {}", enable);
            setPrintLoadsAndEmptiesEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_TIMETABLE)) != null) {
            String enable = a.getValue();
            log.debug("printTimetable: {}", enable);
            setPrintTimetableNameEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.USE12HR_FORMAT)) != null) {
            String enable = a.getValue();
            log.debug("use12hrFormat: {}", enable);
            set12hrFormatEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_VALID)) != null) {
            String enable = a.getValue();
            log.debug("printValid: {}", enable);
            setPrintValidEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.SORT_BY_TRACK)) != null) {
            String enable = a.getValue();
            log.debug("sortByTrack: {}", enable);
            setSortByTrackNameEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.PRINT_HEADERS)) != null) {
            String enable = a.getValue();
            log.debug("printHeaders: {}", enable);
            setPrintHeadersEnabled(enable.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.PICKUP_ENG_FORMAT) != null) {
        if ((a = operations.getChild(Xml.PICKUP_ENG_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setPickupEnginePrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.PICKUP_ENG_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("pickupEngFormat: {}", setting);
            String[] keys = setting.split(",");
            keyToStringConversion(keys);
            setPickupEngineMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.DROP_ENG_FORMAT) != null) {
        if ((a = operations.getChild(Xml.DROP_ENG_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setDropEnginePrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.DROP_ENG_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("dropEngFormat: {}", setting);
            String[] keys = setting.split(",");
            keyToStringConversion(keys);
            setDropEngineMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.PICKUP_CAR_FORMAT) != null) {
        if ((a = operations.getChild(Xml.PICKUP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setPickupCarPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.PICKUP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("pickupCarFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setPickupManifestMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.DROP_CAR_FORMAT) != null) {
        if ((a = operations.getChild(Xml.DROP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setDropCarPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.DROP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("dropCarFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setDropManifestMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.LOCAL_FORMAT) != null) {
        if ((a = operations.getChild(Xml.LOCAL_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setLocalPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.LOCAL_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("localFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setLocalManifestMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.MISSING_CAR_FORMAT) != null) {
        if ((a = operations.getChild(Xml.MISSING_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("missingCarFormat: {}", setting);
            String[] keys = setting.split(",");
            keyToStringConversion(keys);
            setMissingCarMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.SWITCH_LIST) != null) {
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.SAME_AS_MANIFEST)) != null) {
            String b = a.getValue();
            log.debug("sameAsManifest: {}", b);
            setSwitchListFormatSameAsManifest(b.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.REAL_TIME)) != null) {
            String b = a.getValue();
            log.debug("realTime: {}", b);
            getDefault().switchListRealTime = b.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.ALL_TRAINS)) != null) {
            String b = a.getValue();
            log.debug("allTrains: {}", b);
            getDefault().switchListAllTrains = b.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PAGE_FORMAT)) != null) {
            switch(a.getValue()) {
                case Xml.PAGE_NORMAL:
                    getDefault().switchListPageFormat = PAGE_NORMAL;
                    break;
                case Xml.PAGE_PER_TRAIN:
                    getDefault().switchListPageFormat = PAGE_PER_TRAIN;
                    break;
                case Xml.PAGE_PER_VISIT:
                    getDefault().switchListPageFormat = PAGE_PER_VISIT;
                    break;
                default:
                    log.error("Unknown switch list page format {}", a.getValue());
            }
        } else // old way to save switch list page format pre 3.11
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PAGE_MODE)) != null) {
            String b = a.getValue();
            log.debug("old style pageMode: {}", b);
            if (b.equals(Xml.TRUE)) {
                getDefault().switchListPageFormat = PAGE_PER_TRAIN;
            }
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.PRINT_ROUTE_LOCATION)) != null) {
            String b = a.getValue();
            log.debug("print route location comment: {}", b);
            setSwitchListRouteLocationCommentEnabled(b.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST).getAttribute(Xml.TRACK_SUMMARY)) != null) {
            String b = a.getValue();
            log.debug("track summary: {}", b);
            setTrackSummaryEnabled(b.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT) != null) {
        if ((a = operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setSwitchListPickupCarPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("switchListpickupCarFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setPickupSwitchListMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT) != null) {
        if ((a = operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setSwitchListDropCarPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST_DROP_CAR_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("switchListDropCarFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setDropSwitchListMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT) != null) {
        if ((a = operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT).getAttribute(Xml.PREFIX)) != null) {
            setSwitchListLocalPrefix(a.getValue());
        }
        if ((a = operations.getChild(Xml.SWITCH_LIST_LOCAL_FORMAT).getAttribute(Xml.SETTING)) != null) {
            String setting = a.getValue();
            log.debug("switchListLocalFormat: {}", setting);
            String[] keys = setting.split(",");
            replaceOldFormat(keys);
            xmlAttributeToKeyConversion(keys);
            keyToStringConversion(keys);
            setLocalSwitchListMessageFormat(keys);
        }
    }
    if (operations.getChild(Xml.PANEL) != null) {
        if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.NAME)) != null) {
            String panel = a.getValue();
            log.debug("panel: {}", panel);
            setPanelName(panel);
        }
        if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.TRAIN_ICONXY)) != null) {
            String enable = a.getValue();
            log.debug("TrainIconXY: {}", enable);
            setTrainIconCordEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.PANEL).getAttribute(Xml.TRAIN_ICON_APPEND)) != null) {
            String enable = a.getValue();
            log.debug("TrainIconAppend: {}", enable);
            setTrainIconAppendEnabled(enable.equals(Xml.TRUE));
        }
    }
    if ((operations.getChild(Xml.FONT_NAME) != null) && (a = operations.getChild(Xml.FONT_NAME).getAttribute(Xml.NAME)) != null) {
        String font = a.getValue();
        log.debug("fontName: {}", font);
        setFontName(font);
    }
    if ((operations.getChild(Xml.FONT_SIZE) != null) && (a = operations.getChild(Xml.FONT_SIZE).getAttribute(Xml.SIZE)) != null) {
        String size = a.getValue();
        log.debug("fontsize: {}", size);
        try {
            setManifestFontSize(Integer.parseInt(size));
        } catch (NumberFormatException ee) {
            log.error("Manifest font size ({}) isn't a valid number", a.getValue());
        }
    }
    if ((operations.getChild(Xml.PAGE_ORIENTATION) != null)) {
        if ((a = operations.getChild(Xml.PAGE_ORIENTATION).getAttribute(Xml.MANIFEST)) != null) {
            String orientation = a.getValue();
            log.debug("manifestOrientation: {}", orientation);
            setManifestOrientation(orientation);
        }
        if ((a = operations.getChild(Xml.PAGE_ORIENTATION).getAttribute(Xml.SWITCH_LIST)) != null) {
            String orientation = a.getValue();
            log.debug("switchListOrientation: {}", orientation);
            setSwitchListOrientation(orientation);
        }
    }
    if ((operations.getChild(Xml.MANIFEST_COLORS) != null)) {
        if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.DROP_COLOR)) != null) {
            String dropColor = a.getValue();
            log.debug("dropColor: {}", dropColor);
            setDropTextColor(dropColor);
        }
        if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.PICKUP_COLOR)) != null) {
            String pickupColor = a.getValue();
            log.debug("pickupColor: {}", pickupColor);
            setPickupTextColor(pickupColor);
        }
        if ((a = operations.getChild(Xml.MANIFEST_COLORS).getAttribute(Xml.LOCAL_COLOR)) != null) {
            String localColor = a.getValue();
            log.debug("localColor: {}", localColor);
            setLocalTextColor(localColor);
        }
    }
    if ((operations.getChild(Xml.TAB) != null)) {
        if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("tab: {}", enable);
            setTabEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.LENGTH)) != null) {
            String length = a.getValue();
            log.debug("tab 1 length: {}", length);
            try {
                setTab1length(Integer.parseInt(length));
            } catch (NumberFormatException ee) {
                log.error("Tab 1 length ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.TAB2_LENGTH)) != null) {
            String length = a.getValue();
            log.debug("tab 2 length: {}", length);
            try {
                setTab2length(Integer.parseInt(length));
            } catch (NumberFormatException ee) {
                log.error("Tab 2 length ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.TAB).getAttribute(Xml.TAB3_LENGTH)) != null) {
            String length = a.getValue();
            log.debug("tab 3 length: {}", length);
            try {
                setTab3length(Integer.parseInt(length));
            } catch (NumberFormatException ee) {
                log.error("Tab 3 length ({}) isn't a valid number", a.getValue());
            }
        }
    }
    if ((operations.getChild(Xml.MANIFEST) != null)) {
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_LOC_COMMENTS)) != null) {
            String enable = a.getValue();
            log.debug("manifest printLocComments: {}", enable);
            setPrintLocationCommentsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_ROUTE_COMMENTS)) != null) {
            String enable = a.getValue();
            log.debug("manifest printRouteComments: {}", enable);
            setPrintRouteCommentsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_LOADS_EMPTIES)) != null) {
            String enable = a.getValue();
            log.debug("manifest printLoadsEmpties: {}", enable);
            setPrintLoadsAndEmptiesEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_TIMETABLE)) != null) {
            String enable = a.getValue();
            log.debug("manifest printTimetable: {}", enable);
            setPrintTimetableNameEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE12HR_FORMAT)) != null) {
            String enable = a.getValue();
            log.debug("manifest use12hrFormat: {}", enable);
            set12hrFormatEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_VALID)) != null) {
            String enable = a.getValue();
            log.debug("manifest printValid: {}", enable);
            setPrintValidEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.SORT_BY_TRACK)) != null) {
            String enable = a.getValue();
            log.debug("manifest sortByTrack: {}", enable);
            setSortByTrackNameEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_HEADERS)) != null) {
            String enable = a.getValue();
            log.debug("manifest print headers: {}", enable);
            setPrintHeadersEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.TRUNCATE)) != null) {
            String enable = a.getValue();
            log.debug("manifest truncate: {}", enable);
            setTruncateManifestEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE_DEPARTURE_TIME)) != null) {
            String enable = a.getValue();
            log.debug("manifest use departure time: {}", enable);
            setUseDepartureTimeEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.USE_EDITOR)) != null) {
            String enable = a.getValue();
            log.debug("manifest useEditor: {}", enable);
            setManifestEditorEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_CABOOSE_LOAD)) != null) {
            String enable = a.getValue();
            log.debug("manifest print caboose load: {}", enable);
            setPrintCabooseLoadEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.PRINT_PASSENGER_LOAD)) != null) {
            String enable = a.getValue();
            log.debug("manifest print passenger load: {}", enable);
            setPrintPassengerLoadEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.MANIFEST).getAttribute(Xml.HAZARDOUS_MSG)) != null) {
            String message = a.getValue();
            log.debug("manifest hazardousMsg: {}", message);
            setHazardousMsg(message);
        }
    }
    if ((operations.getChild(Xml.MANIFEST_FORMAT) != null)) {
        if ((a = operations.getChild(Xml.MANIFEST_FORMAT).getAttribute(Xml.VALUE)) != null) {
            switch(a.getValue()) {
                case Xml.STANDARD:
                    getDefault().manifestFormat = STANDARD_FORMAT;
                    break;
                case Xml.TWO_COLUMN:
                    getDefault().manifestFormat = TWO_COLUMN_FORMAT;
                    break;
                case Xml.TWO_COLUMN_TRACK:
                    getDefault().manifestFormat = TWO_COLUMN_TRACK_FORMAT;
                    break;
                default:
                    log.debug("Unknown manifest format");
            }
        }
    } else if ((operations.getChild(Xml.COLUMN_FORMAT) != null)) {
        if ((a = operations.getChild(Xml.COLUMN_FORMAT).getAttribute(Xml.TWO_COLUMNS)) != null) {
            String enable = a.getValue();
            log.debug("two columns: {}", enable);
            if (enable.equals(Xml.TRUE)) {
                setManifestFormat(TWO_COLUMN_FORMAT);
            }
        }
    }
    // get manifest logo
    if ((operations.getChild(Xml.MANIFEST_LOGO) != null)) {
        if ((a = operations.getChild(Xml.MANIFEST_LOGO).getAttribute(Xml.NAME)) != null) {
            setManifestLogoURL(a.getValue());
        }
    }
    // manifest file options
    if ((operations.getChild(Xml.MANIFEST_FILE_OPTIONS) != null)) {
        if ((a = operations.getChild(Xml.MANIFEST_FILE_OPTIONS).getAttribute(Xml.MANIFEST_SAVE)) != null) {
            String enable = a.getValue();
            log.debug("manifest file save option: {}", enable);
            getDefault().saveTrainManifests = enable.equals(Xml.TRUE);
        }
    }
    if ((operations.getChild(Xml.BUILD_OPTIONS) != null)) {
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.AGGRESSIVE)) != null) {
            String enable = a.getValue();
            log.debug("aggressive: {}", enable);
            setBuildAggressive(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.NUMBER_PASSES)) != null) {
            String number = a.getValue();
            log.debug("number of passes: {}", number);
            try {
                setNumberPasses(Integer.parseInt(number));
            } catch (NumberFormatException ne) {
                log.debug("Number of passes isn't a number");
            }
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_INTERCHANGE)) != null) {
            String enable = a.getValue();
            log.debug("noLocalInterchange: {}", enable);
            setLocalInterchangeMovesEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_SPUR)) != null) {
            String enable = a.getValue();
            log.debug("noLocalSpur: {}", enable);
            setLocalSpurMovesEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_LOCAL_YARD)) != null) {
            String enable = a.getValue();
            log.debug("noLocalYard: {}", enable);
            setLocalYardMovesEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.STAGING_RESTRICTION_ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("stagingRestrictionEnabled: {}", enable);
            setTrainIntoStagingCheckEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.STAGING_TRACK_AVAIL)) != null) {
            String enable = a.getValue();
            log.debug("stagingTrackAvail: {}", enable);
            setStagingTrackImmediatelyAvail(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.ALLOW_RETURN_STAGING)) != null) {
            String enable = a.getValue();
            log.debug("allowReturnStaging: {}", enable);
            setAllowReturnToStagingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.PROMPT_STAGING_ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("promptStagingEnabled: {}", enable);
            setPromptFromStagingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.PROMPT_TO_STAGING_ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("promptToStagingEnabled: {}", enable);
            setPromptToStagingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.GENERATE_CSV_MANIFEST)) != null) {
            String enable = a.getValue();
            log.debug("generateCvsManifest: {}", enable);
            getDefault().generateCsvManifest = enable.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.BUILD_OPTIONS).getAttribute(Xml.GENERATE_CSV_SWITCH_LIST)) != null) {
            String enable = a.getValue();
            log.debug("generateCvsSwitchList: {}", enable);
            getDefault().generateCsvSwitchList = enable.equals(Xml.TRUE);
        }
    }
    if (operations.getChild(Xml.BUILD_REPORT) != null) {
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.LEVEL)) != null) {
            String level = a.getValue();
            log.debug("buildReportLevel: {}", level);
            setBuildReportLevel(level);
        }
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.ROUTER_LEVEL)) != null) {
            String level = a.getValue();
            log.debug("routerBuildReportLevel: {}", level);
            setRouterBuildReportLevel(level);
        }
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.USE_EDITOR)) != null) {
            String enable = a.getValue();
            log.debug("build report useEditor: {}", enable);
            setBuildReportEditorEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.INDENT)) != null) {
            String enable = a.getValue();
            log.debug("build report indent: {}", enable);
            setBuildReportIndentEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.FONT_SIZE)) != null) {
            String size = a.getValue();
            log.debug("build font size: {}", size);
            try {
                setBuildReportFontSize(Integer.parseInt(size));
            } catch (NumberFormatException ee) {
                log.error("Build report font size ({}) isn't a valid number", a.getValue());
            }
        }
        if ((a = operations.getChild(Xml.BUILD_REPORT).getAttribute(Xml.ALWAYS_PREVIEW)) != null) {
            String enable = a.getValue();
            log.debug("build report always preview: {}", enable);
            setBuildReportAlwaysPreviewEnabled(enable.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.ROUTER) != null) {
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingEnabled: {}", enable);
            setCarRoutingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_VIA_YARDS)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingViaYards: {}", enable);
            setCarRoutingViaYardsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CAR_ROUTING_VIA_STAGING)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingViaStaging: {}", enable);
            setCarRoutingViaStagingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.FORWARD_TO_YARD)) != null) {
            String enable = a.getValue();
            log.debug("forwardToYard: {}", enable);
            setForwardToYardEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.ONLY_ACTIVE_TRAINS)) != null) {
            String enable = a.getValue();
            log.debug("onlyActiveTrains: {}", enable);
            setOnlyActiveTrainsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.ROUTER).getAttribute(Xml.CHECK_CAR_DESTINATION)) != null) {
            String enable = a.getValue();
            log.debug("checkCarDestination: {}", enable);
            setCheckCarDestinationEnabled(enable.equals(Xml.TRUE));
        }
    } else if (operations.getChild(Xml.SETTINGS) != null) {
        // the next four items are for backwards compatibility
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_ENABLED)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingEnabled: {}", enable);
            setCarRoutingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_VIA_YARDS)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingViaYards: {}", enable);
            setCarRoutingViaYardsEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_ROUTING_VIA_STAGING)) != null) {
            String enable = a.getValue();
            log.debug("carRoutingViaStaging: {}", enable);
            setCarRoutingViaStagingEnabled(enable.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.FORWARD_TO_YARD)) != null) {
            String enable = a.getValue();
            log.debug("forwardToYard: {}", enable);
            setForwardToYardEnabled(enable.equals(Xml.TRUE));
        }
    }
    if ((operations.getChild(Xml.OWNER) != null) && (a = operations.getChild(Xml.OWNER).getAttribute(Xml.NAME)) != null) {
        String owner = a.getValue();
        log.debug("owner: {}", owner);
        setOwnerName(owner);
    }
    if (operations.getChild(Xml.ICON_COLOR) != null) {
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.NORTH)) != null) {
            String color = a.getValue();
            log.debug("north color: {}", color);
            setTrainIconColorNorth(color);
        }
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.SOUTH)) != null) {
            String color = a.getValue();
            log.debug("south color: {}", color);
            setTrainIconColorSouth(color);
        }
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.EAST)) != null) {
            String color = a.getValue();
            log.debug("east color: {}", color);
            setTrainIconColorEast(color);
        }
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.WEST)) != null) {
            String color = a.getValue();
            log.debug("west color: {}", color);
            setTrainIconColorWest(color);
        }
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.LOCAL)) != null) {
            String color = a.getValue();
            log.debug("local color: {}", color);
            setTrainIconColorLocal(color);
        }
        if ((a = operations.getChild(Xml.ICON_COLOR).getAttribute(Xml.TERMINATE)) != null) {
            String color = a.getValue();
            log.debug("terminate color: {}", color);
            setTrainIconColorTerminate(color);
        }
    }
    if (operations.getChild(Xml.COMMENTS) != null) {
        if ((a = operations.getChild(Xml.COMMENTS).getAttribute(Xml.MISPLACED_CARS)) != null) {
            String comment = a.getValue();
            log.debug("Misplaced comment: {}", comment);
            setMiaComment(comment);
        }
    }
    if (operations.getChild(Xml.DISPLAY) != null) {
        if ((a = operations.getChild(Xml.DISPLAY).getAttribute(Xml.SHOW_TRACK_MOVES)) != null) {
            String enable = a.getValue();
            log.debug("show track moves: {}", enable);
            getDefault().showTrackMoves = enable.equals(Xml.TRUE);
        }
    }
    if (operations.getChild(Xml.VSD) != null) {
        if ((a = operations.getChild(Xml.VSD).getAttribute(Xml.ENABLE_PHYSICAL_LOCATIONS)) != null) {
            String enable = a.getValue();
            setVsdPhysicalLocationEnabled(enable.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.CATS) != null) {
        if ((a = operations.getChild(Xml.CATS).getAttribute(Xml.EXACT_LOCATION_NAME)) != null) {
            String enable = a.getValue();
            AbstractOperationsServer.setExactLocationName(enable.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.SETTINGS) != null) {
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.AUTO_SAVE)) != null) {
            String enabled = a.getValue();
            log.debug("autoSave: {}", enabled);
            setAutoSaveEnabled(enabled.equals(Xml.TRUE));
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.AUTO_BACKUP)) != null) {
            String enabled = a.getValue();
            log.debug("autoBackup: {}", enabled);
            setAutoBackupEnabled(enabled.equals(Xml.TRUE));
        }
    }
    if (operations.getChild(Xml.LOGGER) != null) {
        if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.CAR_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("carLogger: {}", enable);
            getDefault().carLogger = enable.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.ENGINE_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("engineLogger: {}", enable);
            getDefault().engineLogger = enable.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.LOGGER).getAttribute(Xml.TRAIN_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("trainLogger: {}", enable);
            getDefault().trainLogger = enable.equals(Xml.TRUE);
        }
    } else if (operations.getChild(Xml.SETTINGS) != null) {
        // for backward compatibility
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.CAR_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("carLogger: {}", enable);
            getDefault().carLogger = enable.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.ENGINE_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("engineLogger: {}", enable);
            getDefault().engineLogger = enable.equals(Xml.TRUE);
        }
        if ((a = operations.getChild(Xml.SETTINGS).getAttribute(Xml.TRAIN_LOGGER)) != null) {
            String enable = a.getValue();
            log.debug("trainLogger: {}", enable);
            getDefault().trainLogger = enable.equals(Xml.TRUE);
        }
    }
}
Also used : Element(org.jdom2.Element)

Example 9 with Comment

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

the class TrainManifestHeaderText method store.

// must synchronize changes with operation-config.dtd
public static Element store() {
    Element values;
    Element e = new Element(Xml.MANIFEST_HEADER_TEXT_STRINGS);
    // only save strings that have been modified
    if (!getStringHeader_Road().equals(Bundle.getMessage("Road"))) {
        e.addContent(values = new Element(Xml.ROAD));
        values.setAttribute(Xml.TEXT, getStringHeader_Road());
    }
    if (!getStringHeader_Number().equals(Bundle.getMessage("Number"))) {
        e.addContent(values = new Element(Xml.NUMBER));
        values.setAttribute(Xml.TEXT, getStringHeader_Number());
    }
    if (!getStringHeader_EngineNumber().equals(Bundle.getMessage("Number"))) {
        e.addContent(values = new Element(Xml.ENGINE_NUMBER));
        values.setAttribute(Xml.TEXT, getStringHeader_EngineNumber());
    }
    if (!getStringHeader_Type().equals(Bundle.getMessage("Type"))) {
        e.addContent(values = new Element(Xml.TYPE));
        values.setAttribute(Xml.TEXT, getStringHeader_Type());
    }
    if (!getStringHeader_Model().equals(Bundle.getMessage("Model"))) {
        e.addContent(values = new Element(Xml.MODEL));
        values.setAttribute(Xml.TEXT, getStringHeader_Model());
    }
    if (!getStringHeader_Length().equals(Bundle.getMessage("Length"))) {
        e.addContent(values = new Element(Xml.LENGTH));
        values.setAttribute(Xml.TEXT, getStringHeader_Length());
    }
    if (!getStringHeader_Load().equals(Bundle.getMessage("Load"))) {
        e.addContent(values = new Element(Xml.LOAD));
        values.setAttribute(Xml.TEXT, getStringHeader_Load());
    }
    if (!getStringHeader_Color().equals(Bundle.getMessage("Color"))) {
        e.addContent(values = new Element(Xml.COLOR));
        values.setAttribute(Xml.TEXT, getStringHeader_Color());
    }
    if (!getStringHeader_Track().equals(Bundle.getMessage("Track"))) {
        e.addContent(values = new Element(Xml.TRACK));
        values.setAttribute(Xml.TEXT, getStringHeader_Track());
    }
    if (!getStringHeader_Destination().equals(Bundle.getMessage("Destination"))) {
        e.addContent(values = new Element(Xml.DESTINATION));
        values.setAttribute(Xml.TEXT, getStringHeader_Destination());
    }
    if (!getStringHeader_Dest_Track().equals(Bundle.getMessage("Dest&Track"))) {
        e.addContent(values = new Element(Xml.DEST_TRACK));
        values.setAttribute(Xml.TEXT, getStringHeader_Dest_Track());
    }
    if (!getStringHeader_Final_Dest().equals(Bundle.getMessage("Final_Dest"))) {
        e.addContent(values = new Element(Xml.FINAL_DEST));
        values.setAttribute(Xml.TEXT, getStringHeader_Final_Dest());
    }
    if (!getStringHeader_Final_Dest_Track().equals(Bundle.getMessage("FD&Track"))) {
        e.addContent(values = new Element(Xml.FINAL_DEST_TRACK));
        values.setAttribute(Xml.TEXT, getStringHeader_Final_Dest_Track());
    }
    if (!getStringHeader_Location().equals(Bundle.getMessage("Location"))) {
        e.addContent(values = new Element(Xml.LOCATION));
        values.setAttribute(Xml.TEXT, getStringHeader_Location());
    }
    if (!getStringHeader_Consist().equals(Bundle.getMessage("Consist"))) {
        e.addContent(values = new Element(Xml.CONSIST));
        values.setAttribute(Xml.TEXT, getStringHeader_Consist());
    }
    if (!getStringHeader_Kernel().equals(Bundle.getMessage("Kernel"))) {
        e.addContent(values = new Element(Xml.KERNEL));
        values.setAttribute(Xml.TEXT, getStringHeader_Kernel());
    }
    if (!getStringHeader_Owner().equals(Bundle.getMessage("Owner"))) {
        e.addContent(values = new Element(Xml.OWNER));
        values.setAttribute(Xml.TEXT, getStringHeader_Owner());
    }
    if (!getStringHeader_RWE().equals(Bundle.getMessage("RWELabel"))) {
        e.addContent(values = new Element(Xml.RWE));
        values.setAttribute(Xml.TEXT, getStringHeader_RWE());
    }
    if (!getStringHeader_Comment().equals(Bundle.getMessage("Comment"))) {
        e.addContent(values = new Element(Xml.COMMENT));
        values.setAttribute(Xml.TEXT, getStringHeader_Comment());
    }
    if (!getStringHeader_Drop_Comment().equals(Bundle.getMessage("SetOut_Msg"))) {
        e.addContent(values = new Element(Xml.DROP_COMMENT));
        values.setAttribute(Xml.TEXT, getStringHeader_Drop_Comment());
    }
    if (!getStringHeader_Pickup_Comment().equals(Bundle.getMessage("PickUp_Msg"))) {
        e.addContent(values = new Element(Xml.PICKUP_COMMENT));
        values.setAttribute(Xml.TEXT, getStringHeader_Pickup_Comment());
    }
    if (!getStringHeader_Hazardous().equals(Bundle.getMessage("Hazardous"))) {
        e.addContent(values = new Element(Xml.HAZARDOUS));
        values.setAttribute(Xml.TEXT, getStringHeader_Hazardous());
    }
    return e;
}
Also used : Element(org.jdom2.Element)

Example 10 with Comment

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

the class RosterEntry method store.

/**
     * Create an XML element to represent this Entry.
     * <p>
     * This member has to remain
     * synchronized with the detailed DTD in roster-config.xml.
     *
     * @return Contents in a JDOM Element
     */
@Override
public Element store() {
    Element e = new Element("locomotive");
    e.setAttribute("id", getId());
    e.setAttribute("fileName", getFileName());
    e.setAttribute("roadNumber", getRoadNumber());
    e.setAttribute("roadName", getRoadName());
    e.setAttribute("mfg", getMfg());
    e.setAttribute("owner", getOwner());
    e.setAttribute("model", getModel());
    e.setAttribute("dccAddress", getDccAddress());
    //e.setAttribute("protocol",""+getProtocol());
    e.setAttribute("comment", getComment());
    e.setAttribute(RosterEntry.MAX_SPEED, (Integer.toString(getMaxSpeedPCT())));
    // file path are saved without default xml config path
    e.setAttribute("imageFilePath", (this.getImagePath() != null) ? FileUtil.getPortableFilename(this.getImagePath()) : "");
    e.setAttribute("iconFilePath", (this.getIconPath() != null) ? FileUtil.getPortableFilename(this.getIconPath()) : "");
    e.setAttribute("URL", getURL());
    e.setAttribute(RosterEntry.SHUNTING_FUNCTION, getShuntingFunction());
    if (_dateUpdated.isEmpty()) {
        // set date updated to now if never set previously
        this.changeDateUpdated();
    }
    e.addContent(new Element("dateUpdated").addContent(this.getDateUpdated()));
    Element d = new Element("decoder");
    d.setAttribute("model", getDecoderModel());
    d.setAttribute("family", getDecoderFamily());
    d.setAttribute("comment", getDecoderComment());
    e.addContent(d);
    if (_dccAddress.isEmpty()) {
        // store a null address
        e.addContent((new jmri.configurexml.LocoAddressXml()).store(null));
    } else {
        e.addContent((new jmri.configurexml.LocoAddressXml()).store(new DccLocoAddress(Integer.parseInt(_dccAddress), _protocol)));
    }
    if (functionLabels != null) {
        d = new Element("functionlabels");
        // loop to copy non-null elements
        for (int i = 0; i <= MAXFNNUM; i++) {
            if (functionLabels[i] != null && !functionLabels[i].isEmpty()) {
                Element fne = new Element(RosterEntry.FUNCTION_LABEL);
                fne.setAttribute("num", "" + i);
                boolean lockable = false;
                if (functionLockables != null) {
                    lockable = functionLockables[i];
                }
                fne.setAttribute("lockable", lockable ? "true" : "false");
                if ((functionImages != null)) {
                    fne.setAttribute("functionImage", (functionImages[i] != null) ? FileUtil.getPortableFilename(functionImages[i]) : "");
                }
                if ((functionSelectedImages != null)) {
                    fne.setAttribute("functionImageSelected", (functionSelectedImages[i] != null) ? FileUtil.getPortableFilename(functionSelectedImages[i]) : "");
                }
                fne.addContent(functionLabels[i]);
                d.addContent(fne);
            }
        }
        e.addContent(d);
    }
    if (soundLabels != null) {
        d = new Element("soundlabels");
        // loop to copy non-null elements
        for (int i = 0; i < MAXSOUNDNUM; i++) {
            if (soundLabels[i] != null && !soundLabels[i].isEmpty()) {
                Element fne = new Element(RosterEntry.SOUND_LABEL);
                fne.setAttribute("num", "" + i);
                fne.addContent(soundLabels[i]);
                d.addContent(fne);
            }
        }
        e.addContent(d);
    }
    if (!getAttributes().isEmpty()) {
        d = new Element("attributepairs");
        for (String key : getAttributes()) {
            d.addContent(new Element("keyvaluepair").addContent(new Element("key").addContent(key)).addContent(new Element("value").addContent(getAttribute(key))));
        }
        e.addContent(d);
    }
    if (_sp != null) {
        _sp.store(e);
    }
    return e;
}
Also used : Element(org.jdom2.Element) DccLocoAddress(jmri.DccLocoAddress)

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