annotate gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java @ 35:4405f31bbc30

CodeCleanUP gnv/trunk@171 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 08:49:18 +0000
parents 25fdec8b4c69
children ad381cc47217
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.DefaultInputParameter;
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 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
25 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
26 import de.intevation.gnv.artifactdatabase.objects.OutputParameter;
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27
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 * @author Tim Englich <tim.englich@intevation.de>
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
30 *
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 public class DoOutputAction extends ArtifactDatabaseActionBase {
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
34 /**
29
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
35 * 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
36 */
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
37 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
38 /**
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 * Constructor
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
40 */
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 public DoOutputAction() {
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42 super();
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43 }
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 * @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
48 */
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49 @Override
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50 public ActionForward execute(ActionMapping mapping, ActionForm form,
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 HttpServletRequest request, HttpServletResponse response)
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 throws Exception {
29
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
53 log.debug("DoOutputAction.execute");
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
54 try {
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
55 String target = request.getParameter("target");
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
56 String mimeType = request.getParameter("mimetype");
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
57
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
58 log.debug("Target: "+target);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
59 log.debug("MimeType: "+mimeType);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
60
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
61 // TODO Check if is propper;
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
62
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
63 SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
64 OutputMode outputMode = sm.getOutputMode(target);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
65 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
66 Collection<OutputParameter> inputParameter =outputMode.getOutputParameters();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
67 Collection<InputParameter> ips = null;
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
68 if (inputParameter != null){
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
69 ips = new ArrayList<InputParameter>(inputParameter.size());
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
70 Iterator<OutputParameter> it = inputParameter.iterator();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
71 while (it.hasNext()){
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
72 String name = it.next().getName();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
73 String[] values = request.getParameterValues(name);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
74 InputParameter ip = new DefaultInputParameter(name, values);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
75 ips.add(ip);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
76 }
30
07e9c137a2f1 Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents: 29
diff changeset
77 }
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
78
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
79 ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
80
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
81 this.setHeaders(target, mimeType, response, request);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
82
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
83 OutputStream outputStream = response.getOutputStream();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
84 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
85
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
86 outputStream.flush();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
87 outputStream.close();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
88 }else{
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
89 if (outputMode == null){
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
90 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
91 }else if (!outputMode.getMimeType().equals(mimeType)){
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
92 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
93 }
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
94 // TODO FIXME: Fehlerbehandlung
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
95 }
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
96 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
97 } catch (Exception e) {
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
98 log.error(e,e);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
99 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
100 return super.getExceptionForward(mapping);
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
101 }
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
29
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
104 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
105 response.setHeader("Content-Type", mimeType);
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
106 }
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
107
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
108
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
109 }

http://dive4elements.wald.intevation.org