diff flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java @ 524:ba238f917b94

The theme list information stored in the attribute of a collection is read and added in form of Themes and ThemeLists to the Collection. flys-client/trunk@2003 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 25 May 2011 13:42:04 +0000
parents d01b0d81b92a
children 5277f46a63c2
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java	Wed May 25 11:34:34 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java	Wed May 25 13:42:04 2011 +0000
@@ -1,7 +1,9 @@
 package de.intevation.flys.client.server;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -27,9 +29,12 @@
 import de.intevation.flys.client.shared.model.DefaultCollectionItem;
 import de.intevation.flys.client.shared.model.DefaultFacet;
 import de.intevation.flys.client.shared.model.DefaultOutputMode;
+import de.intevation.flys.client.shared.model.DefaultTheme;
 import de.intevation.flys.client.shared.model.ExportMode;
 import de.intevation.flys.client.shared.model.Facet;
 import de.intevation.flys.client.shared.model.OutputMode;
+import de.intevation.flys.client.shared.model.Theme;
+import de.intevation.flys.client.shared.model.ThemeList;
 import de.intevation.flys.client.client.services.DescribeCollectionService;
 
 
@@ -72,6 +77,8 @@
                 throw new ServerException(ERROR_DESCRIBE_COLLECTION);
             }
 
+            System.out.println("Collection successfully parsed.");
+
             return c;
         }
         catch (ConnectionException ce) {
@@ -110,7 +117,17 @@
             return null;
         }
 
-        Collection c = new DefaultCollection(uuid);
+        Map<String, ThemeList> themeList = parseThemeLists(description);
+
+        Collection c = null;
+
+        if (themeList != null) {
+            c = new DefaultCollection(uuid, themeList);
+            //c = new DefaultCollection(uuid);
+        }
+        else {
+            c = new DefaultCollection(uuid);
+        }
 
         NodeList items = (NodeList) XMLUtils.xpath(
             description,
@@ -142,6 +159,92 @@
     }
 
 
+    protected Map<String, ThemeList> parseThemeLists(Document description) {
+        System.out.println("DescribeCollectionServiceImpl.parseThemeLists");
+
+        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, ThemeList> themeList = new HashMap<String, ThemeList>(num);
+
+        for (int i = 0; i < num; i++) {
+            Node node = lists.item(i);
+
+            String outName = XMLUtils.xpathString(
+                node, "@name", ArtifactNamespaceContext.INSTANCE);
+
+            ThemeList list = parseThemeList(node);
+
+            if (list != null) {
+                themeList.put(outName, list);
+            }
+        }
+
+        return themeList;
+    }
+
+
+    protected ThemeList parseThemeList(Node node) {
+        System.out.println("DescribeCollectionServiceImpl.parseThemeList");
+
+        NodeList themes = (NodeList) XMLUtils.xpath(
+            node,
+            "art:theme",
+            XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        int num = themes != null ? themes.getLength() : 0;
+
+        List<Theme> themeList = new ArrayList<Theme>(num);
+
+        for (int i = 0; i < num; i++) {
+            Theme theme = parseTheme(themes.item(i));
+
+            if (theme != null) {
+                themeList.add(theme);
+            }
+        }
+
+        return new ThemeList(themeList);
+    }
+
+
+    protected Theme parseTheme(Node node) {
+        System.out.println("DescribeCollectionServiceImpl.parseTheme");
+
+        String strAct = XMLUtils.xpathString(
+            node, "@art:active", ArtifactNamespaceContext.INSTANCE);
+
+        String art = XMLUtils.xpathString(
+            node, "@art:artifact", ArtifactNamespaceContext.INSTANCE);
+
+        String fac = XMLUtils.xpathString(
+            node, "@art:facet", ArtifactNamespaceContext.INSTANCE);
+
+        String strPos = XMLUtils.xpathString(
+            node, "@art:pos", ArtifactNamespaceContext.INSTANCE);
+
+        if (strAct != null && art != null && fac != null && strPos != null) {
+            try {
+                int pos    = Integer.valueOf(strPos);
+                int active = Integer.valueOf(strAct);
+
+                return new DefaultTheme(pos, active > 0, art, fac);
+            }
+            catch (NumberFormatException nfe) {
+                nfe.printStackTrace();
+            }
+        }
+
+        return null;
+    }
+
+
     /**
      * 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