Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
1821:e55f1a851923 | 1822:6ed439ff61bf |
---|---|
13 import org.w3c.dom.NodeList; | 13 import org.w3c.dom.NodeList; |
14 | 14 |
15 import de.intevation.artifacts.common.utils.XMLUtils; | 15 import de.intevation.artifacts.common.utils.XMLUtils; |
16 | 16 |
17 import de.intevation.flys.artifacts.context.FLYSContext; | 17 import de.intevation.flys.artifacts.context.FLYSContext; |
18 | 18 import de.intevation.flys.artifacts.FLYSArtifact; |
19 | 19 |
20 /** | 20 /** |
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
22 * | |
23 * Mapping-matching rules: | |
24 * | |
22 */ | 25 */ |
23 public class ThemeFactory { | 26 public class ThemeFactory { |
24 | 27 |
25 private static Logger logger = Logger.getLogger(ThemeFactory.class); | 28 private static Logger logger = Logger.getLogger(ThemeFactory.class); |
26 | 29 |
30 /** Trivial, hidden constructor. */ | |
27 private ThemeFactory() { | 31 private ThemeFactory() { |
32 ; | |
28 } | 33 } |
29 | 34 |
30 | 35 |
31 /** | 36 /** |
32 * Creates a new theme from <i>config</i>. | 37 * Creates a new theme from <i>config</i>. |
64 public static Theme getTheme(FLYSContext c, String name) { | 69 public static Theme getTheme(FLYSContext c, String name) { |
65 return getTheme(c, name, null); | 70 return getTheme(c, name, null); |
66 } | 71 } |
67 | 72 |
68 | 73 |
74 /** | |
75 * Get first matching theme for facet. | |
76 * | |
77 * @param name Name to match "from" of theme mapping. | |
78 * @param pattern String to 'compare' to pattern in mapping. | |
79 * | |
80 * @return First matching theme. | |
81 */ | |
69 public static Theme getTheme(FLYSContext c, String name, String pattern) { | 82 public static Theme getTheme(FLYSContext c, String name, String pattern) { |
83 | |
70 logger.debug("Search theme for: " + name + " - " + pattern); | 84 logger.debug("Search theme for: " + name + " - " + pattern); |
85 | |
71 if (c == null || name == null) { | 86 if (c == null || name == null) { |
72 logger.warn("Cannot search for theme."); | 87 logger.warn("Cannot search for theme."); |
73 return null; | 88 return null; |
74 } | 89 } |
75 | 90 |
91 // Fetch mapping and themes. | |
76 Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>) | 92 Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>) |
77 c.get(FLYSContext.THEME_MAPPING); | 93 c.get(FLYSContext.THEME_MAPPING); |
78 | 94 |
79 Map<String, Theme> t = (Map<String, Theme>) | 95 Map<String, Theme> t = (Map<String, Theme>) |
80 c.get(FLYSContext.THEMES); | 96 c.get(FLYSContext.THEMES); |
81 | 97 |
98 FLYSArtifact artifact = (FLYSArtifact) c.get(FLYSContext.ARTIFACT_KEY); | |
99 | |
82 if (map == null || map.size() == 0 || t == null || t.size() == 0) { | 100 if (map == null || map.size() == 0 || t == null || t.size() == 0) { |
83 logger.warn("No mappings or themes found. Cannot retrieve theme!"); | 101 logger.warn("No mappings or themes found. Cannot retrieve theme!"); |
84 return null; | 102 return null; |
85 } | 103 } |
86 | 104 |
87 List<ThemeMapping> mapping = map.get(name); | 105 List<ThemeMapping> mapping = map.get(name); |
88 | 106 |
89 if (mapping == null) { | 107 if (mapping == null) { |
90 logger.warn("No theme fount for mapping: " + name); | 108 logger.warn("No theme found for mapping: " + name); |
91 return null; | 109 return null; |
92 } | 110 } |
93 | 111 |
94 int patternLen = pattern != null ? pattern.length() : 0; | 112 // Take first mapping of which all conditions are satisfied. |
95 | |
96 Theme defaultTheme = null; | |
97 | |
98 for (ThemeMapping tm: mapping) { | 113 for (ThemeMapping tm: mapping) { |
99 if (name.equals(tm.getFrom())) { | 114 if (name.equals(tm.getFrom()) |
100 String tmPattern = tm.getPatternStr(); | 115 && tm.applyPattern(pattern) |
101 | 116 && tm.masterAttrMatches(artifact)) |
102 int tmLen = tmPattern != null ? tmPattern.length() : 0; | 117 { |
103 | 118 return t.get(tm.getTo()); |
104 if (tmLen == 0 && patternLen == 0) { | |
105 // we want and get the default theme | |
106 return t.get(tm.getTo()); | |
107 } | |
108 else if (tmLen == 0 && patternLen > 0) { | |
109 // found a defaultTheme, lets save it | |
110 defaultTheme = t.get(tm.getTo()); | |
111 } | |
112 else if (tm.applyPattern(pattern)) { | |
113 // found the special theme we have searched for | |
114 return t.get(tm.getTo()); | |
115 } | |
116 } | 119 } |
117 } | 120 } |
118 | 121 |
119 String msg = | 122 String msg = |
120 "No theme found for '" + name + | 123 "No theme found for '" + name + |
121 "' with pattern '" + pattern + "'."; | 124 "' with pattern '" + pattern + "'."; |
122 | 125 |
123 if (defaultTheme != null) { | |
124 logger.info(msg + " Use the default instead."); | |
125 return defaultTheme; | |
126 } | |
127 | |
128 logger.warn(msg); | 126 logger.warn(msg); |
129 | 127 |
130 return null; | 128 return null; |
131 } | 129 } |
132 | 130 |