Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.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 | f72c63713099 |
children | d2a17e990c70 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Fri Apr 22 15:49:35 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeFactory.java Tue Apr 26 13:17:08 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.themes; +import java.util.Map; + import javax.xml.xpath.XPathConstants; import org.apache.log4j.Logger; @@ -11,6 +13,8 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.context.FLYSContext; + /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> @@ -48,6 +52,41 @@ } + /** + * Returns the theme for a specified output type and facet. + * + * @param c The FLYSContext that stores the mappings and themes. + * @param name The name of the mapping. + * + * @return a theme. + */ + public static Theme getTheme(FLYSContext c, String name) { + if (c == null || name == null) { + logger.warn("Cannot search for theme."); + return null; + } + + Map<String, String> map = (Map<String, String>) + c.get(FLYSContext.THEME_MAPPING); + + Map<String, Theme> t = (Map<String, Theme>) + c.get(FLYSContext.THEMES); + + if (map == null || map.size() == 0 || t == null || t.size() == 0) { + logger.warn("No mappings or themes found. Cannot retrieve theme!"); + return null; + } + + String themeName = map.get(name); + + if (themeName == null) { + logger.warn("No theme found for mapping: " + name); + } + + return t.get(themeName); + } + + protected static String getName(Node config) { return (String) XMLUtils.xpath(config, "@name", XPathConstants.STRING); }