Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/MainValuesService.java @ 7555:74e9768098a0
issue1542: Let MainValues have localized dates.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 12 Nov 2013 12:11:23 +0100 |
parents | 4e999b1d7acd |
children | 368d419ae4d1 |
comparison
equal
deleted
inserted
replaced
7554:19a133698eaf | 7555:74e9768098a0 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.services; | 9 package org.dive4elements.river.artifacts.services; |
10 | 10 |
11 import java.util.List; | 11 import java.util.List; |
12 import java.text.DateFormat; | |
12 | 13 |
13 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
14 | 15 |
15 import org.w3c.dom.Document; | 16 import org.w3c.dom.Document; |
16 import org.w3c.dom.Element; | 17 import org.w3c.dom.Element; |
30 import org.dive4elements.river.model.Range; | 31 import org.dive4elements.river.model.Range; |
31 import org.dive4elements.river.model.River; | 32 import org.dive4elements.river.model.River; |
32 | 33 |
33 import org.dive4elements.river.artifacts.model.RiverFactory; | 34 import org.dive4elements.river.artifacts.model.RiverFactory; |
34 | 35 |
36 import org.dive4elements.river.artifacts.resources.Resources; | |
37 import org.dive4elements.river.utils.Formatter; | |
38 | |
35 | 39 |
36 /** | 40 /** |
37 * This service returns the main values of a river's gauge based on the start | 41 * This service returns the main values of a river's gauge based on the start |
38 * and end point of the river. | 42 * and end point of the river. |
39 * | 43 * |
42 public class MainValuesService extends D4EService { | 46 public class MainValuesService extends D4EService { |
43 | 47 |
44 /** The logger that is used by this service.*/ | 48 /** The logger that is used by this service.*/ |
45 private static Logger logger = Logger.getLogger(MainValuesService.class); | 49 private static Logger logger = Logger.getLogger(MainValuesService.class); |
46 | 50 |
47 | |
48 /** The XPath that points to the river definition of the incoming request.*/ | 51 /** The XPath that points to the river definition of the incoming request.*/ |
49 public static final String XPATH_RIVER = "/art:mainvalues/art:river/text()"; | 52 public static final String XPATH_RIVER = "/art:mainvalues/art:river/text()"; |
50 | 53 |
51 /** The XPath that points to the start definition of the incoming request.*/ | 54 /** The XPath that points to the start definition of the incoming request.*/ |
52 public static final String XPATH_START = "/art:mainvalues/art:start/text()"; | 55 public static final String XPATH_START = "/art:mainvalues/art:start/text()"; |
53 | 56 |
54 /** The XPath that points to the end definition of the incoming request.*/ | 57 /** The XPath that points to the end definition of the incoming request.*/ |
55 public static final String XPATH_END = "/art:mainvalues/art:end/text()"; | 58 public static final String XPATH_END = "/art:mainvalues/art:end/text()"; |
59 | |
60 protected CallMeta callMeta; | |
61 | |
56 | 62 |
57 /** | 63 /** |
58 * The default constructor. | 64 * The default constructor. |
59 */ | 65 */ |
60 public MainValuesService() { | 66 public MainValuesService() { |
72 GlobalContext context, | 78 GlobalContext context, |
73 CallMeta callMeta | 79 CallMeta callMeta |
74 ) { | 80 ) { |
75 logger.debug("MainValuesService.process"); | 81 logger.debug("MainValuesService.process"); |
76 | 82 |
83 this.callMeta = callMeta; | |
84 | |
77 River river = getRequestedRiver(data); | 85 River river = getRequestedRiver(data); |
78 if (river == null) { | 86 if (river == null) { |
79 return error("no river found."); | 87 return error("no river found."); |
80 } | 88 } |
81 | 89 |
319 | 327 |
320 cr.addAttr(el, "value", mainValue.getValue().toString()); | 328 cr.addAttr(el, "value", mainValue.getValue().toString()); |
321 cr.addAttr(el, "name", namedMainValue.getName()); | 329 cr.addAttr(el, "name", namedMainValue.getName()); |
322 cr.addAttr(el, "type", mainValueType.getName()); | 330 cr.addAttr(el, "type", mainValueType.getName()); |
323 if (mainValue.getTimeInterval() != null) { | 331 if (mainValue.getTimeInterval() != null) { |
324 // TODO instead of bulky toString, use i18n. | 332 DateFormat df = |
333 DateFormat.getDateInstance(DateFormat.SHORT, Resources.getLocale(callMeta)); | |
325 if (mainValue.getTimeInterval().getStartTime() != null) { | 334 if (mainValue.getTimeInterval().getStartTime() != null) { |
326 cr.addAttr(el, "starttime", ""+mainValue.getTimeInterval().getStartTime()); | 335 cr.addAttr(el, "starttime", |
336 df.format(mainValue.getTimeInterval().getStartTime())); | |
327 } | 337 } |
328 if (mainValue.getTimeInterval().getStopTime() != null) { | 338 if (mainValue.getTimeInterval().getStopTime() != null) { |
329 cr.addAttr(el, "stoptime", ""+mainValue.getTimeInterval().getStopTime()); | 339 cr.addAttr(el, "stoptime", |
340 df.format(mainValue.getTimeInterval().getStopTime())); | |
330 } | 341 } |
331 } | 342 } |
332 | 343 |
333 if (hasOfficialLine(namedMainValue, riverId)) { | 344 if (hasOfficialLine(namedMainValue, riverId)) { |
334 cr.addAttr(el, "official", "true"); | 345 cr.addAttr(el, "official", "true"); |