Mercurial > dive4elements > gnv-client
annotate gnv/src/main/java/de/intevation/gnv/action/StoreAction.java @ 963:0441e78cd900
Add more Javadocs
gnv/trunk@1107 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 18 May 2010 11:09:33 +0000 |
parents | af22fa5567a6 |
children | 33198e55371c |
rev | line source |
---|---|
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.action; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.io.OutputStream; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import javax.servlet.http.HttpServletRequest; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import javax.servlet.http.HttpServletResponse; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.apache.struts.action.ActionForm; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.apache.struts.action.ActionForward; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.apache.struts.action.ActionMapping; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
963 | 13 import de.intevation.gnv.action.sessionmodel.SessionModel; |
14 import de.intevation.gnv.action.sessionmodel.SessionModelFactory; | |
15 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; | |
16 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; | |
17 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; | |
18 | |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 /** |
690
254f062e334b
Added JavaDoc.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
684
diff
changeset
|
20 * This controller is used to save the current artifact to an xml file. A file |
254f062e334b
Added JavaDoc.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
684
diff
changeset
|
21 * dialog is opened to save the file to the local disk. |
699
af22fa5567a6
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
690
diff
changeset
|
22 * |
684
57fa8019fbdc
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 */ |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public class StoreAction extends ArtifactDatabaseActionBase { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 public static final String RESOURCE_DOWNLOAD_FAILURE = "no.artifact.chosen"; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
963 | 29 /** |
30 * the logger, used to log exceptions and additonaly information | |
31 */ | |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 private static Logger logger = Logger.getLogger(StoreAction.class); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
963 | 34 /** |
35 * Constructor | |
36 */ | |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 public StoreAction() { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 super(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
963 | 41 @Override |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public ActionForward execute( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 ActionMapping mapping, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 ActionForm form, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 HttpServletRequest request, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 HttpServletResponse response) |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 throws Exception |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 SessionModelFactory sf = SessionModelFactory.getInstance(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 SessionModel sm = sf.getSessionModel(request); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 ArtifactDatabaseClientFactory adcf = |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 ArtifactDatabaseClientFactory.getInstance(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 ArtifactDatabaseClient adc = |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 adcf.getArtifactDatabaseClient(getLocale(request)); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 ArtifactObject artifact = sm.getCurrentArtifact(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 // no artifact set at the moment (which means, the user didn't select a |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 // fis yet. |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 if (artifact == null) { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 logger.warn("No artifact/fis selected yet."); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 request.setAttribute( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 CommunicationKeys.REQUEST_EXCEPTION_PROJECT, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 RESOURCE_DOWNLOAD_FAILURE); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 return super.execute(mapping, form, request, response); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 logger.info("Export artifact " + artifact.getId()); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 setHeaders(response, artifact.getId()); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 OutputStream out = response.getOutputStream(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 adc.doExport( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 sm.getSelectedArtifactFactory(), |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 artifact, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 out); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 out.flush(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 out.close(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 return null; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 } |
963 | 84 |
85 /** | |
86 * Sets the header of the response. | |
87 * @param response the response | |
88 * @param uuid the uuid of the artifact | |
89 */ | |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 protected void setHeaders(HttpServletResponse response, String uuid) { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 String filename = "GNVArtefakt_" + uuid + ".xml"; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 response.setHeader("Content-Type", "application/xml"); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 response.setHeader( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 "Content-Disposition", |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 "attachment;filename=" + filename); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |