comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/ExportResource.java @ 473:d0ac790a6c89 dive4elements-move

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 10:57:18 +0200
parents artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ExportResource.java@7fc0650f194c
children 415df0fc4fa1
comparison
equal deleted inserted replaced
472:783cc1b6b615 473:d0ac790a6c89
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.artifactdatabase.rest;
10
11 import de.intevation.artifacts.ArtifactDatabase;
12 import de.intevation.artifacts.ArtifactDatabaseException;
13
14 import org.apache.log4j.Logger;
15
16 import org.restlet.Request;
17 import org.restlet.Response;
18
19 import org.restlet.data.MediaType;
20 import org.restlet.data.Status;
21
22 import org.restlet.ext.xml.DomRepresentation;
23
24 import org.restlet.representation.EmptyRepresentation;
25 import org.restlet.representation.Representation;
26
27 import org.restlet.resource.ResourceException;
28
29 /**
30 * Resource to produce an external XML representation of a given
31 * artifact to be import by ImportResource later on.
32 *
33 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
34 */
35 public class ExportResource
36 extends BaseResource
37 {
38 private static Logger logger = Logger.getLogger(ExportResource.class);
39
40 /**
41 * server URL where to reach the resource.
42 */
43 public static final String PATH = "/export/{uuid}";
44
45 @Override
46 protected Representation innerGet()
47 throws ResourceException
48 {
49 Request request = getRequest();
50
51 String identifier = (String)request.getAttributes().get("uuid");
52
53 if (logger.isDebugEnabled()) {
54 logger.debug("looking for artifact id '" + identifier + "'");
55 }
56
57 ArtifactDatabase db = (ArtifactDatabase)getContext()
58 .getAttributes().get("database");
59
60 try {
61 return new DomRepresentation(
62 MediaType.APPLICATION_XML,
63 db.exportArtifact(identifier, getCallMeta()));
64 }
65 catch (ArtifactDatabaseException adbe) {
66 logger.warn(adbe.getLocalizedMessage(), adbe);
67 Response response = getResponse();
68 response.setStatus(
69 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage());
70 return new EmptyRepresentation();
71 }
72 }
73 }
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org