diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceGaugeState.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents a38f43f626f5
children 8e66293c5369
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceGaugeState.java	Fri Sep 28 12:14:35 2012 +0200
@@ -0,0 +1,88 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.River;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.utils.FLYSUtils;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ReferenceGaugeState extends DefaultState {
+
+    private static final Logger logger =
+        Logger.getLogger(ReferenceGaugeState.class);
+
+
+    public static final String DATA_NAME = "reference_gauge";
+
+
+    @Override
+    protected Element[] createItems(
+        XMLUtils.ElementCreator cr,
+        Artifact    artifact,
+        String      name,
+        CallContext context)
+    {
+        CallMeta  meta = context.getMeta();
+
+        River       river   = FLYSUtils.getRiver((FLYSArtifact) artifact);
+        List<Gauge> gauges  = river.getGauges();
+
+        int num = gauges != null ? gauges.size() : 0;
+
+        Element[] opts = new Element[num];
+
+        for (int i = 0; i < num; i++ ) {
+            Gauge g = gauges.get(i);
+
+            String gaugeName      = g.getName();
+            long   officialNumber = g.getOfficialNumber();
+
+            opts[i] = createItem(
+                cr, new String[] { gaugeName, String.valueOf(officialNumber) });
+        }
+
+        return opts;
+    }
+
+
+    @Override
+    protected String getLabelFor(
+        CallContext cc,
+        String      name,
+        String      value,
+        String      type
+    ) {
+        if (name.equals(DATA_NAME)) {
+            try {
+                long  number = Long.valueOf(value);
+                Gauge gauge  = Gauge.getGaugeByOfficialNumber(number);
+
+                if (gauge != null) {
+                    return gauge.getName();
+                }
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+
+        return super.getLabelFor(cc, name, value, type);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org