changeset 3630:28be160b5870

Add a module service. It's now possible to configure the modules which are available for a client. With the selected attribute it is possible to give a hint for the client which module should be pre selected by default flys-artifacts/trunk@5330 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 31 Aug 2012 13:17:16 +0000
parents f3717e625b0a
children 2b8e1864213e
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.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 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Module.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/ModuleService.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 10 files changed, 169 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 31 13:17:16 2012 +0000
@@ -1,3 +1,18 @@
+2012-08-31	Björn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/ModuleService.java,
+	  src/main/java/de/intevation/flys/artifacts/model/Module.java,
+	  src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java,
+	  src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java,
+	  src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties,
+	  doc/conf/conf.xml:
+	  Add a module service. It's now possible to configure the modules which are
+	  available for a client. With the selected attribute it is possible to give
+	  a hint for the client which module should be pre selected by default.
+
 2012-08-31  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/minfo/BedQualityState.java,
--- a/flys-artifacts/doc/conf/conf.xml	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Fri Aug 31 13:17:16 2012 +0000
@@ -182,6 +182,10 @@
                 name="sq-km-chart"
                 service="de.intevation.flys.artifacts.services.SQKMChartService"
                 description="Returns a chart of km and date of meassuring points of a given river.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
+            <service-factory
+                name="modules"
+                service="de.intevation.flys.artifacts.services.ModuleService"
+                description="Returns a list of available modules.">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
         </service-factories>
 
     </factories>
@@ -215,6 +219,13 @@
         <artifact name="qsector" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/qsector.xml" />
     </artifacts>
 
+    <modules>
+        <module name="winfo" selected="true"/>
+        <module name="minfo"/>
+        <module name="new_map"/>
+        <module name="new_chart"/>
+        <module name="fixanalysis"/>
+    </modules>
 
     <hooks>
         <hook
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java	Fri Aug 31 13:17:16 2012 +0000
@@ -54,6 +54,9 @@
     public static final String SCHEDULER =
         "flys.wsplgen.scheduler";
 
