001package jmri.jmrit.operations.trains;
002
003import org.jdom2.Attribute;
004import org.jdom2.Element;
005
006/**
007 * Loads and stores the manifest text strings.
008 *
009 * @author Daniel Boudreau Copyright (C) 2013
010 *
011 */
012public class TrainManifestText {
013
014    private static String manifestForTrain = Bundle.getMessage("ManifestForTrain");
015    private static String valid = Bundle.getMessage("Valid");
016    private static String scheduledWorkAt = Bundle.getMessage("ScheduledWorkAt");
017    private static String departureTime = Bundle.getMessage("WorkDepartureTime");
018    private static String arrivalTime = Bundle.getMessage("WorkArrivalTime");
019    private static String noScheduledWorkAt = Bundle.getMessage("NoScheduledWorkAt");
020    private static String noScheduledWorkAtRouteComment = Bundle.getMessage("NoScheduledWorkAtWithRouteComment");
021    private static String departTime = Bundle.getMessage("departureTime"); // this get's appended to "no scheduled work at"
022    private static String trainDepartsCars = Bundle.getMessage("TrainDepartsCars");
023    private static String trainDepartsLoads = Bundle.getMessage("TrainDepartsLoads");
024    private static String trainTerminatesIn = Bundle.getMessage("TrainTerminatesIn");
025
026    private static String destination = Bundle.getMessage("destination");
027    private static String from = Bundle.getMessage("from");
028    private static String to = Bundle.getMessage("to");
029
030    private static String fd = Bundle.getMessage("FD");
031    private static String dest = Bundle.getMessage("dest");
032
033    private static String addHelpersAt = Bundle.getMessage("AddHelpersAt");
034    private static String removeHelpersAt = Bundle.getMessage("RemoveHelpersAt");
035    private static String locoChangeAt = Bundle.getMessage("LocoChangeAt");
036    private static String cabooseChangeAt = Bundle.getMessage("CabooseChangeAt");
037    private static String locoAndCabooseChangeAt = Bundle.getMessage("LocoAndCabooseChangeAt");
038
039    public static String getStringManifestForTrain() {
040        return manifestForTrain;
041    }
042
043    public static void setStringManifestForTrain(String s) {
044        manifestForTrain = s;
045    }
046
047    public static String getStringValid() {
048        return valid;
049    }
050
051    public static void setStringValid(String s) {
052        valid = s;
053    }
054
055    public static String getStringScheduledWork() {
056        return scheduledWorkAt;
057    }
058
059    public static void setStringScheduledWork(String s) {
060        scheduledWorkAt = s;
061    }
062
063    public static String getStringWorkDepartureTime() {
064        return departureTime;
065    }
066
067    public static void setStringWorkDepartureTime(String s) {
068        departureTime = s;
069    }
070
071    public static String getStringWorkArrivalTime() {
072        return arrivalTime;
073    }
074
075    public static void setStringWorkArrivalTime(String s) {
076        arrivalTime = s;
077    }
078
079    public static String getStringNoScheduledWork() {
080        return noScheduledWorkAt;
081    }
082
083    public static void setStringNoScheduledWork(String s) {
084        noScheduledWorkAt = s;
085    }
086
087    public static String getStringNoScheduledWorkWithRouteComment() {
088        return noScheduledWorkAtRouteComment;
089    }
090
091    public static void setStringNoScheduledWorkWithRouteComment(String s) {
092        noScheduledWorkAtRouteComment = s;
093    }
094
095    public static String getStringDepartTime() {
096        return departTime;
097    }
098
099    public static void setStringDepartTime(String s) {
100        departTime = s;
101    }
102
103    public static String getStringTrainDepartsCars() {
104        return trainDepartsCars;
105    }
106
107    public static void setStringTrainDepartsCars(String s) {
108        trainDepartsCars = s;
109    }
110
111    public static String getStringTrainDepartsLoads() {
112        return trainDepartsLoads;
113    }
114
115    public static void setStringTrainDepartsLoads(String s) {
116        trainDepartsLoads = s;
117    }
118
119    public static String getStringTrainTerminates() {
120        return trainTerminatesIn;
121    }
122
123    public static void setStringTrainTerminates(String s) {
124        trainTerminatesIn = s;
125    }
126
127    public static String getStringDestination() {
128        return destination;
129    }
130
131    public static void setStringDestination(String s) {
132        destination = s;
133    }
134
135    public static String getStringFrom() {
136        return from;
137    }
138
139    public static void setStringFrom(String s) {
140        from = s;
141    }
142
143    public static String getStringTo() {
144        return to;
145    }
146
147    public static void setStringTo(String s) {
148        to = s;
149    }
150
151    public static String getStringDest() {
152        return dest;
153    }
154
155    public static void setStringDest(String s) {
156        dest = s;
157    }
158
159    public static String getStringFinalDestination() {
160        return fd;
161    }
162
163    public static void setStringFinalDestination(String s) {
164        fd = s;
165    }
166
167    public static String getStringAddHelpers() {
168        return addHelpersAt;
169    }
170
171    public static void setStringAddHelpers(String s) {
172        addHelpersAt = s;
173    }
174
175    public static String getStringRemoveHelpers() {
176        return removeHelpersAt;
177    }
178
179    public static void setStringRemoveHelpers(String s) {
180        removeHelpersAt = s;
181    }
182
183    public static String getStringLocoChange() {
184        return locoChangeAt;
185    }
186
187    public static void setStringLocoChange(String s) {
188        locoChangeAt = s;
189    }
190
191    public static String getStringCabooseChange() {
192        return cabooseChangeAt;
193    }
194
195    public static void setStringCabooseChange(String s) {
196        cabooseChangeAt = s;
197    }
198
199    public static String getStringLocoAndCabooseChange() {
200        return locoAndCabooseChangeAt;
201    }
202
203    public static void setStringLocoAndCabooseChange(String s) {
204        locoAndCabooseChangeAt = s;
205    }
206
207    // must synchronize changes with operation-config.dtd
208    public static Element store() {
209        Element values;
210        Element e = new Element(Xml.MANIFEST_TEXT_STRINGS);
211        // only save strings that have been modified
212        if (!getStringManifestForTrain().equals(Bundle.getMessage("ManifestForTrain"))) {
213            e.addContent(values = new Element(Xml.MANIFEST_FOR_TRAIN));
214            values.setAttribute(Xml.TEXT, getStringManifestForTrain());
215        }
216        if (!getStringValid().equals(Bundle.getMessage("Valid"))) {
217            e.addContent(values = new Element(Xml.VALID));
218            values.setAttribute(Xml.TEXT, getStringValid());
219        }
220        if (!getStringScheduledWork().equals(Bundle.getMessage("ScheduledWorkAt"))) {
221            e.addContent(values = new Element(Xml.SCHEDULED_WORK));
222            values.setAttribute(Xml.TEXT, getStringScheduledWork());
223        }
224        if (!getStringWorkDepartureTime().equals(Bundle.getMessage("WorkDepartureTime"))) {
225            e.addContent(values = new Element(Xml.WORK_DEPARTURE_TIME));
226            values.setAttribute(Xml.TEXT, getStringWorkDepartureTime());
227        }
228        if (!getStringWorkArrivalTime().equals(Bundle.getMessage("WorkArrivalTime"))) {
229            e.addContent(values = new Element(Xml.WORK_ARRIVAL_TIME));
230            values.setAttribute(Xml.TEXT, getStringWorkArrivalTime());
231        }
232        if (!getStringNoScheduledWork().equals(Bundle.getMessage("NoScheduledWorkAt"))) {
233            e.addContent(values = new Element(Xml.NO_SCHEDULED_WORK));
234            values.setAttribute(Xml.TEXT, getStringNoScheduledWork());
235        }
236        if (!getStringNoScheduledWorkWithRouteComment().equals(Bundle.getMessage("NoScheduledWorkAtWithRouteComment"))) {
237            e.addContent(values = new Element(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT));
238            values.setAttribute(Xml.TEXT, getStringNoScheduledWorkWithRouteComment());
239        }
240        if (!getStringDepartTime().equals(Bundle.getMessage("departureTime"))) {
241            e.addContent(values = new Element(Xml.DEPART_TIME));
242            values.setAttribute(Xml.TEXT, getStringDepartTime());
243        }
244        if (!getStringTrainDepartsCars().equals(Bundle.getMessage("TrainDepartsCars"))) {
245            e.addContent(values = new Element(Xml.TRAIN_DEPARTS_CARS));
246            values.setAttribute(Xml.TEXT, getStringTrainDepartsCars());
247        }
248        if (!getStringTrainDepartsLoads().equals(Bundle.getMessage("TrainDepartsLoads"))) {
249            e.addContent(values = new Element(Xml.TRAIN_DEPARTS_LOADS));
250            values.setAttribute(Xml.TEXT, getStringTrainDepartsLoads());
251        }
252        if (!getStringTrainTerminates().equals(Bundle.getMessage("TrainTerminatesIn"))) {
253            e.addContent(values = new Element(Xml.TRAIN_TERMINATES));
254            values.setAttribute(Xml.TEXT, getStringTrainTerminates());
255        }
256        if (!getStringDestination().equals(Bundle.getMessage("destination"))) {
257            e.addContent(values = new Element(Xml.DESTINATION));
258            values.setAttribute(Xml.TEXT, getStringDestination());
259        }
260        if (!getStringFrom().equals(Bundle.getMessage("from"))) {
261            e.addContent(values = new Element(Xml.FROM));
262            values.setAttribute(Xml.TEXT, getStringFrom());
263        }
264        if (!getStringTo().equals(Bundle.getMessage("to"))) {
265            e.addContent(values = new Element(Xml.TO));
266            values.setAttribute(Xml.TEXT, getStringTo());
267        }
268        if (!getStringDest().equals(Bundle.getMessage("dest"))) {
269            e.addContent(values = new Element(Xml.DEST));
270            values.setAttribute(Xml.TEXT, getStringDest());
271        }
272        if (!getStringFinalDestination().equals(Bundle.getMessage("FD"))) {
273            e.addContent(values = new Element(Xml.FINAL_DEST));
274            values.setAttribute(Xml.TEXT, getStringFinalDestination());
275        }
276        if (!getStringAddHelpers().equals(Bundle.getMessage("AddHelpersAt"))) {
277            e.addContent(values = new Element(Xml.ADD_HELPERS));
278            values.setAttribute(Xml.TEXT, getStringAddHelpers());
279        }
280        if (!getStringRemoveHelpers().equals(Bundle.getMessage("RemoveHelpersAt"))) {
281            e.addContent(values = new Element(Xml.REMOVE_HELPERS));
282            values.setAttribute(Xml.TEXT, getStringRemoveHelpers());
283        }
284        if (!getStringLocoChange().equals(Bundle.getMessage("LocoChangeAt"))) {
285            e.addContent(values = new Element(Xml.LOCO_CHANGE));
286            values.setAttribute(Xml.TEXT, getStringLocoChange());
287        }
288        if (!getStringCabooseChange().equals(Bundle.getMessage("CabooseChangeAt"))) {
289            e.addContent(values = new Element(Xml.CABOOSE_CHANGE));
290            values.setAttribute(Xml.TEXT, getStringCabooseChange());
291        }
292        if (!getStringLocoAndCabooseChange().equals(Bundle.getMessage("LocoAndCabooseChangeAt"))) {
293            e.addContent(values = new Element(Xml.LOCO_CABOOSE_CHANGE));
294            values.setAttribute(Xml.TEXT, getStringLocoAndCabooseChange());
295        }
296
297        return e;
298    }
299
300    public static void load(Element e) {
301        Element emts = e.getChild(Xml.MANIFEST_TEXT_STRINGS);
302        if (emts == null) {
303            return;
304        }
305        Attribute a;
306        if (emts.getChild(Xml.MANIFEST_FOR_TRAIN) != null) {
307            if ((a = emts.getChild(Xml.MANIFEST_FOR_TRAIN).getAttribute(Xml.TEXT)) != null) {
308                setStringManifestForTrain(a.getValue());
309            }
310        }
311        if (emts.getChild(Xml.VALID) != null) {
312            if ((a = emts.getChild(Xml.VALID).getAttribute(Xml.TEXT)) != null) {
313                setStringValid(a.getValue());
314            }
315        }
316        if (emts.getChild(Xml.SCHEDULED_WORK) != null) {
317            if ((a = emts.getChild(Xml.SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
318                setStringScheduledWork(a.getValue());
319            }
320        }
321        if (emts.getChild(Xml.WORK_DEPARTURE_TIME) != null) {
322            if ((a = emts.getChild(Xml.WORK_DEPARTURE_TIME).getAttribute(Xml.TEXT)) != null) {
323                setStringWorkDepartureTime(a.getValue());
324            }
325        }
326        if (emts.getChild(Xml.WORK_ARRIVAL_TIME) != null) {
327            if ((a = emts.getChild(Xml.WORK_ARRIVAL_TIME).getAttribute(Xml.TEXT)) != null) {
328                setStringWorkArrivalTime(a.getValue());
329            }
330        }
331        if (emts.getChild(Xml.NO_SCHEDULED_WORK) != null) {
332            if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
333                setStringNoScheduledWork(a.getValue());
334            }
335        }
336        if (emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT) != null) {
337            if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT).getAttribute(Xml.TEXT)) != null) {
338                setStringNoScheduledWorkWithRouteComment(a.getValue());
339            }
340        }
341        if (emts.getChild(Xml.DEPART_TIME) != null) {
342            if ((a = emts.getChild(Xml.DEPART_TIME).getAttribute(Xml.TEXT)) != null) {
343                setStringDepartTime(a.getValue());
344            }
345        }
346        if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
347            if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
348                setStringTrainDepartsCars(a.getValue());
349            }
350        }
351        if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
352            if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
353                setStringTrainDepartsLoads(a.getValue());
354            }
355        }
356        if (emts.getChild(Xml.TRAIN_TERMINATES) != null) {
357            if ((a = emts.getChild(Xml.TRAIN_TERMINATES).getAttribute(Xml.TEXT)) != null) {
358                setStringTrainTerminates(a.getValue());
359            }
360        }
361
362        if (emts.getChild(Xml.DESTINATION) != null) {
363            if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
364                setStringDestination(a.getValue());
365            }
366        }
367        if (emts.getChild(Xml.TO) != null) {
368            if ((a = emts.getChild(Xml.TO).getAttribute(Xml.TEXT)) != null) {
369                setStringTo(a.getValue());
370            }
371        }
372        if (emts.getChild(Xml.FROM) != null) {
373            if ((a = emts.getChild(Xml.FROM).getAttribute(Xml.TEXT)) != null) {
374                setStringFrom(a.getValue());
375            }
376        }
377        if (emts.getChild(Xml.DEST) != null) {
378            if ((a = emts.getChild(Xml.DEST).getAttribute(Xml.TEXT)) != null) {
379                setStringDest(a.getValue());
380            }
381        }
382        if (emts.getChild(Xml.FINAL_DEST) != null) {
383            if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
384                setStringFinalDestination(a.getValue());
385            }
386        }
387        if (emts.getChild(Xml.ADD_HELPERS) != null) {
388            if ((a = emts.getChild(Xml.ADD_HELPERS).getAttribute(Xml.TEXT)) != null) {
389                setStringAddHelpers(a.getValue());
390            }
391        }
392        if (emts.getChild(Xml.REMOVE_HELPERS) != null) {
393            if ((a = emts.getChild(Xml.REMOVE_HELPERS).getAttribute(Xml.TEXT)) != null) {
394                setStringRemoveHelpers(a.getValue());
395            }
396        }
397        if (emts.getChild(Xml.LOCO_CHANGE) != null) {
398            if ((a = emts.getChild(Xml.LOCO_CHANGE).getAttribute(Xml.TEXT)) != null) {
399                setStringLocoChange(a.getValue());
400            }
401        }
402        if (emts.getChild(Xml.CABOOSE_CHANGE) != null) {
403            if ((a = emts.getChild(Xml.CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
404                setStringCabooseChange(a.getValue());
405            }
406        }
407        if (emts.getChild(Xml.LOCO_CABOOSE_CHANGE) != null) {
408            if ((a = emts.getChild(Xml.LOCO_CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
409                setStringLocoAndCabooseChange(a.getValue());
410            }
411        }
412    }
413}