diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java @ 2683:f5af3adb3b95

Improved datacage configuration for floodmaps and maps and modified the WMS layer artifacts to support names for layers. flys-artifacts/trunk@4383 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 May 2012 11:14:17 +0000
parents 5afccab9aac1
children 64dc2997b2dd
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Thu May 10 10:04:12 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Thu May 10 11:14:17 2012 +0000
@@ -27,6 +27,7 @@
 
 import de.intevation.flys.backend.SessionFactoryProvider;
 
+import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.artifacts.states.DefaultState;
 import de.intevation.flys.artifacts.model.WMSDBLayerFacet;
 import de.intevation.flys.utils.FLYSUtils;
@@ -106,6 +107,7 @@
         protected FLYSArtifact artifact;
 
         protected String name;
+        protected int    riverId;
 
 
         public WMSDBState() {}
@@ -113,6 +115,7 @@
         public WMSDBState(FLYSArtifact artifact) {
             this.artifact = artifact;
             this.name     = null;
+            this.riverId  = 0;
         }
 
         @Override
@@ -227,6 +230,22 @@
             return null;
         }
 
+        public int getRiverId() {
+            if (riverId == 0) {
+                String   ids   = artifact.getDataAsString("ids");
+                String[] parts = ids.split(";");
+
+                try {
+                    riverId = Integer.valueOf(parts[0]);
+                }
+                catch (NumberFormatException nfe) {
+                    logger.error("Cannot parse river id from '" + parts[0] + "'");
+                }
+            }
+
+            return riverId;
+        }
+
         /**
          * Returns the name of the WMS layer. This method extracts the name
          * from 'ids' data string. It is expected, that the 'ids' string is
@@ -238,17 +257,40 @@
             if (name == null) {
                 String ids = artifact.getDataAsString("ids");
 
-                String parts[] = ids.split(";");
-                name = parts[1];
+                String parts[] = ids != null ? ids.split(";") : null;
+
+                if (parts != null && parts.length >= 2) {
+                    name = parts[1];
+                }
             }
 
             return name;
         }
 
+
+        /**
+         * Returns the name of the layer (returned by getName()) or the layer
+         * type if the name is empty. The layer type is created by an i18n
+         * string of getFacetType().
+         *
+         * @param meta A CallMeta used for i18n.
+         *
+         * @return the name of the layer or its type if name is empty.
+         */
+        protected String getTitle(CallMeta meta) {
+            String name = getName();
+
+            return name != null && name.length() > 0
+                ? name
+                : Resources.getMsg(
+                    meta,
+                    getFacetType(),
+                    getFacetType());
+        }
+
+
         protected abstract String getFacetType();
 
-        protected abstract String getTitle(CallMeta meta);
-
         protected abstract String getUrl();
 
         protected abstract String getSrid();

http://dive4elements.wald.intevation.org