+    /** Key to store the configured modules in the context. */
+    public static final String MODULES = "flys.modules";
+
 
     /**
      * The default constructor.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Fri Aug 31 13:17:16 2012 +0000
@@ -26,6 +26,7 @@
 import de.intevation.artifactdatabase.transition.Transition;
 import de.intevation.artifactdatabase.transition.TransitionEngine;
 
+import de.intevation.flys.artifacts.model.Module;
 import de.intevation.flys.artifacts.states.StateFactory;
 import de.intevation.flys.artifacts.transitions.TransitionFactory;
 import de.intevation.flys.themes.Theme;
@@ -81,6 +82,8 @@
     public static final String XPATH_RIVER_WMS =
         "/artifact-database/floodmap/river";
 
+    public static final String XPATH_MODULES = "/artifact-database/modules/module";
+
     /**
      * Creates a new FLYSArtifactContext object and initialize all
      * components required by the application.
@@ -97,6 +100,7 @@
         configureThemes(config, context);
         configureThemesMappings(config, context);
         configureRiverWMS(config, context);
+        configureModules(config, context);
 
         return context;
     }
@@ -423,5 +427,31 @@
 
         context.put(FLYSContext.RIVER_WMS, riverWMS);
     }
+
+
+    /**
+     * This method initializes the modules configuration.
+     *
+     * @param config the config document.
+     * @param context the FLYSContext.
+     */
+    protected void configureModules(Document cfg, FLYSContext context) {
+        NodeList modulenodes = (NodeList) XMLUtils.xpath(
+            cfg, XPATH_MODULES, XPathConstants.NODESET);
+
+        int num = modulenodes != null ? modulenodes.getLength() : 0;
+        ArrayList<Module> modules = new ArrayList<Module>(num);
+
+        for (int i = 0; i < num; i++) {
+            Element e = (Element) modulenodes.item(i);
+            String modulename = e.getAttribute("name");
+            String attrselected = e.getAttribute("selected");
+            boolean selected = attrselected == null ? false :
+                attrselected.equalsIgnoreCase("true");
+            logger.debug("Loaded module " + modulename);
+            modules.add(new Module(modulename, selected));
+        }
+        context.put(FLYSContext.MODULES, modules);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Module.java	Fri Aug 31 13:17:16 2012 +0000
@@ -0,0 +1,25 @@
+package de.intevation.flys.artifacts.model;
+
+/**
+ * Represents a Module as is is loaded from the config
+ */
+public class Module {
+
+    private String name;
+    private boolean selected;
+
+    public Module(String name, boolean selected) {
+        this.name = name;
+        this.selected = selected;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public boolean isSelected() {
+        return this.selected;
+    }
+}
+
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/ModuleService.java	Fri Aug 31 13:17:16 2012 +0000
@@ -0,0 +1,62 @@
+package de.intevation.flys.artifacts.services;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.GlobalContext;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.flys.artifacts.model.Module;
+import de.intevation.flys.artifacts.context.FLYSContext;
+import de.intevation.flys.artifacts.resources.Resources;
+
+public class ModuleService extends FLYSService {
+
+    private static final String MODULE = "module";
+
+    private static Logger logger = Logger.getLogger(ModuleService.class);
+
+    protected Document doProcess(
+        Document      data,
+        GlobalContext globalContext,
+        CallMeta      callMeta
+    ) {
+        logger.debug("ModuleService.process");
+
+        Document result = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            result,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element em = ec.create("modules");
+        List<Module> modules = (List<Module>)globalContext.get(FLYSContext.MODULES);
+
+        for (Module module : modules) {
+            Element m = ec.create("module");
+            ec.addAttr(m, "name", module.getName(), true);
+            String localname = Resources.getMsg(callMeta,
+                    MODULE + "." + module.getName(), module.getName());
+            ec.addAttr(m, "localname", localname, true);
+
+            if (module.isSelected()) {
+                ec.addAttr(m, "selected", "true", true);
+            }
+
+            em.appendChild(m);
+        }
+
+        result.appendChild(em);
+
+        return result;
+    }
+}
+
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80:
--- a/flys-artifacts/src/main/resources/messages.properties	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Fri Aug 31 13:17:16 2012 +0000
@@ -417,3 +417,9 @@
 sq.km.chart.title = Measuring Points
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Date
+
+module.winfo = WINFO
+module.minfo = MINFO
+module.fixanalysis = Fix Analysis
+module.new_map = New Map
+module.new_chart = New Chart
--- a/flys-artifacts/src/main/resources/messages_de.properties	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Fri Aug 31 13:17:16 2012 +0000
@@ -420,3 +420,9 @@
 sq.km.chart.title = Messstellen
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Datum
+
+module.winfo = WINFO
+module.minfo = MINFO
+module.fixanalysis = Fixierungsanalyse
+module.new_map = Neue Karte
+module.new_chart = Neues Diagramm
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Fri Aug 31 13:17:16 2012 +0000
@@ -419,3 +419,9 @@
 sq.km.chart.title = Messstellen
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Datum
+
+module.winfo = WINFO
+module.minfo = MINFO
+module.fixanalysis = Fixierungsanalyse
+module.new_map = Neue Karte
+module.new_chart = Neues Diagramm
--- a/flys-artifacts/src/main/resources/messages_en.properties	Fri Aug 31 11:26:49 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Fri Aug 31 13:17:16 2012 +0000
@@ -419,3 +419,8 @@
 sq.km.chart.km.axis = km
 sq.km.chart.date.axis = Date
 
+module.winfo = WINFO
+module.minfo = MINFO
+module.fixanalysis = Fix Analysis
+module.new_map = New Map
+module.new_chart = New Chart

http://dive4elements.wald.intevation.org