changeset 341:eca7892bf8ff

Added a first small theme configuration and code to read it. flys-artifacts/trunk@1740 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 21 Apr 2011 08:47:39 +0000
parents b36fd8f21e6a
children f72c63713099
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java
diffstat 5 files changed, 143 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/themes/Theme.java,
--- 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 @@
         <url>jdbc:postgresql://localhost:5432/flys</url>
     </backend-database>
     -->
+
+    <flys>
+        <themes>
+            <configuration>${artifacts.config.dir}/themes.xml</configuration>
+        </themes>
+    </flys>
 </artifact-database>
--- /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 @@
+<themes>
+
+    <!-- Concrete themes are following now! -->
+    <theme name="DischargeCurve">
+        <inherits>
+            <inherit from="HiddenColorLines"/>
+        </inherits>
+    </theme>
+
+
+
+    <!-- Virtual themes are following now! -->
+    <theme name="Lines" type="virtual">
+        <fields>
+            <field name="showlines" type="boolean" display="Linie anzeigen" default="true"/>
+            <field name="linesize"  type="int"     display="Liniendicke"    default="1"/>
+            <field name="linetype"  type="Dash"    display="Linienart"      default="new Dash()"/>
+        </fields>
+    </theme>
+
+    <theme name="ColorLines" type="virtual">
+        <inherits>
+            <inherit from="Lines"/>
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="Color.BLACK"/>
+        </fields>
+    </theme>
+
+    <theme name="HiddenColorLines" type="virtual">
+        <inherits>
+            <inherit from="ColorLines"/>
+        </inherits>
+        <fields>
+            <field name="showlines" type="boolean" display="Linie anzeigen" default="true"        hints="h"/>
+            <field name="linesize"  type="int"     display="Liniendicke"    default="1"           hints="h"/>
+            <field name="linetype"  type="Dash"    display="Linienart"      default="new Dash()"  hints="h"/>
+        </fields>
+    </theme>
+
+
+
+    <!-- Mappings are following now. A mapping maps between a name of a facet
+         and a theme. -->
+    <mappings>
+        <mapping from="discharge_curve.curve" to="DischargeCurve"/>
+    </mappings>
+</themes>
--- 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.
--- 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<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);
+            }
+        }
+
+        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 :

http://dive4elements.wald.intevation.org