comparison gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java @ 409:df78178e1180

Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this. gnv/trunk@599 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 22 Jan 2010 11:28:25 +0000
parents b5733f9f386b
children 27f25b9ae9af
comparison
equal deleted inserted replaced
408:b5733f9f386b 409:df78178e1180
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.intevation.gnv.action; 4 package de.intevation.gnv.action;
5 import de.intevation.gnv.action.sessionmodel.SessionModel;
6 import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
7
8 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
9 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
10
11 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
12 import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter;
13 import de.intevation.gnv.artifactdatabase.objects.InputParameter;
5 14
6 import java.util.ArrayList; 15 import java.util.ArrayList;
7 import java.util.Collection; 16 import java.util.Collection;
8 import java.util.Iterator; 17 import java.util.Iterator;
9 import java.util.Map; 18 import java.util.Map;
10 19
11 import javax.servlet.http.HttpServletRequest; 20 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse; 21 import javax.servlet.http.HttpServletResponse;
13 22
14 import org.apache.log4j.Logger; 23 import org.apache.log4j.Logger;
24
15 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionForm;
16 import org.apache.struts.action.ActionForward; 26 import org.apache.struts.action.ActionForward;
17 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionMapping;
18 import org.w3c.dom.Node;
19 28
20 import de.intevation.gnv.action.sessionmodel.SessionModel;
21 import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
22 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
23 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
24 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
25 import de.intevation.gnv.artifactdatabase.objects.ArtifactStatisticsSet;
26 import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter;
27 import de.intevation.gnv.artifactdatabase.objects.InputParameter;
28 import de.intevation.gnv.util.XMLUtils;
29 import de.intevation.gnv.util.XSLTransformer;
30 29
31 /** 30 /**
32 * @author Tim Englich <tim.englich@intevation.de> 31 * @author Tim Englich <tim.englich@intevation.de>
32 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
33 * 33 *
34 */ 34 */
35 public class NextArtifactStepAction extends ArtifactDatabaseActionBase { 35 public class NextArtifactStepAction extends DescribeUIAction {
36 36
37 /** 37 /**
38 * the logger, used to log exceptions and additonaly information 38 * the logger, used to log exceptions and additonaly information
39 */ 39 */
40 private static Logger log = Logger 40 private static Logger log = Logger
90 // state. 90 // state.
91 } else { 91 } else {
92 target = ad.getReachableStates().iterator().next(); 92 target = ad.getReachableStates().iterator().next();
93 } 93 }
94 94
95 ArtifactDescription artifactDescription;
96 try { 95 try {
97 artifactDescription = adc.doNextStep(sm.getSelectedArtifactFactory(), 96 adc.doNextStep(
98 sm.getCurrentArtifact(), 97 sm.getSelectedArtifactFactory(),
99 target, ips); 98 sm.getCurrentArtifact(),
99 target,
100 ips
101 );
100 } catch (Exception e) { 102 } catch (Exception e) {
101 log.error(e, e); 103 log.error(e, e);
102 request.setAttribute( 104 request.setAttribute(
103 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e 105 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
104 .getMessage()); 106 .getMessage());
105 artifactDescription = sm.getArtifactDescription();
106 } 107 }
107 108
108 Node currentUI = artifactDescription.getCurrentUI();
109 if (currentUI != null){
110 XSLTransformer transformer = new XSLTransformer();
111 String url = response.encodeURL(
112 mapping.findForward("back").getPath());
113 transformer.addParameter("back-url", url);
114
115 String fisUrl = response.encodeURL(
116 mapping.findForward("selectfis").getPath());
117 transformer.addParameter("selectfis", fisUrl);
118
119 Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"art:dynamic");
120 if (dynamicUINode != null){
121 String ui = transformer.transform(
122 dynamicUINode,
123 "UTF-8",
124 request.getRealPath(XSL_SHEET_DYNAMIC));
125
126 if (ui != null && ui.length() > 1)
127 request.setAttribute("ui", ui);
128 }
129
130 Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "art:static");
131 if (staticUINode != null){
132 String staticUI = transformer.transform(
133 staticUINode,
134 "UTF-8",
135 request.getRealPath(XSL_SHEET_STATIC));
136 request.setAttribute("staticui", staticUI);
137 }
138 }
139 Map tmpOuts = ad.getOutputModes(); 109 Map tmpOuts = ad.getOutputModes();
140 request.setAttribute( 110 request.setAttribute(
141 "furthertargets", 111 "furthertargets",
142 tmpOuts == null || tmpOuts.isEmpty() 112 tmpOuts == null || tmpOuts.isEmpty()
143 ); 113 );
144 } else { 114 } else {
145 // statistic abholen und in das sessionmodell schreiben.
146 ArtifactDescription artifactDescription;
147 try{ 115 try{
148 artifactDescription = adc.getCurrentStepDescription( 116 adc.getCurrentStepDescription(
149 sm.getSelectedArtifactFactory(), 117 sm.getSelectedArtifactFactory(),
150 sm.getCurrentArtifact(), 118 sm.getCurrentArtifact(),
151 true 119 true
152 ); 120 );
153 121
154 request.setAttribute("diagramm", true); 122 request.setAttribute("diagramm", true);
155 123
156 } catch (Exception e) { 124 } catch (Exception e) {
157 log.error(e, e); 125 log.error(e, e);
158 request.setAttribute( 126 request.setAttribute(
159 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e 127 CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID,
160 .getMessage()); 128 e.getMessage());
161 artifactDescription = sm.getArtifactDescription();
162 } 129 }
163 130
164 Node currentUI = artifactDescription.getCurrentUI();
165 if (currentUI != null){
166 XSLTransformer transformer = new XSLTransformer();
167 String url = response.encodeURL(
168 mapping.findForward("back").getPath());
169 transformer.addParameter("back-url", url);
170
171 String fisUrl = response.encodeURL(
172 mapping.findForward("selectfis").getPath());
173 transformer.addParameter("selectfis", fisUrl);
174
175 Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"art:dynamic");
176 if (dynamicUINode != null){
177 String ui = transformer.transform(
178 dynamicUINode,
179 "UTF-8",
180 request.getRealPath(XSL_SHEET_DYNAMIC));
181
182 if (ui != null && ui.length() > 1)
183 request.setAttribute("ui", ui);
184 }
185
186 Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "art:static");
187 if (staticUINode != null){
188 String staticUI = transformer.transform(
189 staticUINode,
190 "UTF-8",
191 request.getRealPath(XSL_SHEET_STATIC));
192
193 request.setAttribute("staticui", staticUI);
194 }
195 }
196 request.setAttribute("furthertargets", false); 131 request.setAttribute("furthertargets", false);
197 } 132 }
198 }else{ 133 }else{
199 log.warn("SessionTimeout has occured"); 134 log.warn("SessionTimeout has occured");
200 request.setAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, 135 request.setAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID,
203 } 138 }
204 return super.execute(mapping, form, request, response); 139 return super.execute(mapping, form, request, response);
205 } 140 }
206 141
207 } 142 }
143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org