diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 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 8da36efc839a
children 237e7450ae2e
line wrap: on
line diff
--- 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());
 

http://dive4elements.wald.intevation.org