annotate flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java @ 1326:974c6b3700de

Use the theme index to identify the correct style. flys-client/trunk@2968 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 14 Oct 2011 08:36:29 +0000
parents c4c957a9c092
children b18b32269a3f
rev   line source
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 import org.w3c.dom.Element;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import org.w3c.dom.NodeList;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.httpclient.http.HttpClient;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.common.utils.XMLUtils;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.client.shared.exceptions.ServerException;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.client.shared.model.Collection;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.client.shared.model.Style;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import de.intevation.flys.client.shared.model.StyleSetting;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 /**
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 *
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 */
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 public class CollectionItemAttributeServiceImpl
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 extends RemoteServiceServlet
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 implements CollectionItemAttributeService
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 public static final String XPATH_RESULT = "/art:result/text()";
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 public static final String OPERATION_FAILURE = "FAILED";
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37
1310
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
38 public static final String ERROR_NO_STYLES_FOUND =
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
39 "error_no_theme_styles_found";
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
40
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 public CollectionItemAttribute getCollectionItemAttribute(
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 Collection collection,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 String artifact,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 String url,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 String locale)
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 throws ServerException
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 System.out.println(
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
50 "CollectionItemAttributeServiceImpl.getCollectionItemAttribute");
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 Document requestDoc = XMLUtils.newDocument();
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 requestDoc,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 ArtifactNamespaceContext.NAMESPACE_URI,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 ArtifactNamespaceContext.NAMESPACE_PREFIX);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 Element action = ec.create("action");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 Element type = ec.create("type");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 ec.addAttr(type, "name", "getitemattribute", false);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 Element art = ec.create("artifact");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 ec.addAttr(art, "uuid", artifact, false);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 type.appendChild(art);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 action.appendChild(type);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 requestDoc.appendChild (action);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 try {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 HttpClient client = new HttpClientImpl(url, locale);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 Document res = (Document) client.doCollectionAction(
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 requestDoc,
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 collection.identifier(),
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 new DocumentResponseHandler());
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
77 return readXML (res, artifact);
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 catch (ConnectionException ce) {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 System.err.println(ce.getLocalizedMessage());
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
1310
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
82
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
83 throw new ServerException(ERROR_NO_STYLES_FOUND);
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
86
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
87 public void setCollectionItemAttribute(
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
88 Collection collection,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
89 String artifact,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
90 String url,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
91 String locale,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
92 CollectionItemAttribute attributes)
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
93 throws ServerException
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
94 {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
95 System.out.println(
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
96 "CollectionItemAttributeServiceImpl.setCollectionItemAttribute");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
97
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
98 Document doc = writeXML(attributes, artifact);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
99
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
100 try {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
101 HttpClient client = new HttpClientImpl(url, locale);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
102 Document res = (Document) client.doCollectionAction(
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
103 doc,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
104 collection.identifier(),
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
105 new DocumentResponseHandler());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
106
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
107 return;
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
108 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
109 catch (ConnectionException ce) {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
110 System.err.println(ce.getLocalizedMessage());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
111 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
112 throw new ServerException("");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
113 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
114
1310
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
115 protected CollectionItemAttribute readXML(Document doc, String artifact)
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
116 throws ServerException
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
117 {
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 CollectionItemAttribute cia = new CollectionItemAttribute();
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
119 cia.setArtifact(artifact);
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 Element root = doc.getDocumentElement();
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 NodeList themes = root.getElementsByTagName("art:themes");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123
1310
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
124 if (themes == null || themes.getLength() == 0) {
c4c957a9c092 Improved exception handling while fetching theme styles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1295
diff changeset
125 throw new ServerException(ERROR_NO_STYLES_FOUND);
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 Element e = (Element) themes.item(0);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 NodeList items = e.getElementsByTagName("theme");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 for (int i = 0; i < items.getLength(); i++) {
1326
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
132 Style s = getStyle ((Element) items.item(i));
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
133 if(s == null) {
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
134 throw new ServerException(ERROR_NO_STYLES_FOUND);
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
135 }
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
136 else {
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
137 cia.appendStyle(s);
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
138 }
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 return cia;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
145 protected Document writeXML (
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
146 CollectionItemAttribute attributes,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
147 String artifact)
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
148 {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
149 Document styles = XMLUtils.newDocument();
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
150
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
151 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
152 styles,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
153 ArtifactNamespaceContext.NAMESPACE_URI,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
154 ArtifactNamespaceContext.NAMESPACE_PREFIX);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
155 Element action = ec.create("action");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
156 Element type = ec.create("type");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
157 type.setAttribute("name", "setitemattribute");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
158 Element art = ec.create("artifact");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
159 art.setAttribute("uuid", artifact);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
160 Element attr = ec.create("attribute");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
161 Element themes = ec.create("themes");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
162 action.appendChild(type);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
163 type.appendChild(art);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
164 art.appendChild(attr);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
165 attr.appendChild(themes);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
166
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
167 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
168 styles,
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
169 "",
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
170 "");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
171
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
172 for (int i = 0; i < attributes.getNumStyles(); i++) {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
173 Style s = attributes.getStyle(i);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
174 Element theme = creator.create("theme");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
175 theme.setAttribute("name", s.getName());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
176 theme.setAttribute("facet", s.getFacet());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
177 theme.setAttribute("index", String.valueOf(i));
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
178 for (int j = 0; j < s.getNumSettings(); j++) {
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
179 StyleSetting set = s.getSetting(j);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
180 Element field = creator.create("field");
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
181 field.setAttribute("name", set.getName());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
182 field.setAttribute("display", set.getDisplayName());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
183 field.setAttribute("default", set.getDefaultValue());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
184 field.setAttribute("hints", set.getHints());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
185 field.setAttribute("type", set.getType());
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
186 theme.appendChild(field);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
187 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
188 themes.appendChild(theme);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
189 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
190 styles.appendChild(action);
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
191 return styles;
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
192 }
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
193
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
194
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 protected Style getStyle (Element element) {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 if (!element.getTagName().equals("theme")) {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 return null;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 NodeList list = element.getElementsByTagName("field");
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 Style style = new Style();
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
203
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 style.setName (element.getAttribute("name"));
1292
bdc270ea6195 Edited item attributes are saved and send to the server on accept.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1285
diff changeset
205 style.setFacet (element.getAttribute("facet"));
1326
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
206 try {
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
207 int ndx = Integer.parseInt(element.getAttribute("index"));
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
208 style.setIndex (ndx);
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
209 }
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
210 catch(NumberFormatException nfe) {
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
211 return null;
974c6b3700de Use the theme index to identify the correct style.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1310
diff changeset
212 }
1285
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
213 for(int i = 0; i < list.getLength(); i++) {
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214 Element e = (Element) list.item(i);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
215 StyleSetting set = new StyleSetting (
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
216 e.getAttribute("name"),
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
217 e.getAttribute("default"),
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
218 e.getAttribute("display"),
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
219 e.getAttribute("hints"),
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
220 e.getAttribute("type"));
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
221 style.appendStyleSetting(set);
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
222 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
223 return style;
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
224 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
225 }
0f3b19df1880 Added new service and model for collection item attributes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
226 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org