# HG changeset patch # User Ingo Weinzierl # Date 1303375659 0 # Node ID eca7892bf8ff65a37ad4c14364de9487f6cd0ee8 # Parent b36fd8f21e6aa2c6e04105dfadb6bade832347c7 Added a first small theme configuration and code to read it. flys-artifacts/trunk@1740 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b36fd8f21e6a -r eca7892bf8ff flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Apr 21 08:44:41 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Apr 21 08:47:39 2011 +0000 @@ -1,3 +1,16 @@ +2011-04-21 Ingo Weinzierl + + * doc/conf/themes.xml: New. A first small theme configuration. + + * doc/conf/conf.xml: Added a link to the theme configuration. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java: + Defined a key that is used to store a themes map in the FLYSContext. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java: + The theme configuration is read at startup and the themes are stores in + the FLYSContext. + 2011-04-21 Ingo Weinzierl * src/main/java/de/intevation/flys/themes/Theme.java, diff -r b36fd8f21e6a -r eca7892bf8ff flys-artifacts/doc/conf/conf.xml --- a/flys-artifacts/doc/conf/conf.xml Thu Apr 21 08:44:41 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Thu Apr 21 08:47:39 2011 +0000 @@ -70,4 +70,10 @@ jdbc:postgresql://localhost:5432/flys --> + + + + ${artifacts.config.dir}/themes.xml + + diff -r b36fd8f21e6a -r eca7892bf8ff flys-artifacts/doc/conf/themes.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/doc/conf/themes.xml Thu Apr 21 08:47:39 2011 +0000 @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b36fd8f21e6a -r eca7892bf8ff flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Thu Apr 21 08:44:41 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Thu Apr 21 08:47:39 2011 +0000 @@ -30,6 +30,10 @@ public static final String OUTGENERATORS_KEY = "flys.export.outgenerators"; + /** The key that is used to store the map of themes in the context.*/ + public static final String THEMES = + "flys.themes.map"; + /** * The default constructor. diff -r b36fd8f21e6a -r eca7892bf8ff flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Apr 21 08:44:41 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Apr 21 08:47:39 2011 +0000 @@ -27,6 +27,8 @@ 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.ThemeFactory; /** @@ -61,6 +63,12 @@ public static final String XPATH_OUTPUT_GENERATORS = "/artifact-database/output-generators/output-generator"; + public static final String XPATH_THEME_CONFIG = + "/artifact-database/flys/themes/configuration/text()"; + + public static final String XPATH_THEMES = + "/themes/theme"; + /** * Creates a new FLYSArtifactContext object and initialize all * components required by the application. @@ -74,6 +82,7 @@ configureTransitions(config, context); configureStates(config, context); configureOutGenerators(config, context); + configureThemes(config, context); return context; } @@ -246,5 +255,68 @@ logger.info("Successfully loaded " + idx + " output generators."); context.put(FLYSContext.OUTGENERATORS_KEY, generators); } + + + /** + * This methods reads the configured themes and puts them into the + * FLYSContext. + * + * @param config The global configuration. + * @param context The FLYSContext. + */ + protected void configureThemes(Document config, FLYSContext context) { + logger.debug("FLYSContextFactory.configureThemes"); + + Document cfg = getThemeConfig(config); + + NodeList themes = (NodeList) XMLUtils.xpath( + cfg, XPATH_THEMES, XPathConstants.NODESET); + + int num = themes != null ? themes.getLength() : 0; + + if (num == 0) { + logger.warn("There are no themes configured!"); + return; + } + + logger.debug("Found " + num + " configured themes."); + + Map theThemes = new HashMap(); + + 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); + } + } + + logger.debug("Initialized " + theThemes.size() + "/" + num + " themes"); + + context.put(FLYSContext.THEMES, theThemes); + } + + + /** + * This method is used to retrieve the theme configuration document. + * + * @param config The global configuration. + * + * @return the theme configuration. + */ + protected Document getThemeConfig(Document config) { + String themeConfig = (String) XMLUtils.xpath( + config, + XPATH_THEME_CONFIG, + XPathConstants.STRING); + + themeConfig = Config.replaceConfigDir(themeConfig); + + logger.debug("Parse theme cfg: " + themeConfig); + + return XMLUtils.parseDocument(new File(themeConfig)); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :