Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java @ 27:75bdaf900473
Added REST handler for 'describe'.
artifacts/trunk@64 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Sep 2009 14:21:58 +0000 |
parents | |
children | 019b9f02d523 |
comparison
equal
deleted
inserted
replaced
26:83a059c204f8 | 27:75bdaf900473 |
---|---|
1 package de.intevation.artifactdatabase.rest; | |
2 | |
3 import org.restlet.resource.Get; | |
4 import org.restlet.resource.Post; | |
5 import org.restlet.resource.ServerResource; | |
6 | |
7 import org.restlet.representation.Representation; | |
8 import org.restlet.representation.EmptyRepresentation; | |
9 | |
10 import org.restlet.ext.xml.DomRepresentation; | |
11 | |
12 import de.intevation.artifacts.ArtifactDatabase; | |
13 import de.intevation.artifacts.Artifact; | |
14 | |
15 import org.restlet.data.Request; | |
16 import org.restlet.data.Response; | |
17 import org.restlet.data.Status; | |
18 | |
19 import org.restlet.data.MediaType; | |
20 | |
21 import org.apache.log4j.Logger; | |
22 | |
23 import org.w3c.dom.Document; | |
24 | |
25 /** | |
26 * @author Sascha L. Teichmann (sascha.teichmann@intevation) | |
27 */ | |
28 public class ArtifactResource | |
29 extends ServerResource | |
30 { | |
31 private static Logger logger = Logger.getLogger(ArtifactResource.class); | |
32 | |
33 public static final String PATH = "/artifact/{uuid}"; | |
34 | |
35 public static final String NO_ARTIFACT_FOUND = "Artifact not found"; | |
36 | |
37 @Get | |
38 public Representation represent() { | |
39 | |
40 Request request = getRequest(); | |
41 | |
42 String identifier = (String)request.getAttributes().get("uuid"); | |
43 | |
44 if (logger.isDebugEnabled()) { | |
45 logger.debug("looking for artifact id '" + identifier + "'"); | |
46 } | |
47 | |
48 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
49 .getAttributes().get("database"); | |
50 | |
51 Artifact artifact = db.getArtifact(identifier); | |
52 | |
53 if (artifact == null) { | |
54 Response response = getResponse(); | |
55 response.setStatus(Status.CLIENT_ERROR_NOT_FOUND, NO_ARTIFACT_FOUND); | |
56 return new EmptyRepresentation(); | |
57 } | |
58 | |
59 Document description = artifact.describe(db.getArtifactContext()); | |
60 | |
61 if (logger.isDebugEnabled()) { | |
62 logger.debug("out document: " + description); | |
63 } | |
64 | |
65 return new DomRepresentation( | |
66 MediaType.APPLICATION_XML, description); | |
67 } | |
68 | |
69 /* | |
70 @Post | |
71 public Representation representPost() { | |
72 return new EmptyRepresentation(); | |
73 } | |
74 */ | |
75 } | |
76 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |