annotate gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java @ 36:ad381cc47217

Format Code to max 80 Chars per Row gnv/trunk@172 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 08:54:13 +0000
parents 4405f31bbc30
children fccf90761825
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>
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
30 *
13
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);
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
38
29
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 /**
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
47 * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
48 * org.apache.struts.action.ActionForm,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
49 * javax.servlet.http.HttpServletRequest,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
50 * javax.servlet.http.HttpServletResponse)
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 */
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 @Override
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
53 public ActionForward execute(ActionMapping mapping, ActionForm form,
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54 HttpServletRequest request, HttpServletResponse response)
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 throws Exception {
29
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
56 log.debug("DoOutputAction.execute");
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
57 try {
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
58 String target = request.getParameter("target");
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
59 String mimeType = request.getParameter("mimetype");
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
60
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
61 log.debug("Target: " + target);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
62 log.debug("MimeType: " + mimeType);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
63
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
64 // TODO Check if is propper;
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
65
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
66 SessionModel sm = SessionModelFactory.getInstance()
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
67 .getSessionModel(request);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
68 OutputMode outputMode = sm.getOutputMode(target);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
69 if (outputMode != null && outputMode.getMimeType().equals(mimeType)) {
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
70 Collection<OutputParameter> inputParameter = outputMode
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
71 .getOutputParameters();
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
72 Collection<InputParameter> ips = null;
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
73 if (inputParameter != null) {
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
74 ips = new ArrayList<InputParameter>(inputParameter.size());
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
75 Iterator<OutputParameter> it = inputParameter.iterator();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
76 while (it.hasNext()) {
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
77 String name = it.next().getName();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
78 String[] values = request.getParameterValues(name);
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
79 InputParameter ip = new DefaultInputParameter(name,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
80 values);
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
81 ips.add(ip);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
82 }
30
07e9c137a2f1 Added dynamic Outputparameter Support and Outputparameter-manipulation
Tim Englich <tim.englich@intevation.de>
parents: 29
diff changeset
83 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
84
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
85 ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
86 .getInstance().getArtifactDatabaseClient();
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
87
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
88 this.setHeaders(target, mimeType, response, request);
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
89
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
90 OutputStream outputStream = response.getOutputStream();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
91 adc.doOutput(sm.getSelectedArtifactFactory(), sm
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
92 .getCurrentArtifact(), outputStream, target, mimeType,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
93 ips);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
94
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
95 outputStream.flush();
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
96 outputStream.close();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
97 } else {
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
98 if (outputMode == null) {
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
99 log.error("Outputmode wird nicht unterst�tzt.");
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
100 } else if (!outputMode.getMimeType().equals(mimeType)) {
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
101 log.error("MimeType " + mimeType
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
102 + " wird nicht unterst�tzt.");
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
103 }
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
104 // TODO FIXME: Fehlerbehandlung
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
105 }
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
106 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
107 } catch (Exception e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
108 log.error(e, e);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
109 request.setAttribute(
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
110 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
111 .getMessage());
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 30
diff changeset
112 return super.getExceptionForward(mapping);
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
113 }
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
114 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
115
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
116 protected void setHeaders(String target, String mimeType,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
117 HttpServletResponse response, HttpServletRequest request) {
29
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
118 response.setHeader("Content-Type", mimeType);
bba8fd97e549 Export and Diagrammoptions integrated into GUI
Tim Englich <tim.englich@intevation.de>
parents: 13
diff changeset
119 }
13
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
120
2535158e2687 Chartoutput Added to the View
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
121 }

http://dive4elements.wald.intevation.org