Search in sources :

Example 16 with Attribute

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

the class RollingStockAttribute method load.

public void load(Element root, String eNames, String eName, String oldName) {
    // new format using elements starting version 3.3.1
    if (root.getChild(eNames) != null) {
        @SuppressWarnings("unchecked") List<Element> l = root.getChild(eNames).getChildren(eName);
        Attribute a;
        String[] names = new String[l.size()];
        for (int i = 0; i < l.size(); i++) {
            Element name = l.get(i);
            if ((a = name.getAttribute(Xml.NAME)) != null) {
                names[i] = a.getValue();
            }
            // lengths use "VALUE"
            if ((a = name.getAttribute(Xml.VALUE)) != null) {
                names[i] = a.getValue();
            }
        }
        setNames(names);
    } else // try old format
    if (root.getChild(oldName) != null) {
        // NOI18N
        String[] names = root.getChildText(oldName).split("%%");
        setNames(names);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 17 with Attribute

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

the class EngineManager method load.

public void load(Element root) {
    // new format using elements starting version 3.3.1
    if (root.getChild(Xml.NEW_CONSISTS) != null) {
        @SuppressWarnings("unchecked") List<Element> consists = root.getChild(Xml.NEW_CONSISTS).getChildren(Xml.CONSIST);
        log.debug("Engine manager sees {} consists", consists.size());
        Attribute a;
        for (Element consist : consists) {
            if ((a = consist.getAttribute(Xml.NAME)) != null) {
                newConsist(a.getValue());
            }
        }
    } else // old format
    if (root.getChild(Xml.CONSISTS) != null) {
        String names = root.getChildText(Xml.CONSISTS);
        if (!names.equals(NONE)) {
            // NOI18N
            String[] consistNames = names.split("%%");
            log.debug("consists: {}", names);
            for (String name : consistNames) {
                newConsist(name);
            }
        }
    }
    if (root.getChild(Xml.ENGINES) != null) {
        @SuppressWarnings("unchecked") List<Element> engines = root.getChild(Xml.ENGINES).getChildren(Xml.ENGINE);
        log.debug("readFile sees {} engines", engines.size());
        for (Element e : engines) {
            register(new Engine(e));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 18 with Attribute

use of org.jdom2.Attribute 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 19 with Attribute

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

the class TrainManifestText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.MANIFEST_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.MANIFEST_FOR_TRAIN) != null) {
        if ((a = emts.getChild(Xml.MANIFEST_FOR_TRAIN).getAttribute(Xml.TEXT)) != null) {
            setStringManifestForTrain(a.getValue());
        }
    }
    if (emts.getChild(Xml.VALID) != null) {
        if ((a = emts.getChild(Xml.VALID).getAttribute(Xml.TEXT)) != null) {
            setStringValid(a.getValue());
        }
    }
    if (emts.getChild(Xml.SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_DEPARTURE_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_DEPARTURE_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkDepartureTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_ARRIVAL_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_ARRIVAL_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkArrivalTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWorkWithRouteComment(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPART_TIME) != null) {
        if ((a = emts.getChild(Xml.DEPART_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringDepartTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsCars(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsLoads(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_TERMINATES) != null) {
        if ((a = emts.getChild(Xml.TRAIN_TERMINATES).getAttribute(Xml.TEXT)) != null) {
            setStringTrainTerminates(a.getValue());
        }
    }
    if (emts.getChild(Xml.DESTINATION) != null) {
        if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
            setStringDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.TO) != null) {
        if ((a = emts.getChild(Xml.TO).getAttribute(Xml.TEXT)) != null) {
            setStringTo(a.getValue());
        }
    }
    if (emts.getChild(Xml.FROM) != null) {
        if ((a = emts.getChild(Xml.FROM).getAttribute(Xml.TEXT)) != null) {
            setStringFrom(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEST) != null) {
        if ((a = emts.getChild(Xml.DEST).getAttribute(Xml.TEXT)) != null) {
            setStringDest(a.getValue());
        }
    }
    if (emts.getChild(Xml.FINAL_DEST) != null) {
        if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
            setStringFinalDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.ADD_HELPERS) != null) {
        if ((a = emts.getChild(Xml.ADD_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringAddHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.REMOVE_HELPERS) != null) {
        if ((a = emts.getChild(Xml.REMOVE_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringRemoveHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringCabooseChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoAndCabooseChange(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 20 with Attribute

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

the class RosterEntry method loadFunctions.

/**
     * Loads function names from a JDOM element. Does not change values that are
     * already present!
     *
     * @param e3     the XML element containing the functions
     * @param source "family" if source is the decoder definition, or "model" if
     *               source is the roster entry itself
     */
public void loadFunctions(Element e3, String source) {
    /*Load flag once, means that when the roster entry is edited only the first set of function labels are displayed 
         ie those saved in the roster file, rather than those being left blank
         rather than being over-written by the defaults linked to the decoder def*/
    if (loadedOnce) {
        return;
    }
    if (e3 != null) {
        // load function names
        List<Element> l = e3.getChildren(RosterEntry.FUNCTION_LABEL);
        for (Element fn : l) {
            int num = Integer.parseInt(fn.getAttribute("num").getValue());
            String lock = fn.getAttribute("lockable").getValue();
            String val = fn.getText();
            if ((this.getFunctionLabel(num) == null) || (source.equalsIgnoreCase("model"))) {
                this.setFunctionLabel(num, val);
                this.setFunctionLockable(num, lock.equals("true"));
                Attribute a;
                if ((a = fn.getAttribute("functionImage")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionImage(num, null);
                        }
                    }
                }
                if ((a = fn.getAttribute("functionImageSelected")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionSelectedImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionSelectedImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionSelectedImage(num, null);
                        }
                    }
                }
            }
        }
    }
    if (source.equalsIgnoreCase("RosterEntry")) {
        loadedOnce = true;
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)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 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5