comparison flys-client/src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java @ 99:5c3d685546a6

Added a new service to describe collections. flys-client/trunk@1613 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 30 Mar 2011 07:35:59 +0000
parents c8cd1b918901
children f7967d12ce6e
comparison
equal deleted inserted replaced
98:83bf2fb17b7c 99:5c3d685546a6
32 32
33 /** 33 /**
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
35 */ 35 */
36 public class AddArtifactServiceImpl 36 public class AddArtifactServiceImpl
37 extends RemoteServiceServlet 37 extends DescribeCollectionServiceImpl
38 implements AddArtifactService 38 implements AddArtifactService
39 { 39 {
40 public Collection add(Collection collection, Artifact artifact, String url) { 40 public Collection add(Collection collection, Artifact artifact, String url) {
41 System.out.println("AddArtifactServiceImpl - add()"); 41 System.out.println("AddArtifactServiceImpl.add");
42 42
43 Document add = ClientProtocolUtils.newAddArtifactDocument( 43 Document add = ClientProtocolUtils.newAddArtifactDocument(
44 artifact.getUuid(), null); 44 artifact.getUuid(), null);
45 45
46 HttpClient client = new HttpClientImpl(url); 46 HttpClient client = new HttpClientImpl(url);
61 System.err.println(ce.getLocalizedMessage()); 61 System.err.println(ce.getLocalizedMessage());
62 } 62 }
63 63
64 return null; 64 return null;
65 } 65 }
66
67
68 /**
69 * This method takes the DESCRIBE document of the Collections describe()
70 * operation and extracts the information about the collection itself and
71 * the collection items.
72 *
73 * @param description The DESCRIBE document of the Collections describe()
74 * operation.
75 *
76 * @return a Collection with CollectionItems.
77 */
78 protected Collection parseCollection(Document description) {
79 System.out.println("AddArtifactServiceImpl.parseCollection");
80
81 if (description == null) {
82 System.err.println("The DESCRIBE of the Collection is null!");
83 return null;
84 }
85
86 String uuid = XMLUtils.xpathString(
87 description,
88 "art:artifact-collection/@art:uuid",
89 ArtifactNamespaceContext.INSTANCE);
90
91 if (uuid == null || uuid.equals("")) {
92 System.err.println("Found an invalid Collection!");
93 return null;
94 }
95
96 Collection c = new DefaultCollection(uuid);
97
98 NodeList items = (NodeList) XMLUtils.xpath(
99 description,
100 "art:artifact-collection/art:artifacts/art:artifact",
101 XPathConstants.NODESET,
102 ArtifactNamespaceContext.INSTANCE);
103
104 if (items == null || items.getLength() == 0) {
105 System.out.println("No collection item found for this collection.");
106
107 return c;
108 }
109
110 int size = items.getLength();
111
112 for (int i = 0; i < size; i++) {
113 CollectionItem item = parseCollectionItem(items.item(i));
114
115 if (item != null) {
116 c.addItem(item);
117 }
118 }
119
120 System.out.println(
121 "Found " + c.getItemLength() + " collection items " +
122 "for the Collection '" + c.identifier() + "'.");
123
124 return c;
125 }
126
127
128 /**
129 * This method extracts the CollectionItem from <i>node</i> with its output
130 * modes. The output modes are parsed using the parseOutputModes() method.
131 *
132 * @param node A node that contains information about a CollectionItem.
133 *
134 * @return a CollectionItem.
135 */
136 protected CollectionItem parseCollectionItem(Node node) {
137 System.out.println("AddArtifactServiceImpl.parseCollectionItem");
138
139 if (node == null) {
140 System.err.println("The node for parsing CollectionItem is null!");
141 return null;
142 }
143
144 String uuid = XMLUtils.xpathString(
145 node, "@art:uuid", ArtifactNamespaceContext.INSTANCE);
146
147 String hash = XMLUtils.xpathString(
148 node, "@art:hash", ArtifactNamespaceContext.INSTANCE);
149
150 if (uuid == null || uuid.equals("")) {
151 System.err.println("Found an invalid CollectionItem!");
152 }
153
154 Node outputmodes = (Node) XMLUtils.xpath(
155 node,
156 "art:outputmodes",
157 XPathConstants.NODE,
158 ArtifactNamespaceContext.INSTANCE);
159
160 List<OutputMode> modes = parseOutputModes(outputmodes);
161
162 return new DefaultCollectionItem(uuid, hash, modes);
163 }
164
165
166 /**
167 * This method extracts the OutputModes available for a specific
168 * CollectionItem and returns them as list.
169 *
170 * @param node The root node of the outputmodes list.
171 *
172 * @return a list of OutputModes.
173 */
174 protected List<OutputMode> parseOutputModes(Node node) {
175 System.out.println("AddArtifactServiceImpl.parseOutputModes");
176
177 if (node == null) {
178 System.err.println("The node for parsing OutputModes is null!");
179 return null;
180 }
181
182 NodeList list = (NodeList) XMLUtils.xpath(
183 node,
184 "art:output",
185 XPathConstants.NODESET,
186 ArtifactNamespaceContext.INSTANCE);
187
188 if (list == null || list.getLength() == 0) {
189 System.err.println("No outputmode nodes found!");
190 return null;
191 }
192
193 int size = list.getLength();
194
195 List<OutputMode> modes = new ArrayList<OutputMode>(size);
196
197 for (int i = 0; i < size; i++) {
198 Node tmp = list.item(i);
199 String name = XMLUtils.xpathString(
200 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE);
201 String desc = XMLUtils.xpathString(
202 tmp, "@art:description", ArtifactNamespaceContext.INSTANCE);
203 String mime = XMLUtils.xpathString(
204 tmp, "@art:mime-type", ArtifactNamespaceContext.INSTANCE);
205
206 if (name == null || name.equals("")) {
207 System.err.println("Found an invalid output mode.");
208
209 continue;
210 }
211
212 // TODO Parse Facets
213
214 modes.add(new DefaultOutputMode(name, desc, mime));
215 }
216
217 return modes;
218 }
219 } 66 }
220 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 67 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org