diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Wed May 23 08:12:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Wed May 23 08:46:45 2012 +0000
@@ -29,6 +29,7 @@
 import de.intevation.flys.artifacts.states.StateFactory;
 import de.intevation.flys.artifacts.transitions.TransitionFactory;
 import de.intevation.flys.themes.Theme;
+import de.intevation.flys.themes.ThemeGroup;
 import de.intevation.flys.themes.ThemeFactory;
 import de.intevation.flys.themes.ThemeMapping;
 
@@ -69,7 +70,10 @@
         "/artifact-database/flys/themes/configuration/text()";
 
     public static final String XPATH_THEMES =
-        "/themes/theme";
+        "theme";
+
+    public static final String XPATH_THEME_GROUPS =
+        "/themes/themegroup";
 
     public static final String XPATH_THEME_MAPPINGS =
         "/themes/mappings/mapping";
@@ -281,36 +285,49 @@
 
         Document cfg = getThemeConfig(config);
 
-        NodeList themes = (NodeList) XMLUtils.xpath(
-            cfg, XPATH_THEMES, XPathConstants.NODESET);
+        NodeList themeGroups = (NodeList) XMLUtils.xpath(
+            cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET);
 
-        int num = themes != null ? themes.getLength() : 0;
+        int groupNum = themeGroups != null ? themeGroups.getLength() : 0;
 
-        if (num == 0) {
-            logger.warn("There are no themes configured!");
-            return;
+        if (groupNum == 0) {
+            logger.warn("There are no theme groups configured!");
         }
 
-        logger.debug("Found " + num + " configured themes.");
-
-        Map<String, Theme> theThemes = new HashMap<String, Theme>();
-
-        for (int i = 0; i < num; i++) {
-            Node theme = themes.item(i);
-
-            Theme theTheme = ThemeFactory.createTheme(cfg, theme);
+        List<ThemeGroup> groups = new ArrayList<ThemeGroup>();
 
-            if (theme != null) {
-                theThemes.put(theTheme.getName(), theTheme);
-            }
-        }
+        for (int g = 0; g < groupNum; g++) {
+            Element themeGroup = (Element) themeGroups.item(g);
+            NodeList themes = (NodeList) XMLUtils.xpath(
+                themeGroup, XPATH_THEMES, XPathConstants.NODESET);
 
-        logger.debug("Initialized " + theThemes.size() + "/" + num + " themes");
+            int num = themes != null ? themes.getLength() : 0;
 
-        context.put(FLYSContext.THEMES, theThemes);
+            if (num == 0) {
+                logger.warn("There are no themes configured!");
+                return;
+            }
+
+            logger.debug("Found " + num + " configured theme groups.");
+
+            Map<String, Theme> theThemes = new HashMap<String, Theme>();
+
+            for (int i = 0; i < num; i++) {
+                Node theme = themes.item(i);
+
+                Theme theTheme = ThemeFactory.createTheme(cfg, theme);
+
+                if (theme != null) {
+                    theThemes.put(theTheme.getName(), theTheme);
+                }
+            }
+            String gName = themeGroup.getAttribute("name");
+            groups.add(new ThemeGroup(gName, theThemes));
+            logger.debug("Initialized " + theThemes.size() + "/" + num + " themes");
+        }
+        context.put(FLYSContext.THEMES, groups);
     }
 
-
     /**
      * This method is used to retrieve the theme configuration document.
      *

http://dive4elements.wald.intevation.org