comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ExportResource.java @ 79:f69e5b87f05f

Implementation to export artifacts as xml (applied patch from issue208 by SLT). artifacts/trunk@792 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 16 Mar 2010 16:03:06 +0000
parents
children 69c84cf7c5d7
comparison
equal deleted inserted replaced
78:55eefe63a777 79:f69e5b87f05f
1 package de.intevation.artifactdatabase.rest;
2
3 import de.intevation.artifacts.ArtifactDatabase;
4 import de.intevation.artifacts.ArtifactDatabaseException;
5
6 import org.apache.log4j.Logger;
7
8 import org.restlet.data.MediaType;
9 import org.restlet.data.Request;
10 import org.restlet.data.Response;
11 import org.restlet.data.Status;
12
13 import org.restlet.ext.xml.DomRepresentation;
14
15 import org.restlet.representation.EmptyRepresentation;
16 import org.restlet.representation.Representation;
17
18 import org.restlet.resource.ResourceException;
19
20 /**
21 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
22 */
23 public class ExportResource
24 extends BaseResource
25 {
26 private static Logger logger = Logger.getLogger(ExportResource.class);
27
28 public static final String PATH = "/export/{uuid}";
29
30 protected Representation innerGet()
31 throws ResourceException
32 {
33 Request request = getRequest();
34
35 String identifier = (String)request.getAttributes().get("uuid");
36
37 if (logger.isDebugEnabled()) {
38 logger.debug("looking for artifact id '" + identifier + "'");
39 }
40
41 ArtifactDatabase db = (ArtifactDatabase)getContext()
42 .getAttributes().get("database");
43
44 try {
45 return new DomRepresentation(
46 MediaType.APPLICATION_XML,
47 db.exportArtifact(identifier, getCallMeta()));
48 }
49 catch (ArtifactDatabaseException adbe) {
50 logger.warn(adbe.getLocalizedMessage(), adbe);
51 Response response = getResponse();
52 response.setStatus(
53 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage());
54 return new EmptyRepresentation();
55 }
56 }
57 }
58 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org