diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1439:4df2d9a4b9b4

Added interfaces and container for output settings. Added settings container to collection. Extract settings from describe collection document. flys-client/trunk@3420 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 15 Dec 2011 08:29:04 +0000
parents f6fbfdc813f0
children 8da36efc839a
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Dec 13 13:24:43 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Thu Dec 15 08:29:04 2011 +0000
@@ -43,7 +43,18 @@
 import de.intevation.flys.client.shared.model.Recommendation;
 import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.shared.model.ThemeList;
+import de.intevation.flys.client.shared.model.Settings;
+import de.intevation.flys.client.shared.model.Property;
+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.OutputSettings;
 
+//temporary
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import org.xml.sax.InputSource;
+import java.io.StringReader;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -327,6 +338,7 @@
         }
 
         List<Recommendation> recommended = parseRecommendations(description);
+        Map<String, Settings> outSettings = parseSettings(description);
         Map<String, CollectionItem> collectionItems =
             new HashMap<String, CollectionItem>();
 
@@ -464,6 +476,107 @@
 
 
     /**
+     * Parse Settings elements.
+     *
+     * @param description The collection description.
+     *
+     * @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>();
+
+        return list;
+    }
+
+
+    /**
+     *
+     */
+    protected static Settings parseSettings(String outName, Element settings) {
+        logger.info("parseSettings(String,Element)");
+        OutputSettings set = new OutputSettings(outName);
+        // get the categories
+        NodeList catNodes = settings.getChildNodes();
+        for (int i = 0; i < catNodes.getLength(); i++) {
+            Element catNode = (Element)catNodes.item(i);
+
+            // The category name
+            String category = catNode.getTagName();
+
+            // list of properties or groups (groups have child nodes).
+            NodeList list = catNode.getChildNodes();
+
+            // iterate through all properties or groups.
+            ArrayList<Property> props = new ArrayList<Property> ();
+            for (int j = 0; j < list.getLength(); j++) {
+                Property p;
+                Element e = (Element)list.item(j);
+                if (e.hasChildNodes() &&
+                    e.getFirstChild().getNodeType() != Node.TEXT_NODE) {
+                    p = parseSettingsGroup(e);
+                }
+                else {
+                    p = parseSetting(e);
+                }
+                props.add(p);
+            }
+            set.setSettings(category, props);
+        }
+        return set;
+    }
+
+
+    /**
+     *
+     */
+    protected static Property parseSettingsGroup(Element group) {
+        PropertyGroup p = new PropertyGroup();
+        p.setName(group.getTagName());
+
+        NodeList list = group.getChildNodes();
+        ArrayList<Property> props = new ArrayList<Property>();
+        for (int i = 0; i < list.getLength(); i++) {
+            props.add(parseSetting((Element)list.item(i)));
+        }
+        p.setProperties(props);
+        return p;
+    }
+
+
+    /**
+     *
+     */
+    protected static Property parseSetting(Element property){
+        NamedNodeMap attrMap = property.getAttributes();
+        int          attrNum = attrMap != null ? attrMap.getLength() : 0;
+
+        Node type = attrMap.getNamedItem("type");
+        String t = type.getNodeValue();
+        PropertySetting ps = new PropertySetting();
+
+        if(t.equals("string")) {
+            ps = new StringProperty();
+        }
+        ps.setName(property.getTagName());
+        ps.setValue(property.getTextContent());
+
+        for (int i = 0; i < attrNum; i++) {
+            Node attr = attrMap.item(i);
+
+            String name   = attr.getNodeName();
+            String value  = attr.getNodeValue();
+            if(name.equals("type")) {
+                continue;
+            }
+            ps.setAttribute(name, value);
+        }
+        return ps;
+    }
+
+
+    /**
      * This method extracts the CollectionItem from <i>node</i> with its output
      * modes. The output modes are parsed using the parseOutputModes() method.
      *

http://dive4elements.wald.intevation.org