comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java @ 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
children bdc270ea6195
comparison
equal deleted inserted replaced
1284:cdb1505a32f1 1285:0f3b19df1880
1 package de.intevation.flys.client.server;
2
3 import org.w3c.dom.Document;
4 import org.w3c.dom.Element;
5 import org.w3c.dom.NodeList;
6
7 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
8
9 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
10 import de.intevation.artifacts.httpclient.http.HttpClient;
11 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
12 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
13
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
15 import de.intevation.artifacts.common.utils.XMLUtils;
16
17 import de.intevation.flys.client.shared.exceptions.ServerException;
18 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
19
20 import de.intevation.flys.client.shared.model.Collection;
21 import de.intevation.flys.client.shared.model.Artifact;
22 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
23 import de.intevation.flys.client.shared.model.Style;
24 import de.intevation.flys.client.shared.model.StyleSetting;
25
26
27 /**
28 *
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
30 */
31 public class CollectionItemAttributeServiceImpl
32 extends RemoteServiceServlet
33 implements CollectionItemAttributeService
34 {
35 public static final String XPATH_RESULT = "/art:result/text()";
36
37 public static final String OPERATION_FAILURE = "FAILED";
38
39
40 public CollectionItemAttribute getCollectionItemAttribute(
41 Collection collection,
42 String artifact,
43 String url,
44 String locale)
45 throws ServerException
46 {
47 System.out.println(
48 "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute");
49
50 Document requestDoc = XMLUtils.newDocument();
51
52 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
53 requestDoc,
54 ArtifactNamespaceContext.NAMESPACE_URI,
55 ArtifactNamespaceContext.NAMESPACE_PREFIX);
56
57 Element action = ec.create("action");
58
59 Element type = ec.create("type");
60 ec.addAttr(type, "name", "getitemattribute", false);
61
62 Element art = ec.create("artifact");
63 ec.addAttr(art, "uuid", artifact, false);
64
65 type.appendChild(art);
66 action.appendChild(type);
67 requestDoc.appendChild (action);
68
69 try {
70 HttpClient client = new HttpClientImpl(url, locale);
71 Document res = (Document) client.doCollectionAction(
72 requestDoc,
73 collection.identifier(),
74 new DocumentResponseHandler());
75
76 return readXML (res);
77 }
78 catch (ConnectionException ce) {
79 System.err.println(ce.getLocalizedMessage());
80 }
81 throw new ServerException("");
82 }
83
84 protected CollectionItemAttribute readXML (Document doc) {
85 CollectionItemAttribute cia = new CollectionItemAttribute();
86
87 Element root = doc.getDocumentElement();
88 NodeList themes = root.getElementsByTagName("art:themes");
89
90 if (themes.getLength() != 1) {
91 return null;
92 }
93
94 Element e = (Element) themes.item(0);
95 NodeList items = e.getElementsByTagName("theme");
96
97 for (int i = 0; i < items.getLength(); i++) {
98 cia.appendStyle(getStyle ((Element) items.item(i)));
99 }
100
101 return cia;
102 }
103
104
105 protected Style getStyle (Element element) {
106
107 if (!element.getTagName().equals("theme")) {
108 return null;
109 }
110
111 NodeList list = element.getElementsByTagName("field");
112 Style style = new Style();
113 style.setName (element.getAttribute("name"));
114 for(int i = 0; i < list.getLength(); i++) {
115 Element e = (Element) list.item(i);
116 StyleSetting set = new StyleSetting (
117 e.getAttribute("name"),
118 e.getAttribute("default"),
119 e.getAttribute("display"),
120 e.getAttribute("hints"),
121 e.getAttribute("type"));
122 style.appendStyleSetting(set);
123 }
124 return style;
125 }
126 }
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org