comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceGaugeState.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents a38f43f626f5
children 8e66293c5369
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.artifacts.states;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.w3c.dom.Element;
8
9 import de.intevation.artifacts.Artifact;
10 import de.intevation.artifacts.CallContext;
11 import de.intevation.artifacts.CallMeta;
12
13 import de.intevation.artifacts.common.utils.XMLUtils;
14
15 import de.intevation.flys.model.Gauge;
16 import de.intevation.flys.model.River;
17
18 import de.intevation.flys.artifacts.FLYSArtifact;
19 import de.intevation.flys.utils.FLYSUtils;
20
21
22 /**
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
24 */
25 public class ReferenceGaugeState extends DefaultState {
26
27 private static final Logger logger =
28 Logger.getLogger(ReferenceGaugeState.class);
29
30
31 public static final String DATA_NAME = "reference_gauge";
32
33
34 @Override
35 protected Element[] createItems(
36 XMLUtils.ElementCreator cr,
37 Artifact artifact,
38 String name,
39 CallContext context)
40 {
41 CallMeta meta = context.getMeta();
42
43 River river = FLYSUtils.getRiver((FLYSArtifact) artifact);
44 List<Gauge> gauges = river.getGauges();
45
46 int num = gauges != null ? gauges.size() : 0;
47
48 Element[] opts = new Element[num];
49
50 for (int i = 0; i < num; i++ ) {
51 Gauge g = gauges.get(i);
52
53 String gaugeName = g.getName();
54 long officialNumber = g.getOfficialNumber();
55
56 opts[i] = createItem(
57 cr, new String[] { gaugeName, String.valueOf(officialNumber) });
58 }
59
60 return opts;
61 }
62
63
64 @Override
65 protected String getLabelFor(
66 CallContext cc,
67 String name,
68 String value,
69 String type
70 ) {
71 if (name.equals(DATA_NAME)) {
72 try {
73 long number = Long.valueOf(value);
74 Gauge gauge = Gauge.getGaugeByOfficialNumber(number);
75
76 if (gauge != null) {
77 return gauge.getName();
78 }
79 }
80 catch (NumberFormatException nfe) {
81 // do nothing
82 }
83 }
84
85 return super.getLabelFor(cc, name, value, type);
86 }
87 }
88 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org