Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ImportResource.java @ 80:8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
artifacts/trunk@799 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 19 Mar 2010 09:34:40 +0000 |
parents | |
children | 69c84cf7c5d7 |
comparison
equal
deleted
inserted
replaced
79:f69e5b87f05f | 80:8447467cef86 |
---|---|
1 package de.intevation.artifactdatabase.rest; | |
2 | |
3 import de.intevation.artifacts.ArtifactDatabase; | |
4 import de.intevation.artifacts.ArtifactDatabaseException; | |
5 | |
6 import java.io.IOException; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import org.restlet.data.MediaType; | |
11 import org.restlet.data.Request; | |
12 import org.restlet.data.Response; | |
13 import org.restlet.data.Status; | |
14 | |
15 import org.restlet.ext.xml.DomRepresentation; | |
16 | |
17 import org.restlet.representation.EmptyRepresentation; | |
18 import org.restlet.representation.Representation; | |
19 | |
20 import org.w3c.dom.Document; | |
21 | |
22 /** | |
23 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> | |
24 */ | |
25 public class ImportResource | |
26 extends BaseResource | |
27 { | |
28 private static Logger logger = Logger.getLogger(ImportResource.class); | |
29 | |
30 public static final String PATH = "/import"; | |
31 | |
32 protected Representation innerPost(Representation requestRepr) { | |
33 | |
34 Document inputDocument = null; | |
35 try { | |
36 DomRepresentation input = new DomRepresentation(requestRepr); | |
37 input.setNamespaceAware(true); | |
38 inputDocument = input.getDocument(); | |
39 } | |
40 catch (IOException ioe) { | |
41 logger.error(ioe.getMessage()); | |
42 Response response = getResponse(); | |
43 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); | |
44 return new EmptyRepresentation(); | |
45 } | |
46 | |
47 Request request = getRequest(); | |
48 | |
49 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
50 .getAttributes().get("database"); | |
51 | |
52 try { | |
53 return new DomRepresentation( | |
54 MediaType.APPLICATION_XML, | |
55 db.importArtifact(inputDocument, getCallMeta())); | |
56 } | |
57 catch (ArtifactDatabaseException adbe) { | |
58 logger.warn(adbe.getLocalizedMessage(), adbe); | |
59 Response response = getResponse(); | |
60 response.setStatus( | |
61 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage()); | |
62 return new EmptyRepresentation(); | |
63 } | |
64 } | |
65 } | |
66 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |