Mercurial > dive4elements > gnv-client
annotate gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java @ 34:25fdec8b4c69
Added Global Errorhandling to the GNV-Client
gnv/trunk@170 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 02 Oct 2009 08:38:57 +0000 |
parents | 07e9c137a2f1 |
children | 4405f31bbc30 |
rev | line source |
---|---|
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.action; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
6 import java.io.OutputStream; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 import java.util.ArrayList; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
8 import java.util.Collection; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 import java.util.Iterator; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 import javax.servlet.http.HttpServletRequest; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 import javax.servlet.http.HttpServletResponse; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 |
29
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
14 import org.apache.log4j.Logger; |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import org.apache.struts.action.ActionForm; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import org.apache.struts.action.ActionForward; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import org.apache.struts.action.ActionMapping; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.gnv.action.sessionmodel.SessionModel; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.gnv.action.sessionmodel.SessionModelFactory; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 import de.intevation.gnv.artifactdatabase.objects.InputParameter; |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
29
diff
changeset
|
26 import de.intevation.gnv.artifactdatabase.objects.OutputMode; |
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
29
diff
changeset
|
27 import de.intevation.gnv.artifactdatabase.objects.OutputParameter; |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 * @author Tim Englich <tim.englich@intevation.de> |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 * |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 public class DoOutputAction extends ArtifactDatabaseActionBase { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 /** |
29
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
36 * the logger, used to log exceptions and additonaly information |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
37 */ |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
38 private static Logger log = Logger.getLogger(DoOutputAction.class); |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
39 /** |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 * Constructor |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
41 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 public DoOutputAction() { |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 super(); |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 /** |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 */ |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 @Override |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 public ActionForward execute(ActionMapping mapping, ActionForm form, |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 HttpServletRequest request, HttpServletResponse response) |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 throws Exception { |
29
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
54 log.debug("DoOutputAction.execute"); |
34
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
55 try { |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
56 String target = request.getParameter("target"); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
57 String mimeType = request.getParameter("mimetype"); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
58 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
59 log.debug("Target: "+target); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
60 log.debug("MimeType: "+mimeType); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
61 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
62 // TODO Check if is propper; |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
63 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
64 SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
65 OutputMode outputMode = sm.getOutputMode(target); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
66 if (outputMode != null && outputMode.getMimeType().equals(mimeType)){ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
67 Collection<OutputParameter> inputParameter =outputMode.getOutputParameters(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
68 Collection<InputParameter> ips = null; |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
69 if (inputParameter != null){ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
70 ips = new ArrayList<InputParameter>(inputParameter.size()); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
71 Iterator<OutputParameter> it = inputParameter.iterator(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
72 while (it.hasNext()){ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
73 String name = it.next().getName(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
74 String[] values = request.getParameterValues(name); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
75 InputParameter ip = new DefaultInputParameter(name, values); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
76 ips.add(ip); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
77 } |
30
07e9c137a2f1
Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents:
29
diff
changeset
|
78 } |
34
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
79 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
80 ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
81 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
82 this.setHeaders(target, mimeType, response, request); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
83 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
84 OutputStream outputStream = response.getOutputStream(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
85 adc.doOutput(sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), outputStream, target, mimeType, ips); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
86 |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
87 outputStream.flush(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
88 outputStream.close(); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
89 }else{ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
90 if (outputMode == null){ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
91 log.error("Outputmode wird nicht unterst�tzt."); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
92 }else if (!outputMode.getMimeType().equals(mimeType)){ |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
93 log.error("MimeType "+mimeType+" wird nicht unterst�tzt."); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
94 } |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
95 // TODO FIXME: Fehlerbehandlung |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 } |
34
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
97 return super.execute(mapping, form, request, response); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
98 } catch (Exception e) { |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
99 log.error(e,e); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
100 request.setAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e.getMessage()); |
25fdec8b4c69
Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
30
diff
changeset
|
101 return super.getExceptionForward(mapping); |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
103 } |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 |
29
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
105 protected void setHeaders(String target, String mimeType, HttpServletResponse response, HttpServletRequest request){ |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
106 response.setHeader("Content-Type", mimeType); |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
107 } |
bba8fd97e549
Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents:
13
diff
changeset
|
108 |
13
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
109 |
2535158e2687
Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
110 } |