diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1478:237e7450ae2e

Save output settings in chart properties dialog. flys-client/trunk@3524 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 22 Dec 2011 12:46:23 +0000
parents c899a7ffdc8f
children c21d14e48040
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Thu Dec 22 09:28:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Thu Dec 22 12:46:23 2011 +0000
@@ -178,6 +178,22 @@
             }
         }
 
+        Document doc = out.getOwnerDocument();
+
+        ElementCreator settingscr = new ElementCreator(doc, "", "");
+
+        Settings settings = collection.getSettings(mode.getName());
+        if (settings == null ||
+            settings.getCategories().size() == 0)
+        {
+            logger.debug("No settings for output mode: " + mode.getName());
+            return null;
+        }
+        Element s = createSettingsElement(settingscr, collection, settings);
+        if (s != null) {
+            out.appendChild(s);
+        }
+        logger.info(XMLUtils.toString(out));
         return out;
     }
 
@@ -285,6 +301,86 @@
 
 
     /**
+     *
+     */
+    protected static Element createSettingsElement(
+        ElementCreator cr,
+        Collection c,
+        Settings s)
+    {
+        logger.debug("CollectionHelper.createSettingsElement");
+        Element settings = cr.create("settings");
+
+        List<String> categories = s.getCategories();
+
+        for (String category: categories) {
+            Element cat =cr.create(category);
+            settings.appendChild(cat);
+            List<Property> props = s.getSettings(category);
+            for (Property p: props) {
+                if (p instanceof PropertyGroup) {
+                    Element prop = createPropertyGroupElement(cr,
+                                                              (PropertyGroup)p);
+                    cat.appendChild(prop);
+                }
+                else if (p instanceof PropertySetting) {
+                    Element prop = createPropertyElement (cr,
+                                                          (PropertySetting)p);
+                    cat.appendChild(prop);
+                }
+            }
+        }
+        return settings;
+    }
+
+
+    /**
+     *
+     */
+    protected static Element createPropertyGroupElement(
+        ElementCreator cr,
+        PropertyGroup pg)
+    {
+        Element e = cr.create(pg.getName());
+
+        List<Property> list = pg.getProperties();
+        for (Property p: list) {
+            Element pe = createPropertyElement(cr, (PropertySetting)p);
+            e.appendChild(pe);
+        }
+        return e;
+    }
+
+
+    /**
+     *
+     */
+    protected static Element createPropertyElement(
+        ElementCreator cr,
+        PropertySetting p)
+    {
+        Element e = cr.create(p.getName());
+
+        if(p instanceof BooleanProperty) {
+            cr.addAttr(e, "type", "boolean", false);
+        }
+        else if(p instanceof DoubleProperty) {
+            cr.addAttr(e, "type", "double", false);
+        }
+        else if(p instanceof IntegerProperty) {
+            cr.addAttr(e, "type", "integer", false);
+        }
+        else if(p instanceof StringProperty) {
+            cr.addAttr(e, "type", "string", false);
+        }
+
+        e.setTextContent(p.getValue());
+        cr.addAttr(e, "display", p.getAttribute("display"), false);
+        return e;
+    }
+
+
+    /**
      * Take the DESCRIBE document of the Collections describe()
      * operation and extracts the information about the collection itself and
      * the collection items.
@@ -512,7 +608,6 @@
      *
      */
     protected static Settings parseSettings(String outName, Element node) {
-        logger.info("parseSettings(String,Element)");
         OutputSettings set = new OutputSettings(outName);
 
         NodeList elements = node.getElementsByTagName("settings");
@@ -558,7 +653,6 @@
      *
      */
     protected static Property parseSettingsGroup(Element group) {
-        logger.debug("parseSettingsGroup");
         PropertyGroup p = new PropertyGroup();
         p.setName(group.getTagName());
 
@@ -576,7 +670,6 @@
      *
      */
     protected static Property parseSetting(Element property){
-        logger.debug("parseSetting");
         NamedNodeMap attrMap = property.getAttributes();
         int          attrNum = attrMap != null ? attrMap.getLength() : 0;
 

http://dive4elements.wald.intevation.org