Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java @ 2737:83b22ccf48da
Introduced theme groups and added new service to get themes filtered by name.
flys-artifacts/trunk@4470 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 23 May 2012 08:46:45 +0000 |
parents | 79a94c4171cb |
children | faf73245ec73 |
comparison
equal
deleted
inserted
replaced
2736:8839086c4b7b | 2737:83b22ccf48da |
---|---|
27 import de.intevation.artifactdatabase.transition.TransitionEngine; | 27 import de.intevation.artifactdatabase.transition.TransitionEngine; |
28 | 28 |
29 import de.intevation.flys.artifacts.states.StateFactory; | 29 import de.intevation.flys.artifacts.states.StateFactory; |
30 import de.intevation.flys.artifacts.transitions.TransitionFactory; | 30 import de.intevation.flys.artifacts.transitions.TransitionFactory; |
31 import de.intevation.flys.themes.Theme; | 31 import de.intevation.flys.themes.Theme; |
32 import de.intevation.flys.themes.ThemeGroup; | |
32 import de.intevation.flys.themes.ThemeFactory; | 33 import de.intevation.flys.themes.ThemeFactory; |
33 import de.intevation.flys.themes.ThemeMapping; | 34 import de.intevation.flys.themes.ThemeMapping; |
34 | 35 |
35 | 36 |
36 /** | 37 /** |
67 | 68 |
68 public static final String XPATH_THEME_CONFIG = | 69 public static final String XPATH_THEME_CONFIG = |
69 "/artifact-database/flys/themes/configuration/text()"; | 70 "/artifact-database/flys/themes/configuration/text()"; |
70 | 71 |
71 public static final String XPATH_THEMES = | 72 public static final String XPATH_THEMES = |
72 "/themes/theme"; | 73 "theme"; |
74 | |
75 public static final String XPATH_THEME_GROUPS = | |
76 "/themes/themegroup"; | |
73 | 77 |
74 public static final String XPATH_THEME_MAPPINGS = | 78 public static final String XPATH_THEME_MAPPINGS = |
75 "/themes/mappings/mapping"; | 79 "/themes/mappings/mapping"; |
76 | 80 |
77 public static final String XPATH_RIVER_WMS = | 81 public static final String XPATH_RIVER_WMS = |
279 protected void configureThemes(Document config, FLYSContext context) { | 283 protected void configureThemes(Document config, FLYSContext context) { |
280 logger.debug("FLYSContextFactory.configureThemes"); | 284 logger.debug("FLYSContextFactory.configureThemes"); |
281 | 285 |
282 Document cfg = getThemeConfig(config); | 286 Document cfg = getThemeConfig(config); |
283 | 287 |
284 NodeList themes = (NodeList) XMLUtils.xpath( | 288 NodeList themeGroups = (NodeList) XMLUtils.xpath( |
285 cfg, XPATH_THEMES, XPathConstants.NODESET); | 289 cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET); |
286 | 290 |
287 int num = themes != null ? themes.getLength() : 0; | 291 int groupNum = themeGroups != null ? themeGroups.getLength() : 0; |
288 | 292 |
289 if (num == 0) { | 293 if (groupNum == 0) { |
290 logger.warn("There are no themes configured!"); | 294 logger.warn("There are no theme groups configured!"); |
291 return; | 295 } |
292 } | 296 |
293 | 297 List<ThemeGroup> groups = new ArrayList<ThemeGroup>(); |
294 logger.debug("Found " + num + " configured themes."); | 298 |
295 | 299 for (int g = 0; g < groupNum; g++) { |
296 Map<String, Theme> theThemes = new HashMap<String, Theme>(); | 300 Element themeGroup = (Element) themeGroups.item(g); |
297 | 301 NodeList themes = (NodeList) XMLUtils.xpath( |
298 for (int i = 0; i < num; i++) { | 302 themeGroup, XPATH_THEMES, XPathConstants.NODESET); |
299 Node theme = themes.item(i); | 303 |
300 | 304 int num = themes != null ? themes.getLength() : 0; |
301 Theme theTheme = ThemeFactory.createTheme(cfg, theme); | 305 |
302 | 306 if (num == 0) { |
303 if (theme != null) { | 307 logger.warn("There are no themes configured!"); |
304 theThemes.put(theTheme.getName(), theTheme); | 308 return; |
305 } | 309 } |
306 } | 310 |
307 | 311 logger.debug("Found " + num + " configured theme groups."); |
308 logger.debug("Initialized " + theThemes.size() + "/" + num + " themes"); | 312 |
309 | 313 Map<String, Theme> theThemes = new HashMap<String, Theme>(); |
310 context.put(FLYSContext.THEMES, theThemes); | 314 |
311 } | 315 for (int i = 0; i < num; i++) { |
312 | 316 Node theme = themes.item(i); |
317 | |
318 Theme theTheme = ThemeFactory.createTheme(cfg, theme); | |
319 | |
320 if (theme != null) { | |
321 theThemes.put(theTheme.getName(), theTheme); | |
322 } | |
323 } | |
324 String gName = themeGroup.getAttribute("name"); | |
325 groups.add(new ThemeGroup(gName, theThemes)); | |
326 logger.debug("Initialized " + theThemes.size() + "/" + num + " themes"); | |
327 } | |
328 context.put(FLYSContext.THEMES, groups); | |
329 } | |
313 | 330 |
314 /** | 331 /** |
315 * This method is used to retrieve the theme configuration document. | 332 * This method is used to retrieve the theme configuration document. |
316 * | 333 * |
317 * @param config The global configuration. | 334 * @param config The global configuration. |