Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 268:4edaf3073109
Repaired the setting of a new attribute for a Collection.
artifacts/trunk@2016 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 27 May 2011 08:47:31 +0000 |
parents | a2df2b48d2aa |
children | 22a90706d32d |
comparison
equal
deleted
inserted
replaced
267:72de5c373c9b | 268:4edaf3073109 |
---|---|
12 import de.intevation.artifacts.CallMeta; | 12 import de.intevation.artifacts.CallMeta; |
13 | 13 |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 14 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
15 import de.intevation.artifacts.common.utils.XMLUtils; | 15 import de.intevation.artifacts.common.utils.XMLUtils; |
16 | 16 |
17 import de.intevation.artifactdatabase.ArtifactDatabaseImpl; | |
18 | |
17 import java.io.IOException; | 19 import java.io.IOException; |
20 | |
21 import javax.xml.xpath.XPathConstants; | |
18 | 22 |
19 import org.apache.log4j.Logger; | 23 import org.apache.log4j.Logger; |
20 | 24 |
21 import org.restlet.data.MediaType; | 25 import org.restlet.data.MediaType; |
22 import org.restlet.data.Status; | 26 import org.restlet.data.Status; |
25 import org.restlet.representation.Representation; | 29 import org.restlet.representation.Representation; |
26 import org.restlet.Request; | 30 import org.restlet.Request; |
27 import org.restlet.Response; | 31 import org.restlet.Response; |
28 | 32 |
29 import org.w3c.dom.Document; | 33 import org.w3c.dom.Document; |
34 import org.w3c.dom.Node; | |
30 | 35 |
31 | 36 |
32 /** | 37 /** |
33 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a> | 38 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a> |
34 */ | 39 */ |
140 } | 145 } |
141 else if (action.equals(ACTION_SET_ATTRIBUTE)) { | 146 else if (action.equals(ACTION_SET_ATTRIBUTE)) { |
142 String art = getArtifactIdentifier(source); | 147 String art = getArtifactIdentifier(source); |
143 | 148 |
144 logger.info("Set attribute for collection '" + identifier + "'"); | 149 logger.info("Set attribute for collection '" + identifier + "'"); |
145 out = db.setCollectionAttribute(identifier, meta, source); | 150 |
151 Document attr = getCollectionAttribute(source); | |
152 | |
153 out = db.setCollectionAttribute(identifier, meta, attr); | |
146 } | 154 } |
147 else if (action.equals(ACTION_SET_ITEM_ATTRIBUTE)) { | 155 else if (action.equals(ACTION_SET_ITEM_ATTRIBUTE)) { |
148 String art = getArtifactIdentifier(source); | 156 String art = getArtifactIdentifier(source); |
149 | 157 |
150 logger.info("Set attribute for artifact '" + art + "'"); | 158 logger.info("Set attribute for artifact '" + art + "'"); |
224 */ | 232 */ |
225 protected String getArtifactIdentifier(Document source) { | 233 protected String getArtifactIdentifier(Document source) { |
226 return XMLUtils.xpathString( | 234 return XMLUtils.xpathString( |
227 source, XPATH_ARTIFACT, ArtifactNamespaceContext.INSTANCE); | 235 source, XPATH_ARTIFACT, ArtifactNamespaceContext.INSTANCE); |
228 } | 236 } |
237 | |
238 | |
239 /** | |
240 * Returns the attribute for a collection of the incoming request document. | |
241 * | |
242 * @param request The request document. | |
243 * | |
244 * @return the contained attribute as document. | |
245 */ | |
246 protected Document getCollectionAttribute(Document request) { | |
247 Node attr = (Node) XMLUtils.xpath( | |
248 request, | |
249 ArtifactDatabaseImpl.XPATH_COLLECTION_ATTRIBUTE, | |
250 XPathConstants.NODE, | |
251 ArtifactNamespaceContext.INSTANCE); | |
252 | |
253 Document newAttr = XMLUtils.newDocument(); | |
254 | |
255 if (attr == null) { | |
256 logger.error("Collection attribute document not found!"); | |
257 return newAttr; | |
258 } | |
259 | |
260 newAttr.appendChild(newAttr.importNode(attr, true)); | |
261 | |
262 return newAttr; | |
263 } | |
229 } | 264 } |