Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/ImportResource.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/ImportResource.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 java.io.IOException; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 import org.restlet.Request; | |
19 import org.restlet.Response; | |
20 | |
21 import org.restlet.data.MediaType; | |
22 import org.restlet.data.Status; | |
23 | |
24 import org.restlet.ext.xml.DomRepresentation; | |
25 | |
26 import org.restlet.representation.EmptyRepresentation; | |
27 import org.restlet.representation.Representation; | |
28 | |
29 import org.w3c.dom.Document; | |
30 | |
31 /** | |
32 * Resource to import an XML document containg an artifact produced by | |
33 * the ExportResource. | |
34 * | |
35 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> | |
36 */ | |
37 public class ImportResource | |
38 extends BaseResource | |
39 { | |
40 private static Logger logger = Logger.getLogger(ImportResource.class); | |
41 | |
42 /** | |
43 * server URL where to reach the resource. | |
44 */ | |
45 public static final String PATH = "/import"; | |
46 | |
47 @Override | |
48 protected Representation innerPost(Representation requestRepr) { | |
49 | |
50 Document inputDocument = null; | |
51 try { | |
52 DomRepresentation input = new DomRepresentation(requestRepr); | |
53 input.setNamespaceAware(true); | |
54 inputDocument = input.getDocument(); | |
55 } | |
56 catch (IOException ioe) { | |
57 logger.error(ioe.getMessage()); | |
58 Response response = getResponse(); | |
59 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); | |
60 return new EmptyRepresentation(); | |
61 } | |
62 | |
63 Request request = getRequest(); | |
64 | |
65 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
66 .getAttributes().get("database"); | |
67 | |
68 try { | |
69 return new DomRepresentation( | |
70 MediaType.APPLICATION_XML, | |
71 db.importArtifact(inputDocument, getCallMeta())); | |
72 } | |
73 catch (ArtifactDatabaseException adbe) { | |
74 logger.warn(adbe.getLocalizedMessage(), adbe); | |
75 Response response = getResponse(); | |
76 response.setStatus( | |
77 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage()); | |
78 return new EmptyRepresentation(); | |
79 } | |
80 } | |
81 } | |
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |