Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | af13ceeba52a |
children | f0ea2063b58e |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
32 * Mapping-matching rules: | 32 * Mapping-matching rules: |
33 * | 33 * |
34 */ | 34 */ |
35 public class ThemeFactory { | 35 public class ThemeFactory { |
36 | 36 |
37 private static Logger logger = Logger.getLogger(ThemeFactory.class); | 37 private static Logger log = Logger.getLogger(ThemeFactory.class); |
38 | 38 |
39 /** Trivial, hidden constructor. */ | 39 /** Trivial, hidden constructor. */ |
40 private ThemeFactory() { | 40 private ThemeFactory() { |
41 } | 41 } |
42 | 42 |
52 */ | 52 */ |
53 public static Theme createTheme(Document themeCfg, Node config) { | 53 public static Theme createTheme(Document themeCfg, Node config) { |
54 String name = getName(config); | 54 String name = getName(config); |
55 String desc = getDescription(config); | 55 String desc = getDescription(config); |
56 | 56 |
57 logger.debug("Create new theme: " + name); | 57 log.debug("Create new theme: " + name); |
58 | 58 |
59 Theme theme = new DefaultTheme(name, desc); | 59 Theme theme = new DefaultTheme(name, desc); |
60 | 60 |
61 parseInherits(themeCfg, config, theme); | 61 parseInherits(themeCfg, config, theme); |
62 parseFields(config, theme); | 62 parseFields(config, theme); |
80 String name, | 80 String name, |
81 String pattern, | 81 String pattern, |
82 String output, | 82 String output, |
83 String groupName) | 83 String groupName) |
84 { | 84 { |
85 if (logger.isDebugEnabled()) { | 85 if (log.isDebugEnabled()) { |
86 logger.debug( | 86 log.debug( |
87 "Search theme for: " + name + " - pattern: " + pattern); | 87 "Search theme for: " + name + " - pattern: " + pattern); |
88 } | 88 } |
89 | 89 |
90 if (c == null || name == null) { | 90 if (c == null || name == null) { |
91 logger.warn("Cannot search for theme."); | 91 log.warn("Cannot search for theme."); |
92 return null; | 92 return null; |
93 } | 93 } |
94 | 94 |
95 // Fetch mapping and themes. | 95 // Fetch mapping and themes. |
96 @SuppressWarnings("unchecked") | 96 @SuppressWarnings("unchecked") |
108 break; | 108 break; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 if (group == null) { | 112 if (group == null) { |
113 logger.warn("No theme group found: '" + groupName + "'"); | 113 log.warn("No theme group found: '" + groupName + "'"); |
114 return null; | 114 return null; |
115 } | 115 } |
116 | 116 |
117 Map<String, Theme> t = group.getThemes(); | 117 Map<String, Theme> t = group.getThemes(); |
118 | 118 |
119 D4EArtifact artifact = (D4EArtifact) c.get(RiverContext.ARTIFACT_KEY); | 119 D4EArtifact artifact = (D4EArtifact) c.get(RiverContext.ARTIFACT_KEY); |
120 | 120 |
121 if (map == null || map.isEmpty() || t == null || t.isEmpty()) { | 121 if (map == null || map.isEmpty() || t == null || t.isEmpty()) { |
122 logger.warn("No mappings or themes found. Cannot retrieve theme!"); | 122 log.warn("No mappings or themes found. Cannot retrieve theme!"); |
123 return null; | 123 return null; |
124 } | 124 } |
125 | 125 |
126 List<ThemeMapping> mapping = map.get(name); | 126 List<ThemeMapping> mapping = map.get(name); |
127 | 127 |
128 if (mapping == null) { | 128 if (mapping == null) { |
129 logger.warn("No theme found for mapping: " + name); | 129 log.warn("No theme found for mapping: " + name); |
130 return null; | 130 return null; |
131 } | 131 } |
132 | 132 |
133 // Take first mapping of which all conditions are satisfied. | 133 // Take first mapping of which all conditions are satisfied. |
134 for (ThemeMapping tm: mapping) { | 134 for (ThemeMapping tm: mapping) { |
137 && tm.masterAttrMatches(artifact) | 137 && tm.masterAttrMatches(artifact) |
138 && tm.outputMatches(output)) | 138 && tm.outputMatches(output)) |
139 { | 139 { |
140 String target = tm.getTo(); | 140 String target = tm.getTo(); |
141 | 141 |
142 logger.debug("Found theme '" + target + "'"); | 142 log.debug("Found theme '" + target + "'"); |
143 return t.get(target); | 143 return t.get(target); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 String msg = | 147 String msg = |
148 "No theme found for '" + name + | 148 "No theme found for '" + name + |
149 "' with pattern '" + pattern + "' and output " + output + "."; | 149 "' with pattern '" + pattern + "' and output " + output + "."; |
150 | 150 |
151 logger.warn(msg); | 151 log.warn(msg); |
152 | 152 |
153 return null; | 153 return null; |
154 } | 154 } |
155 | 155 |
156 | 156 |
195 Document themeCfg, | 195 Document themeCfg, |
196 Node cfg, | 196 Node cfg, |
197 Theme t, | 197 Theme t, |
198 Map<String, Node> themes | 198 Map<String, Node> themes |
199 ) { | 199 ) { |
200 logger.debug("ThemeFactory.parseInherits"); | 200 log.debug("ThemeFactory.parseInherits"); |
201 | 201 |
202 NodeList inherits = ((Element)cfg).getElementsByTagName("inherit"); | 202 NodeList inherits = ((Element)cfg).getElementsByTagName("inherit"); |
203 | 203 |
204 int num = inherits.getLength(); | 204 int num = inherits.getLength(); |
205 | 205 |
206 if (num == 0) { | 206 if (num == 0) { |
207 logger.debug("Theme does not inherit from other themes."); | 207 log.debug("Theme does not inherit from other themes."); |
208 return; | 208 return; |
209 } | 209 } |
210 | 210 |
211 logger.debug("Theme inherits from " + num + " other themes."); | 211 log.debug("Theme inherits from " + num + " other themes."); |
212 | 212 |
213 if (themes == null) { | 213 if (themes == null) { |
214 themes = buildThemeMap(themeCfg); | 214 themes = buildThemeMap(themeCfg); |
215 } | 215 } |
216 | 216 |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 protected static void parseFields(Node config, Theme theme) { | 246 protected static void parseFields(Node config, Theme theme) { |
247 if (config == null || theme == null) { | 247 if (config == null || theme == null) { |
248 logger.warn("Parsing fields without node or theme is senseless!"); | 248 log.warn("Parsing fields without node or theme is senseless!"); |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 NodeList fields = ((Element)config).getElementsByTagName("field"); | 252 NodeList fields = ((Element)config).getElementsByTagName("field"); |
253 | 253 |
254 int num = fields.getLength(); | 254 int num = fields.getLength(); |
255 | 255 |
256 logger.debug("Found " + num + " own fields in this theme."); | 256 log.debug("Found " + num + " own fields in this theme."); |
257 | 257 |
258 if (num == 0) { | 258 if (num == 0) { |
259 logger.debug("Theme has no own fields."); | 259 log.debug("Theme has no own fields."); |
260 return; | 260 return; |
261 } | 261 } |
262 | 262 |
263 for (int i = 0; i < num; i++) { | 263 for (int i = 0; i < num; i++) { |
264 Node field = fields.item(i); | 264 Node field = fields.item(i); |
269 | 269 |
270 | 270 |
271 protected static void addField(Theme theme, Node field) { | 271 protected static void addField(Theme theme, Node field) { |
272 String name = ((Element)field).getAttribute("name"); | 272 String name = ((Element)field).getAttribute("name"); |
273 | 273 |
274 logger.debug("Add field " + name + " to theme " + theme.getName()); | 274 log.debug("Add field " + name + " to theme " + theme.getName()); |
275 | 275 |
276 NamedNodeMap attrs = field.getAttributes(); | 276 NamedNodeMap attrs = field.getAttributes(); |
277 | 277 |
278 int num = attrs != null ? attrs.getLength() : 0; | 278 int num = attrs != null ? attrs.getLength() : 0; |
279 | 279 |
280 if (num == 0) { | 280 if (num == 0) { |
281 logger.warn("This field has no attributes."); | 281 log.warn("This field has no attributes."); |
282 return; | 282 return; |
283 } | 283 } |
284 | 284 |
285 ThemeField theField = new DefaultThemeField(name); | 285 ThemeField theField = new DefaultThemeField(name); |
286 | 286 |
301 NamedNodeMap attrs = config.getAttributes(); | 301 NamedNodeMap attrs = config.getAttributes(); |
302 | 302 |
303 int num = attrs != null ? attrs.getLength() : 0; | 303 int num = attrs != null ? attrs.getLength() : 0; |
304 | 304 |
305 if (num == 0) { | 305 if (num == 0) { |
306 logger.debug("Theme has no attributes set."); | 306 log.debug("Theme has no attributes set."); |
307 return; | 307 return; |
308 } | 308 } |
309 | 309 |
310 for (int i = 0; i < num; i++) { | 310 for (int i = 0; i < num; i++) { |
311 Node attr = attrs.item(i); | 311 Node attr = attrs.item(i); |