use of org.jdom2.output.Format in project JMRI by JMRI.
the class BlockValueFile method writeBlockValues.
/*
* Writes out block values to a file in the user's preferences directory
* If there are no defined Blocks, no file is written.
* If none of the defined Blocks have values, no file is written.
*/
public void writeBlockValues() throws java.io.IOException {
log.debug("entered writeBlockValues");
List<String> blocks = blockManager.getSystemNameList();
if (blocks.size() > 0) {
// there are blocks defined, create root element
root = new Element("block_values");
doc = newDocument(root, dtdLocation + "block-values.dtd");
boolean valuesFound = false;
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/block-values.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "blockValues.xsl");
org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// save block values in xml format
Element values = new Element("blockvalues");
for (int i = 0; i < blocks.size(); i++) {
String sname = blocks.get(i);
Block b = blockManager.getBySystemName(sname);
if (b != null) {
Object o = b.getValue();
if (o != null) {
// block has value, save it
Element val = new Element("block");
val.setAttribute("systemname", sname);
if (o instanceof jmri.jmrit.roster.RosterEntry) {
val.setAttribute("value", ((jmri.jmrit.roster.RosterEntry) o).getId());
val.setAttribute("valueClass", "jmri.jmrit.roster.RosterEntry");
} else {
val.setAttribute("value", o.toString());
}
int v = b.getDirection();
if (v != jmri.Path.NONE) {
val.setAttribute("dir", "" + v);
}
values.addContent(val);
valuesFound = true;
}
} else {
log.error("Block " + sname + " was not found.");
}
}
root.addContent(values);
// write out the file if values were found
if (valuesFound) {
try {
if (!checkFile(defaultFileName)) {
// file does not exist, create it
File file = new File(defaultFileName);
if (// create and check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
}
// write content to file
writeXML(findFile(defaultFileName), doc);
} catch (java.io.IOException ioe) {
log.error("IO Exception " + ioe);
throw (ioe);
}
}
}
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class EngineManager method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-engines.dtd.
* @param root The common Element for operations-engines.dtd.
*
*/
public void store(Element root) {
// root.addContent(new Element(Xml.OPTIONS)); // nothing to store under options
Element values;
List<String> names = getConsistNameList();
if (Control.backwardCompatible) {
root.addContent(values = new Element(Xml.CONSISTS));
for (String name : names) {
// NOI18N
String consistNames = name + "%%";
values.addContent(consistNames);
}
}
// new format using elements
Element consists = new Element(Xml.NEW_CONSISTS);
for (String name : names) {
Element consist = new Element(Xml.CONSIST);
consist.setAttribute(new Attribute(Xml.NAME, name));
consists.addContent(consist);
}
root.addContent(consists);
root.addContent(values = new Element(Xml.ENGINES));
// add entries
for (RollingStock rs : getByRoadNameList()) {
Engine eng = (Engine) rs;
values.addContent(eng.store());
}
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class Setup method store.
// must synchronize changes with operation-config.dtd
public static Element store() {
Element values;
Element e = new Element(Xml.OPERATIONS);
e.addContent(values = new Element(Xml.RAIL_ROAD));
if (Setup.getRailroadName().equals(WebServerPreferences.getDefault().getRailRoadName())) {
values.setAttribute(Xml.NAME, Xml.USE_JMRI_RAILROAD_NAME);
} else {
values.setAttribute(Xml.NAME, getRailroadName());
}
e.addContent(values = new Element(Xml.SETUP));
values.setAttribute(Xml.COMMENT, getComment());
e.addContent(values = new Element(Xml.SETTINGS));
values.setAttribute(Xml.MAIN_MENU, isMainMenuEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.CLOSE_ON_SAVE, isCloseWindowOnSaveEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.AUTO_SAVE, isAutoSaveEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.AUTO_BACKUP, isAutoBackupEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.TRAIN_DIRECTION, Integer.toString(getTrainDirection()));
values.setAttribute(Xml.TRAIN_LENGTH, Integer.toString(getMaxTrainLength()));
values.setAttribute(Xml.MAX_ENGINES, Integer.toString(getMaxNumberEngines()));
values.setAttribute(Xml.HPT, Integer.toString(getHorsePowerPerTon()));
values.setAttribute(Xml.SCALE, Integer.toString(getScale()));
values.setAttribute(Xml.CAR_TYPES, getCarTypes());
values.setAttribute(Xml.SWITCH_TIME, Integer.toString(getSwitchTime()));
values.setAttribute(Xml.TRAVEL_TIME, Integer.toString(getTravelTime()));
values.setAttribute(Xml.SHOW_VALUE, isValueEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.VALUE_LABEL, getValueLabel());
values.setAttribute(Xml.SHOW_RFID, isRfidEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.RFID_LABEL, getRfidLabel());
values.setAttribute(Xml.LENGTH_UNIT, getLengthUnit());
values.setAttribute(Xml.YEAR_MODELED, getYearModeled());
// next 7 manifest attributes for backward compatibility TODO remove in future release 2014
// values.setAttribute(Xml.PRINT_LOC_COMMENTS, isPrintLocationCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.PRINT_ROUTE_COMMENTS, isPrintRouteCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.PRINT_LOADS_EMPTIES, isPrintLoadsAndEmptiesEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.PRINT_TIMETABLE, isPrintTimetableNameEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.USE12HR_FORMAT, is12hrFormatEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.PRINT_VALID, isPrintValidEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.SORT_BY_TRACK, isSortByTrackEnabled() ? Xml.TRUE : Xml.FALSE);
// This one was left out, wait until 2016
values.setAttribute(Xml.PRINT_HEADERS, isPrintHeadersEnabled() ? Xml.TRUE : Xml.FALSE);
// next three logger attributes for backward compatibility TODO remove in future release 2014
// values.setAttribute(Xml.CAR_LOGGER, isCarLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.ENGINE_LOGGER, isEngineLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
// values.setAttribute(Xml.TRAIN_LOGGER, isTrainLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.PICKUP_ENG_FORMAT));
storeXmlMessageFormat(values, getPickupEnginePrefix(), getPickupEngineMessageFormat());
e.addContent(values = new Element(Xml.DROP_ENG_FORMAT));
storeXmlMessageFormat(values, getDropEnginePrefix(), getDropEngineMessageFormat());
e.addContent(values = new Element(Xml.PICKUP_CAR_FORMAT));
storeXmlMessageFormat(values, getPickupCarPrefix(), getPickupManifestMessageFormat());
e.addContent(values = new Element(Xml.DROP_CAR_FORMAT));
storeXmlMessageFormat(values, getDropCarPrefix(), getDropManifestMessageFormat());
e.addContent(values = new Element(Xml.LOCAL_FORMAT));
storeXmlMessageFormat(values, getLocalPrefix(), getLocalManifestMessageFormat());
e.addContent(values = new Element(Xml.MISSING_CAR_FORMAT));
storeXmlMessageFormat(values, NONE, getMissingCarMessageFormat());
e.addContent(values = new Element(Xml.SWITCH_LIST));
values.setAttribute(Xml.SAME_AS_MANIFEST, isSwitchListFormatSameAsManifest() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.REAL_TIME, isSwitchListRealTime() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ALL_TRAINS, isSwitchListAllTrainsEnabled() ? Xml.TRUE : Xml.FALSE);
// save switch list format
String format = Xml.PAGE_NORMAL;
if (getSwitchListPageFormat().equals(PAGE_PER_TRAIN)) {
format = Xml.PAGE_PER_TRAIN;
// backwards compatible for versions before 3.11
values.setAttribute(Xml.PAGE_MODE, Xml.TRUE);
} else if (getSwitchListPageFormat().equals(PAGE_PER_VISIT)) {
format = Xml.PAGE_PER_VISIT;
}
values.setAttribute(Xml.PAGE_FORMAT, format);
values.setAttribute(Xml.PRINT_ROUTE_LOCATION, isSwitchListRouteLocationCommentEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.TRACK_SUMMARY, isTrackSummaryEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.SWITCH_LIST_PICKUP_CAR_FORMAT));
storeXmlMessageFormat(values, getSwitchListPickupCarPrefix(), getPickupSwitchListMessageFormat());
e.addContent(values = new Element(Xml.SWITCH_LIST_DROP_CAR_FORMAT));
storeXmlMessageFormat(values, getSwitchListDropCarPrefix(), getDropSwitchListMessageFormat());
e.addContent(values = new Element(Xml.SWITCH_LIST_LOCAL_FORMAT));
storeXmlMessageFormat(values, getSwitchListLocalPrefix(), getLocalSwitchListMessageFormat());
e.addContent(values = new Element(Xml.PANEL));
values.setAttribute(Xml.NAME, getPanelName());
values.setAttribute(Xml.TRAIN_ICONXY, isTrainIconCordEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.TRAIN_ICON_APPEND, isTrainIconAppendEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.FONT_NAME));
values.setAttribute(Xml.NAME, getFontName());
e.addContent(values = new Element(Xml.FONT_SIZE));
values.setAttribute(Xml.SIZE, Integer.toString(getManifestFontSize()));
e.addContent(values = new Element(Xml.PAGE_ORIENTATION));
values.setAttribute(Xml.MANIFEST, getManifestOrientation());
values.setAttribute(Xml.SWITCH_LIST, getSwitchListOrientation());
e.addContent(values = new Element(Xml.MANIFEST_COLORS));
values.setAttribute(Xml.DROP_COLOR, getDropTextColor());
values.setAttribute(Xml.PICKUP_COLOR, getPickupTextColor());
values.setAttribute(Xml.LOCAL_COLOR, getLocalTextColor());
e.addContent(values = new Element(Xml.TAB));
values.setAttribute(Xml.ENABLED, isTabEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.LENGTH, Integer.toString(getTab1Length()));
values.setAttribute(Xml.TAB2_LENGTH, Integer.toString(getTab2Length()));
values.setAttribute(Xml.TAB3_LENGTH, Integer.toString(getTab3Length()));
e.addContent(values = new Element(Xml.MANIFEST));
values.setAttribute(Xml.PRINT_LOC_COMMENTS, isPrintLocationCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_ROUTE_COMMENTS, isPrintRouteCommentsEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_LOADS_EMPTIES, isPrintLoadsAndEmptiesEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_TIMETABLE, isPrintTimetableNameEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.USE12HR_FORMAT, is12hrFormatEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_VALID, isPrintValidEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.SORT_BY_TRACK, isSortByTrackNameEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_HEADERS, isPrintHeadersEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.TRUNCATE, isTruncateManifestEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.USE_DEPARTURE_TIME, isUseDepartureTimeEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.USE_EDITOR, isManifestEditorEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_CABOOSE_LOAD, isPrintCabooseLoadEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PRINT_PASSENGER_LOAD, isPrintPassengerLoadEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.HAZARDOUS_MSG, getHazardousMsg());
// backward compatible, remove in 2015
// e.addContent(values = new Element(Xml.COLUMN_FORMAT));
// values.setAttribute(Xml.TWO_COLUMNS, getManifestFormat() == TWO_COLUMN_FORMAT ? Xml.TRUE : Xml.FALSE);
// new format June 2014
e.addContent(values = new Element(Xml.MANIFEST_FORMAT));
// save manifest format
String value = Xml.STANDARD;
if (getManifestFormat().equals(TWO_COLUMN_FORMAT)) {
value = Xml.TWO_COLUMN;
} else if (getManifestFormat().equals(TWO_COLUMN_TRACK_FORMAT)) {
value = Xml.TWO_COLUMN_TRACK;
}
values.setAttribute(Xml.VALUE, value);
if (!getManifestLogoURL().equals(NONE)) {
values = new Element(Xml.MANIFEST_LOGO);
values.setAttribute(Xml.NAME, getManifestLogoURL());
e.addContent(values);
}
// manifest save file options
e.addContent(values = new Element(Xml.MANIFEST_FILE_OPTIONS));
values.setAttribute(Xml.MANIFEST_SAVE, isSaveTrainManifestsEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.BUILD_OPTIONS));
values.setAttribute(Xml.AGGRESSIVE, isBuildAggressive() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.NUMBER_PASSES, Integer.toString(getNumberPasses()));
values.setAttribute(Xml.ALLOW_LOCAL_INTERCHANGE, isLocalInterchangeMovesEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ALLOW_LOCAL_SPUR, isLocalSpurMovesEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ALLOW_LOCAL_YARD, isLocalYardMovesEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.STAGING_RESTRICTION_ENABLED, isTrainIntoStagingCheckEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.STAGING_TRACK_AVAIL, isStagingTrackImmediatelyAvail() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ALLOW_RETURN_STAGING, isAllowReturnToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PROMPT_STAGING_ENABLED, isPromptFromStagingEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.PROMPT_TO_STAGING_ENABLED, isPromptToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.GENERATE_CSV_MANIFEST, isGenerateCsvManifestEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.GENERATE_CSV_SWITCH_LIST, isGenerateCsvSwitchListEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.BUILD_REPORT));
values.setAttribute(Xml.LEVEL, getBuildReportLevel());
values.setAttribute(Xml.ROUTER_LEVEL, getRouterBuildReportLevel());
values.setAttribute(Xml.USE_EDITOR, isBuildReportEditorEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.INDENT, isBuildReportIndentEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ALWAYS_PREVIEW, isBuildReportAlwaysPreviewEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.FONT_SIZE, Integer.toString(getBuildReportFontSize()));
// new format for router options
e.addContent(values = new Element(Xml.ROUTER));
values.setAttribute(Xml.CAR_ROUTING_ENABLED, isCarRoutingEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.CAR_ROUTING_VIA_YARDS, isCarRoutingViaYardsEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.CAR_ROUTING_VIA_STAGING, isCarRoutingViaStagingEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.FORWARD_TO_YARD, isForwardToYardEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ONLY_ACTIVE_TRAINS, isOnlyActiveTrainsEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.CHECK_CAR_DESTINATION, isCheckCarDestinationEnabled() ? Xml.TRUE : Xml.FALSE);
// new format for logger options
e.addContent(values = new Element(Xml.LOGGER));
values.setAttribute(Xml.CAR_LOGGER, isCarLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.ENGINE_LOGGER, isEngineLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
values.setAttribute(Xml.TRAIN_LOGGER, isTrainLoggerEnabled() ? Xml.TRUE : Xml.FALSE);
e.addContent(values = new Element(Xml.OWNER));
values.setAttribute(Xml.NAME, getOwnerName());
e.addContent(values = new Element(Xml.ICON_COLOR));
values.setAttribute(Xml.NORTH, getTrainIconColorNorth());
values.setAttribute(Xml.SOUTH, getTrainIconColorSouth());
values.setAttribute(Xml.EAST, getTrainIconColorEast());
values.setAttribute(Xml.WEST, getTrainIconColorWest());
values.setAttribute(Xml.LOCAL, getTrainIconColorLocal());
values.setAttribute(Xml.TERMINATE, getTrainIconColorTerminate());
e.addContent(values = new Element(Xml.COMMENTS));
values.setAttribute(Xml.MISPLACED_CARS, getMiaComment());
e.addContent(values = new Element(Xml.DISPLAY));
values.setAttribute(Xml.SHOW_TRACK_MOVES, isShowTrackMovesEnabled() ? Xml.TRUE : Xml.FALSE);
if (isVsdPhysicalLocationEnabled()) {
e.addContent(values = new Element(Xml.VSD));
values.setAttribute(Xml.ENABLE_PHYSICAL_LOCATIONS, isVsdPhysicalLocationEnabled() ? Xml.TRUE : Xml.FALSE);
}
// Save CATS setting
e.addContent(values = new Element(Xml.CATS));
values.setAttribute(Xml.EXACT_LOCATION_NAME, AbstractOperationsServer.isExactLoationNameEnabled() ? Xml.TRUE : Xml.FALSE);
return e;
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class Train method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-trains.dtd.
*
* @return Contents in a JDOM Element
*/
public Element store() {
Element e = new Element(Xml.TRAIN);
e.setAttribute(Xml.ID, getId());
e.setAttribute(Xml.NAME, getName());
e.setAttribute(Xml.DESCRIPTION, getRawDescription());
e.setAttribute(Xml.DEPART_HOUR, getDepartureTimeHour());
e.setAttribute(Xml.DEPART_MINUTE, getDepartureTimeMinute());
Element eRowColor = new Element(Xml.ROW_COLOR);
eRowColor.setAttribute(Xml.NAME, getTableRowColorName());
eRowColor.setAttribute(Xml.RESET_ROW_COLOR, getRowColorNameReset());
e.addContent(eRowColor);
Element eRoute = new Element(Xml.ROUTE);
if (getRoute() != null) {
// old format
if (Control.backwardCompatible) {
e.setAttribute(Xml.ROUTE, getRoute().getName());
e.setAttribute(Xml.ROUTE_ID, getRoute().getId());
}
// new format
eRoute.setAttribute(Xml.NAME, getRoute().getName());
eRoute.setAttribute(Xml.ID, getRoute().getId());
e.addContent(eRoute);
// build list of locations that this train skips
// new format
String[] locationIds = getTrainSkipsLocations();
if (locationIds.length > 0) {
Element eSkips = new Element(Xml.SKIPS);
for (String id : locationIds) {
Element eLoc = new Element(Xml.LOCATION);
RouteLocation rl = getRoute().getLocationById(id);
if (rl != null) {
eLoc.setAttribute(Xml.NAME, rl.getName());
eLoc.setAttribute(Xml.ID, id);
eSkips.addContent(eLoc);
}
}
eRoute.addContent(eSkips);
}
}
// old format
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String id : getTrainSkipsLocations()) {
// NOI18N
buf.append(id + "%%");
}
e.setAttribute(Xml.SKIP, buf.toString());
}
if (getCurrentLocation() != null) {
e.setAttribute(Xml.CURRENT, getCurrentLocation().getId());
}
if (getDepartureTrack() != null) {
e.setAttribute(Xml.DEPARTURE_TRACK, getDepartureTrack().getId());
}
if (getTerminationTrack() != null) {
e.setAttribute(Xml.TERMINATION_TRACK, getTerminationTrack().getId());
}
if (Control.backwardCompatible) {
// misspelled should have been option not operation
e.setAttribute(Xml.CAR_ROAD_OPERATION, getRoadOption());
}
e.setAttribute(Xml.BUILT_START_YEAR, getBuiltStartYear());
e.setAttribute(Xml.BUILT_END_YEAR, getBuiltEndYear());
e.setAttribute(Xml.NUMBER_ENGINES, getNumberEngines());
e.setAttribute(Xml.ENGINE_ROAD, getEngineRoad());
e.setAttribute(Xml.ENGINE_MODEL, getEngineModel());
e.setAttribute(Xml.REQUIRES, Integer.toString(getRequirements()));
e.setAttribute(Xml.CABOOSE_ROAD, getCabooseRoad());
e.setAttribute(Xml.BUILD_NORMAL, isBuildTrainNormalEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.TO_TERMINAL, isSendCarsToTerminalEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_LOCAL_MOVES, isAllowLocalMovesEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_RETURN, isAllowReturnToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_THROUGH_CARS, isAllowThroughCarsEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SERVICE_ALL, isServiceAllCarsWithFinalDestinationsEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SEND_CUSTOM_STAGING, isSendCarsWithCustomLoadsToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_CONSIST, isBuildConsistEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILT, isBuilt() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD, isBuildEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_FAILED, getBuildFailed() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_FAILED_MESSAGE, getBuildFailedMessage());
e.setAttribute(Xml.PRINTED, isPrinted() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.MODIFIED, isModified() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SWITCH_LIST_STATUS, getSwitchListStatus());
if (getLeadEngine() != null) {
e.setAttribute(Xml.LEAD_ENGINE, getLeadEngine().getId());
}
e.setAttribute(Xml.STATUS, getStatus());
e.setAttribute(Xml.TERMINATION_DATE, getTerminationDate());
e.setAttribute(Xml.REQUESTED_CARS, Integer.toString(getNumberCarsRequested()));
e.setAttribute(Xml.STATUS_CODE, Integer.toString(getStatusCode()));
e.setAttribute(Xml.OLD_STATUS_CODE, Integer.toString(getOldStatusCode()));
e.setAttribute(Xml.COMMENT, getComment());
e.setAttribute(Xml.SHOW_TIMES, isShowArrivalAndDepartureTimesEnabled() ? Xml.TRUE : Xml.FALSE);
// build list of car types for this train
String[] types = getTypeNames();
// Old way of saving car types
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String type : types) {
// remove types that have been deleted by user
if (CarTypes.instance().containsName(type) || EngineTypes.instance().containsName(type)) {
// NOI18N
buf.append(type + "%%");
}
}
e.setAttribute(Xml.CAR_TYPES, buf.toString());
}
// new way of saving car types
Element eTypes = new Element(Xml.TYPES);
for (String type : types) {
// don't save types that have been deleted by user
if (EngineTypes.instance().containsName(type)) {
Element eType = new Element(Xml.LOCO_TYPE);
eType.setAttribute(Xml.NAME, type);
eTypes.addContent(eType);
} else if (CarTypes.instance().containsName(type)) {
Element eType = new Element(Xml.CAR_TYPE);
eType.setAttribute(Xml.NAME, type);
eTypes.addContent(eType);
}
}
e.addContent(eTypes);
// save list of car roads for this train
if (!getRoadOption().equals(ALL_ROADS)) {
e.setAttribute(Xml.CAR_ROAD_OPTION, getRoadOption());
String[] roads = getRoadNames();
// old way of saving road names
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String road : roads) {
// NOI18N
buf.append(road + "%%");
}
e.setAttribute(Xml.CAR_ROADS, buf.toString());
}
// new way of saving road names
Element eRoads = new Element(Xml.CAR_ROADS);
for (String road : roads) {
Element eRoad = new Element(Xml.CAR_ROAD);
eRoad.setAttribute(Xml.NAME, road);
eRoads.addContent(eRoad);
}
e.addContent(eRoads);
}
// save list of car loads for this train
if (!getLoadOption().equals(ALL_LOADS)) {
e.setAttribute(Xml.CAR_LOAD_OPTION, getLoadOption());
String[] loads = getLoadNames();
// old way of saving car loads
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String load : loads) {
// NOI18N
buf.append(load + "%%");
}
e.setAttribute(Xml.CAR_LOADS, buf.toString());
}
// new way of saving car loads
Element eLoads = new Element(Xml.CAR_LOADS);
for (String load : loads) {
Element eLoad = new Element(Xml.CAR_LOAD);
eLoad.setAttribute(Xml.NAME, load);
eLoads.addContent(eLoad);
}
e.addContent(eLoads);
}
// save list of car owners for this train
if (!getOwnerOption().equals(ALL_OWNERS)) {
e.setAttribute(Xml.CAR_OWNER_OPTION, getOwnerOption());
String[] owners = getOwnerNames();
// old way of saving car owners
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String owner : owners) {
// NOI18N
buf.append(owner + "%%");
}
e.setAttribute(Xml.CAR_OWNERS, buf.toString());
}
// new way of saving car owners
Element eOwners = new Element(Xml.CAR_OWNERS);
for (String owner : owners) {
Element eOwner = new Element(Xml.CAR_OWNER);
eOwner.setAttribute(Xml.NAME, owner);
eOwners.addContent(eOwner);
}
e.addContent(eOwners);
}
// save list of scripts for this train
if (getBuildScripts().size() > 0 || getAfterBuildScripts().size() > 0 || getMoveScripts().size() > 0 || getTerminationScripts().size() > 0) {
Element es = new Element(Xml.SCRIPTS);
if (getBuildScripts().size() > 0) {
for (String scriptPathname : getBuildScripts()) {
Element em = new Element(Xml.BUILD);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
if (getAfterBuildScripts().size() > 0) {
for (String scriptPathname : getAfterBuildScripts()) {
Element em = new Element(Xml.AFTER_BUILD);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
if (getMoveScripts().size() > 0) {
for (String scriptPathname : getMoveScripts()) {
Element em = new Element(Xml.MOVE);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
// save list of termination scripts for this train
if (getTerminationScripts().size() > 0) {
for (String scriptPathname : getTerminationScripts()) {
Element et = new Element(Xml.TERMINATE);
et.setAttribute(Xml.NAME, scriptPathname);
es.addContent(et);
}
}
e.addContent(es);
}
if (!getRailroadName().equals(NONE)) {
Element r = new Element(Xml.RAIL_ROAD);
r.setAttribute(Xml.NAME, getRailroadName());
e.addContent(r);
}
if (!getManifestLogoURL().equals(NONE)) {
Element l = new Element(Xml.MANIFEST_LOGO);
l.setAttribute(Xml.NAME, getManifestLogoURL());
e.addContent(l);
}
if (getSecondLegOptions() != NO_CABOOSE_OR_FRED) {
e.setAttribute(Xml.LEG2_OPTIONS, Integer.toString(getSecondLegOptions()));
e.setAttribute(Xml.LEG2_ENGINES, getSecondLegNumberEngines());
e.setAttribute(Xml.LEG2_ROAD, getSecondLegEngineRoad());
e.setAttribute(Xml.LEG2_MODEL, getSecondLegEngineModel());
e.setAttribute(Xml.LEG2_CABOOSE_ROAD, getSecondLegCabooseRoad());
if (getSecondLegStartLocation() != null) {
e.setAttribute(Xml.LEG2_START, getSecondLegStartLocation().getId());
}
if (getSecondLegEndLocation() != null) {
e.setAttribute(Xml.LEG2_END, getSecondLegEndLocation().getId());
}
}
if (getThirdLegOptions() != NO_CABOOSE_OR_FRED) {
e.setAttribute(Xml.LEG3_OPTIONS, Integer.toString(getThirdLegOptions()));
e.setAttribute(Xml.LEG3_ENGINES, getThirdLegNumberEngines());
e.setAttribute(Xml.LEG3_ROAD, getThirdLegEngineRoad());
e.setAttribute(Xml.LEG3_MODEL, getThirdLegEngineModel());
e.setAttribute(Xml.LEG3_CABOOSE_ROAD, getThirdLegCabooseRoad());
if (getThirdLegStartLocation() != null) {
e.setAttribute(Xml.LEG3_START, getThirdLegStartLocation().getId());
}
if (getThirdLegEndLocation() != null) {
e.setAttribute(Xml.LEG3_END, getThirdLegEndLocation().getId());
}
}
return e;
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class Control method load.
public static void load(Element e) {
Element eControl = e.getChild(Xml.CONTROL);
if (eControl == null) {
return;
}
Element backwardCompatibility = eControl.getChild(Xml.BACKWARD_COMPATIBILITY);
if (backwardCompatibility != null) {
Attribute format;
if ((format = backwardCompatibility.getAttribute(Xml.SAVE_USING_PRE_2013_FORMAT)) != null) {
backwardCompatible = format.getValue().equals(Xml.TRUE);
}
}
Element maximumStringLengths = eControl.getChild(Xml.MAXIMUM_STRING_LENGTHS);
if (maximumStringLengths != null) {
Attribute length;
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ATTRIBUTE) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ATTRIBUTE).getAttribute(Xml.LENGTH)) != null) {
max_len_string_attibute = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROAD_NUMBER) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROAD_NUMBER).getAttribute(Xml.LENGTH)) != null) {
max_len_string_road_number = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_PRINT_ROAD_NUMBER) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_PRINT_ROAD_NUMBER).getAttribute(Xml.LENGTH)) != null) {
max_len_string_print_road_number = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LOCATION_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LOCATION_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_location_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_track_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_LENGTH_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_LENGTH_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_track_length_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LENGTH_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LENGTH_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_length_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_WEIGHT_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_WEIGHT_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_weight_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_BUILT_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_BUILT_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_built_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRAIN_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRAIN_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_train_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROUTE_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROUTE_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_route_name = Integer.parseInt(length.getValue());
}
if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_AUTOMATION_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_AUTOMATION_NAME).getAttribute(Xml.LENGTH)) != null) {
max_len_string_automation_name = Integer.parseInt(length.getValue());
}
}
Element eReports = eControl.getChild(Xml.REPORTS);
if (eReports != null) {
Attribute a;
if ((a = eReports.getAttribute(Xml.FONT_SIZE)) != null) {
try {
reportFontSize = a.getIntValue();
} catch (DataConversionException e1) {
log.error("Report font size ({}) isn't a number", a.getValue());
}
}
if ((a = eReports.getAttribute(Xml.FONT_NAME)) != null) {
reportFontName = a.getValue();
}
}
Element eActions = eControl.getChild(Xml.ACTIONS);
if (eActions != null) {
Attribute a;
if ((a = eActions.getAttribute(Xml.EXCEL_WAIT_TIME)) != null) {
try {
excelWaitTime = a.getIntValue();
} catch (DataConversionException e1) {
log.error("Excel wait time ({}) isn't a number", a.getValue());
}
}
}
}
Aggregations