changeset 1285:0f3b19df1880

Added new service and model for collection item attributes. flys-client/trunk@2871 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 30 Sep 2011 10:57:56 +0000
parents cdb1505a32f1
children b643622d77fe
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java flys-client/src/main/java/de/intevation/flys/client/shared/model/StyleSetting.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 8 files changed, 377 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Sep 30 07:49:41 2011 +0000
+++ b/flys-client/ChangeLog	Fri Sep 30 10:57:56 2011 +0000
@@ -1,3 +1,16 @@
+2011-09-30  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/shared/model/Style.java,
+	  src/main/java/de/intevation/flys/client/shared/model/StyleSetting.java,
+	  src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java,
+	  src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java,
+	  src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java:
+	  New. Added new service and model for collection item attributes.
+
+	* src/main/webapp/WEB-INF/web.xml:
+	  Added the collection item attribute service.
+
 2011-09-30	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
 
 	Fix accidentally messed-up indentation.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,28 @@
+package de.intevation.flys.client.client.services;
+
+import org.w3c.dom.Document;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.CollectionItemAttribute;
+
+/**
+ * This interface provides a method to retrieve an artifact based on its uuid.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+@RemoteServiceRelativePath("collection-item-attribute")
+public interface CollectionItemAttributeService extends RemoteService {
+
+    CollectionItemAttribute getCollectionItemAttribute(
+        Collection collection,
+        String artifact,
+        String url,
+        String locale)
+    throws ServerException;
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,23 @@
+package de.intevation.flys.client.client.services;
+
+import org.w3c.dom.Document;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.CollectionItemAttribute;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface CollectionItemAttributeServiceAsync {
+
+    public void getCollectionItemAttribute(
+        Collection              collection,
+        String                  artifact,
+        String                  serverUrl,
+        String                  locale,
+        AsyncCallback<CollectionItemAttribute> callback);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,127 @@
+package de.intevation.flys.client.server;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.client.services.CollectionItemAttributeService;
+
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.CollectionItemAttribute;
+import de.intevation.flys.client.shared.model.Style;
+import de.intevation.flys.client.shared.model.StyleSetting;
+
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class CollectionItemAttributeServiceImpl
+extends      RemoteServiceServlet
+implements   CollectionItemAttributeService
+{
+    public static final String XPATH_RESULT = "/art:result/text()";
+
+    public static final String OPERATION_FAILURE = "FAILED";
+
+
+    public CollectionItemAttribute getCollectionItemAttribute(
+        Collection collection,
+        String artifact,
+        String url,
+        String locale)
+    throws ServerException
+    {
+        System.out.println(
+            "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute");
+
+        Document requestDoc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+                requestDoc,
+                ArtifactNamespaceContext.NAMESPACE_URI,
+                ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element action = ec.create("action");
+
+        Element type = ec.create("type");
+        ec.addAttr(type, "name", "getitemattribute", false);
+
+        Element art = ec.create("artifact");
+        ec.addAttr(art, "uuid", artifact, false);
+
+        type.appendChild(art);
+        action.appendChild(type);
+        requestDoc.appendChild (action);
+
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            Document res = (Document) client.doCollectionAction(
+                requestDoc,
+                collection.identifier(),
+                new DocumentResponseHandler());
+
+            return readXML (res);
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+        throw new ServerException("");
+    }
+
+    protected CollectionItemAttribute readXML (Document doc) {
+        CollectionItemAttribute cia = new CollectionItemAttribute();
+
+        Element root = doc.getDocumentElement();
+        NodeList themes = root.getElementsByTagName("art:themes");
+
+        if (themes.getLength() != 1) {
+            return null;
+        }
+
+        Element e = (Element) themes.item(0);
+        NodeList items = e.getElementsByTagName("theme");
+
+        for (int i = 0; i < items.getLength(); i++) {
+            cia.appendStyle(getStyle ((Element) items.item(i)));
+        }
+
+        return cia;
+    }
+
+
+    protected Style getStyle (Element element) {
+
+        if (!element.getTagName().equals("theme")) {
+            return null;
+        }
+
+        NodeList list = element.getElementsByTagName("field");
+        Style style = new Style();
+        style.setName (element.getAttribute("name"));
+        for(int i = 0; i < list.getLength(); i++) {
+            Element e = (Element) list.item(i);
+            StyleSetting set = new StyleSetting (
+                e.getAttribute("name"),
+                e.getAttribute("default"),
+                e.getAttribute("display"),
+                e.getAttribute("hints"),
+                e.getAttribute("type"));
+            style.appendStyleSetting(set);
+        }
+        return style;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,48 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+import java.util.List;
+import java.util.ArrayList;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class CollectionItemAttribute implements Serializable {
+
+    protected List<Style> styles;
+
+    public CollectionItemAttribute() {
+        styles = new ArrayList<Style>();
+    }
+
+    public void appendStyle (Style style) {
+        this.styles.add(style);
+    }
+
+    public void removeStyle (String name) {
+        for (int i = 0; i < styles.size(); i++) {
+            if (styles.get(i).getName().equals(name)) {
+                styles.remove(i);
+            }
+        }
+    }
+
+    public Style getStyle(String name) {
+        for (int i = 0; i < styles.size(); i++) {
+            if (styles.get(i).getName().equals(name)) {
+                return styles.get(i);
+            }
+        }
+        return null;
+    }
+
+    public Style getStyle(int i) {
+        return styles.get(i);
+    }
+
+    public int getNumStyles() {
+        return styles.size();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,44 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class Style implements Serializable {
+
+    protected String name;
+    protected List<StyleSetting> settings;
+
+    public Style() {
+        settings = new ArrayList<StyleSetting>();
+    }
+
+    public void appendStyleSetting(StyleSetting setting) {
+        settings.add(setting);
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public StyleSetting getSetting(String name) {
+        for (int i = 0; i < settings.size (); i++) {
+            if (settings.get(i).getName().equals(name)) {
+                return settings.get(i);
+            }
+        }
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StyleSetting.java	Fri Sep 30 10:57:56 2011 +0000
@@ -0,0 +1,84 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class StyleSetting implements Serializable {
+
+    /**The settings name.*/
+    protected String name;
+
+    /** The default value.*/
+    protected String defaultValue;
+
+    /**The display name*/
+    protected String displayName;
+
+    /**Hints.*/
+    protected String hints;
+
+    /**The type*/
+    protected String type;
+
+    public StyleSetting() {
+    }
+
+    public StyleSetting(
+        String name,
+        String defaultValue,
+        String displayName,
+        String hints,
+        String type)
+    {
+        this.name = name;
+        this.defaultValue = defaultValue;
+        this.displayName = displayName;
+        this.hints = hints;
+        this.type = type;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setDefaultValue(String value) {
+        this.defaultValue = value;
+    }
+
+    public void setDisplayName(String name) {
+        this.displayName = name;
+    }
+
+    public void setHints(String hints) {
+        this.hints = hints;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public String getDefaultValue() {
+        return this.defaultValue;
+    }
+
+    public String getDisplayName() {
+        return this.displayName;
+    }
+
+    public String getHints() {
+        return this.hints;
+    }
+
+    public String getType() {
+        return this.type;
+    }
+}
+
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Fri Sep 30 07:49:41 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Fri Sep 30 10:57:56 2011 +0000
@@ -208,6 +208,16 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>CollectionItemAttributeService</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.CollectionItemAttributeServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>CollectionItemAttributeService</servlet-name>
+    <url-pattern>/flys/collection-item-attribute</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>ChartInfoService</servlet-name>
     <servlet-class>de.intevation.flys.client.server.ChartInfoServiceImpl</servlet-class>
   </servlet>

http://dive4elements.wald.intevation.org