changeset 1464:c899a7ffdc8f

Extract and parse the output settings from describe document and add settings objects to collection. flys-client/trunk@3503 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 20 Dec 2011 15:32:08 +0000
parents 14ce1c2a9f6c
children d0bcf5ba7adf
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java
diffstat 5 files changed, 69 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Dec 20 15:22:42 2011 +0000
+++ b/flys-client/ChangeLog	Tue Dec 20 15:32:08 2011 +0000
@@ -1,3 +1,17 @@
+2011-12-20  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/Collection.java:
+	  Added setter for settings.
+
+	* src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java:
+	  Ensure the settings is not null.
+
+	* src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java:
+	  Ensure the categories object is not null.
+
+	* src/main/java/de/intevation/flys/client/server/CollectionHelper.java:
+	  Extract and parse the output settings.
+
 2011-12-20  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Dec 20 15:22:42 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Dec 20 15:32:08 2011 +0000
@@ -48,6 +48,9 @@
 import de.intevation.flys.client.shared.model.PropertyGroup;
 import de.intevation.flys.client.shared.model.PropertySetting;
 import de.intevation.flys.client.shared.model.StringProperty;
+import de.intevation.flys.client.shared.model.DoubleProperty;
+import de.intevation.flys.client.shared.model.IntegerProperty;
+import de.intevation.flys.client.shared.model.BooleanProperty;
 import de.intevation.flys.client.shared.model.OutputSettings;
 
 //temporary
@@ -334,7 +337,6 @@
         }
 
         List<Recommendation> recommended = parseRecommendations(description);
-        Map<String, Settings> outSettings = parseSettings(description);
         Map<String, CollectionItem> collectionItems =
             new HashMap<String, CollectionItem>();
 
@@ -370,6 +372,8 @@
         Map<String, ThemeList> themeLists = parseThemeLists(description, collectionItems);
         c.setThemeLists(themeLists);
 
+        Map<String, Settings> outSettings = parseSettings(description);
+        c.setSettings(outSettings);
         logger.debug(
             "Found " + c.getItemLength() + " collection items " +
             "for the Collection '" + c.identifier() + "'.");
@@ -479,9 +483,26 @@
      * @return Map containing the settings.
      */
     protected static Map<String, Settings> parseSettings(Document description) {
-        //TODO Extract settings from output elements.
         logger.info("parseSettings");
-        Map<String, Settings> list = new HashMap<String, Settings>();
+
+        NodeList lists = (NodeList) XMLUtils.xpath(
+            description,
+            "/art:artifact-collection/art:attribute/art:outputs/art:output",
+            XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        int num = lists != null ? lists.getLength() : 0;
+
+        Map<String, Settings> list = new HashMap<String, Settings>(num);
+
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
+
+        for (int i = 0; i < num; i++) {
+            Element node = (Element)lists.item(i);
+            String outName = node.getAttribute("name");
+            Settings s = parseSettings(outName, node);
+            list.put(outName, s);
+        }
 
         return list;
     }
@@ -490,9 +511,18 @@
     /**
      *
      */
-    protected static Settings parseSettings(String outName, Element settings) {
+    protected static Settings parseSettings(String outName, Element node) {
         logger.info("parseSettings(String,Element)");
         OutputSettings set = new OutputSettings(outName);
+
+        NodeList elements = node.getElementsByTagName("settings");
+
+        if (elements.getLength() == 0 || elements.getLength() > 1) {
+            return set;
+        }
+
+        Element settings = (Element)elements.item(0);
+
         // get the categories
         NodeList catNodes = settings.getChildNodes();
         for (int i = 0; i < catNodes.getLength(); i++) {
@@ -505,9 +535,9 @@
             NodeList list = catNode.getChildNodes();
 
             // iterate through all properties or groups.
-            ArrayList<Property> props = new ArrayList<Property> ();
+            List<Property> props = new ArrayList<Property> ();
             for (int j = 0; j < list.getLength(); j++) {
-                Property p;
+                Property p = new PropertySetting();
                 Element e = (Element)list.item(j);
                 if (e.hasChildNodes() &&
                     e.getFirstChild().getNodeType() != Node.TEXT_NODE) {
@@ -528,6 +558,7 @@
      *
      */
     protected static Property parseSettingsGroup(Element group) {
+        logger.debug("parseSettingsGroup");
         PropertyGroup p = new PropertyGroup();
         p.setName(group.getTagName());
 
@@ -545,6 +576,7 @@
      *
      */
     protected static Property parseSetting(Element property){
+        logger.debug("parseSetting");
         NamedNodeMap attrMap = property.getAttributes();
         int          attrNum = attrMap != null ? attrMap.getLength() : 0;
 
@@ -555,6 +587,15 @@
         if(t.equals("string")) {
             ps = new StringProperty();
         }
+        else if (t.equals("integer")) {
+            ps = new IntegerProperty();
+        }
+        else if (t.equals("double")) {
+            ps = new DoubleProperty();
+        }
+        else if (t.equals("boolean")) {
+            ps = new BooleanProperty();
+        }
         ps.setName(property.getTagName());
         ps.setValue(property.getTextContent());
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Tue Dec 20 15:22:42 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Tue Dec 20 15:32:08 2011 +0000
@@ -40,6 +40,8 @@
 
     public Settings getSettings(String outName);
 
+    public void setSettings(Map<String, Settings> settings);
+
     /** Sets mapping outputname to ThemeList. */
     public void setThemeLists(Map<String, ThemeList> map);
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java	Tue Dec 20 15:22:42 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java	Tue Dec 20 15:32:08 2011 +0000
@@ -229,6 +229,9 @@
 
 
     public void addSettings(String outname, Settings settings) {
+        if (this.settings == null) {
+            this.settings = new HashMap<String, Settings>();
+        }
         this.settings.put(outname, settings);
     }
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java	Tue Dec 20 15:22:42 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java	Tue Dec 20 15:32:08 2011 +0000
@@ -16,7 +16,6 @@
     protected HashMap<String, List<Property> > categories;
 
 
-
     public OutputSettings() {
         this.categories = new HashMap<String, List<Property> >();
     }
@@ -39,6 +38,9 @@
 
 
     public void setSettings(String category, List<Property> settings) {
+        if (this.categories == null) {
+            this.categories = new HashMap<String, List<Property> >();
+        }
         this.categories.put(category, settings);
     }
 

http://dive4elements.wald.intevation.org