Mercurial > dive4elements > gnv-client
annotate gnv/src/main/java/de/intevation/gnv/action/StoreAction.java @ 991:33198e55371c
Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
gnv/trunk@1192 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 10 Jun 2010 15:13:08 +0000 |
parents | 0441e78cd900 |
children | 28a0628b11b0 |
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 { |
991
33198e55371c
Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
963
diff
changeset
|
49 if (isSessionExhausted(request)) { |
33198e55371c
Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
963
diff
changeset
|
50 return sessionExhaustedForward(mapping, form, request, response); |
33198e55371c
Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
963
diff
changeset
|
51 } |
33198e55371c
Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
963
diff
changeset
|
52 |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 SessionModelFactory sf = SessionModelFactory.getInstance(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 SessionModel sm = sf.getSessionModel(request); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 ArtifactDatabaseClientFactory adcf = |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 ArtifactDatabaseClientFactory.getInstance(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 ArtifactDatabaseClient adc = |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 adcf.getArtifactDatabaseClient(getLocale(request)); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 ArtifactObject artifact = sm.getCurrentArtifact(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 // 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
|
63 // fis yet. |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 if (artifact == null) { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 logger.warn("No artifact/fis selected yet."); |
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 request.setAttribute( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 CommunicationKeys.REQUEST_EXCEPTION_PROJECT, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 RESOURCE_DOWNLOAD_FAILURE); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 return super.execute(mapping, form, request, response); |
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 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 logger.info("Export artifact " + artifact.getId()); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 setHeaders(response, artifact.getId()); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 OutputStream out = response.getOutputStream(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 adc.doExport( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 sm.getSelectedArtifactFactory(), |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 artifact, |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 out); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 out.flush(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 out.close(); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 return null; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
963 | 88 |
89 /** | |
90 * Sets the header of the response. | |
91 * @param response the response | |
92 * @param uuid the uuid of the artifact | |
93 */ | |
670
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 protected void setHeaders(HttpServletResponse response, String uuid) { |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 String filename = "GNVArtefakt_" + uuid + ".xml"; |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 response.setHeader("Content-Type", "application/xml"); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 response.setHeader( |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 "Content-Disposition", |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 "attachment;filename=" + filename); |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 } |
b89b31293772
Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |