diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java @ 345:88a669785863

Initialized the facet2theme mappings configured in themes.xml and added a function to the ThemeFactory that retrieves a theme from FLYSContext based on its name. flys-artifacts/trunk@1747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 26 Apr 2011 13:17:08 +0000
parents eca7892bf8ff
children 32d0a543e3e8
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Fri Apr 22 15:49:35 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Tue Apr 26 13:17:08 2011 +0000
@@ -69,6 +69,9 @@
     public static final String XPATH_THEMES =
         "/themes/theme";
 
+    public static final String XPATH_THEME_MAPPINGS =
+        "/themes/mappings/mapping";
+
     /**
      * Creates a new FLYSArtifactContext object and initialize all
      * components required by the application.
@@ -83,6 +86,7 @@
         configureStates(config, context);
         configureOutGenerators(config, context);
         configureThemes(config, context);
+        configureThemesMappings(config, context);
 
         return context;
     }
@@ -318,5 +322,42 @@
 
         return XMLUtils.parseDocument(new File(themeConfig));
     }
+
+
+    protected void configureThemesMappings(Document cfg, FLYSContext context) {
+        logger.debug("FLYSContextFactory.configureThemesMappings");
+
+        Document config = getThemeConfig(cfg);
+
+        NodeList mappings = (NodeList) XMLUtils.xpath(
+            config, XPATH_THEME_MAPPINGS, XPathConstants.NODESET);
+
+        int num = mappings != null ? mappings.getLength() : 0;
+
+        if (num == 0) {
+            logger.warn("No theme <--> facet mappins found!");
+            return;
+        }
+
+        Map<String, String> mapping = new HashMap<String, String>();
+
+        for (int i = 0; i < num; i++) {
+            Node node = mappings.item(i);
+
+            String from = (String) XMLUtils.xpath(
+                node, "@from", XPathConstants.STRING);
+
+            String to = (String) XMLUtils.xpath(
+                node, "@to", XPathConstants.STRING);
+
+            if (from != null && to != null) {
+                mapping.put(from, to);
+            }
+        }
+
+        logger.debug("Found " + mapping.size() + " theme/facet mappings.");
+
+        context.put(FLYSContext.THEME_MAPPING, mapping);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org