diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java @ 1292:bdc270ea6195

Edited item attributes are saved and send to the server on accept. flys-client/trunk@2898 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 05 Oct 2011 16:29:14 +0000
parents 0f3b19df1880
children d9cb362b8b34
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java	Wed Oct 05 16:29:14 2011 +0000
@@ -45,7 +45,7 @@
     throws ServerException
     {
         System.out.println(
-            "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute");
+            "CollectionItemAttributeServiceImpl.getCollectionItemAttribute");
 
         Document requestDoc = XMLUtils.newDocument();
 
@@ -72,8 +72,7 @@
                 requestDoc,
                 collection.identifier(),
                 new DocumentResponseHandler());
-
-            return readXML (res);
+            return readXML (res, artifact);
         }
         catch (ConnectionException ce) {
             System.err.println(ce.getLocalizedMessage());
@@ -81,8 +80,38 @@
         throw new ServerException("");
     }
 
-    protected CollectionItemAttribute readXML (Document doc) {
+
+    public void setCollectionItemAttribute(
+        Collection collection,
+        String artifact,
+        String url,
+        String locale,
+        CollectionItemAttribute attributes)
+    throws ServerException
+    {
+        System.out.println(
+            "CollectionItemAttributeServiceImpl.setCollectionItemAttribute");
+
+        Document doc = writeXML(attributes, artifact);
+
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            Document res = (Document) client.doCollectionAction(
+                doc,
+                collection.identifier(),
+                new DocumentResponseHandler());
+
+            return;
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+        throw new ServerException("");
+    }
+
+    protected CollectionItemAttribute readXML (Document doc, String artifact) {
         CollectionItemAttribute cia = new CollectionItemAttribute();
+        cia.setArtifact(artifact);
 
         Element root = doc.getDocumentElement();
         NodeList themes = root.getElementsByTagName("art:themes");
@@ -102,6 +131,56 @@
     }
 
 
+    protected Document writeXML (
+        CollectionItemAttribute attributes,
+        String artifact)
+    {
+        Document styles = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+                styles,
+                ArtifactNamespaceContext.NAMESPACE_URI,
+                ArtifactNamespaceContext.NAMESPACE_PREFIX);
+        Element action = ec.create("action");
+        Element type = ec.create("type");
+        type.setAttribute("name", "setitemattribute");
+        Element art = ec.create("artifact");
+        art.setAttribute("uuid", artifact);
+        Element attr = ec.create("attribute");
+        Element themes = ec.create("themes");
+        action.appendChild(type);
+        type.appendChild(art);
+        art.appendChild(attr);
+        attr.appendChild(themes);
+
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+                styles,
+                "",
+                "");
+
+        for (int i = 0; i < attributes.getNumStyles(); i++) {
+            Style s = attributes.getStyle(i);
+            Element theme = creator.create("theme");
+            theme.setAttribute("name", s.getName());
+            theme.setAttribute("facet", s.getFacet());
+            theme.setAttribute("index", String.valueOf(i));
+            for (int j = 0; j < s.getNumSettings(); j++) {
+                StyleSetting set = s.getSetting(j);
+                Element field = creator.create("field");
+                field.setAttribute("name", set.getName());
+                field.setAttribute("display", set.getDisplayName());
+                field.setAttribute("default", set.getDefaultValue());
+                field.setAttribute("hints", set.getHints());
+                field.setAttribute("type", set.getType());
+                theme.appendChild(field);
+            }
+            themes.appendChild(theme);
+        }
+        styles.appendChild(action);
+        return styles;
+    }
+
+
     protected Style getStyle (Element element) {
 
         if (!element.getTagName().equals("theme")) {
@@ -110,7 +189,9 @@
 
         NodeList list = element.getElementsByTagName("field");
         Style style = new Style();
+
         style.setName (element.getAttribute("name"));
+        style.setFacet (element.getAttribute("facet"));
         for(int i = 0; i < list.getLength(); i++) {
             Element e = (Element) list.item(i);
             StyleSetting set = new StyleSetting (

http://dive4elements.wald.intevation.org