diff flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java @ 1822:6ed439ff61bf

Changed theme-mapping mechanism to include further condition (on master-artifacts attributes), added point themes for longitudinal.ws for calculations at locations. flys-artifacts/trunk@3151 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 03 Nov 2011 10:25:23 +0000
parents d2a17e990c70
children 9562ca537143
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java	Thu Nov 03 10:19:29 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java	Thu Nov 03 10:25:23 2011 +0000
@@ -15,16 +15,21 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 
 import de.intevation.flys.artifacts.context.FLYSContext;
-
+import de.intevation.flys.artifacts.FLYSArtifact;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ *
+ * Mapping-matching rules:
+ *
  */
 public class ThemeFactory {
 
     private static Logger logger = Logger.getLogger(ThemeFactory.class);
 
+    /** Trivial, hidden constructor. */
     private ThemeFactory() {
+        ;
     }
 
 
@@ -66,19 +71,32 @@
     }
 
 
+    /**
+     * Get first matching theme for facet.
+     *
+     * @param name Name to match "from" of theme mapping.
+     * @param pattern String to 'compare' to pattern in mapping.
+     *
+     * @return First matching theme.
+     */
     public static Theme getTheme(FLYSContext c, String name, String pattern) {
+
         logger.debug("Search theme for: " + name + " - " + pattern);
+
         if (c == null || name == null) {
             logger.warn("Cannot search for theme.");
             return null;
         }
 
+        // Fetch mapping and themes.
         Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>)
             c.get(FLYSContext.THEME_MAPPING);
 
         Map<String, Theme> t = (Map<String, Theme>)
             c.get(FLYSContext.THEMES);
 
+        FLYSArtifact artifact = (FLYSArtifact) c.get(FLYSContext.ARTIFACT_KEY);
+
         if (map == null || map.size() == 0 || t == null || t.size() == 0) {
             logger.warn("No mappings or themes found. Cannot retrieve theme!");
             return null;
@@ -87,32 +105,17 @@
         List<ThemeMapping> mapping = map.get(name);
 
         if (mapping == null) {
-            logger.warn("No theme fount for mapping: " + name);
+            logger.warn("No theme found for mapping: " + name);
             return null;
         }
 
-        int patternLen = pattern != null ? pattern.length() : 0;
-
-        Theme defaultTheme = null;
-
+        // Take first mapping of which all conditions are satisfied.
         for (ThemeMapping tm: mapping) {
-            if (name.equals(tm.getFrom())) {
-                String tmPattern = tm.getPatternStr();
-
-                int tmLen = tmPattern != null ? tmPattern.length() : 0;
-
-                if (tmLen == 0 && patternLen == 0) {
-                    // we want and get the default theme
-                    return t.get(tm.getTo());
-                }
-                else if (tmLen == 0 && patternLen > 0) {
-                    // found a defaultTheme, lets save it
-                    defaultTheme = t.get(tm.getTo());
-                }
-                else if (tm.applyPattern(pattern)) {
-                    // found the special theme we have searched for
-                    return t.get(tm.getTo());
-                }
+            if (name.equals(tm.getFrom())
+                && tm.applyPattern(pattern)
+                && tm.masterAttrMatches(artifact))
+            {
+                return t.get(tm.getTo());
             }
         }
 
@@ -120,11 +123,6 @@
             "No theme found for '" + name +
             "' with pattern '" + pattern + "'.";
 
-        if (defaultTheme != null) {
-            logger.info(msg + " Use the default instead.");
-            return defaultTheme;
-        }
-
         logger.warn(msg);
 
         return null;

http://dive4elements.wald.intevation.org