1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.event.classic;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.*;
30
31 import org.dbforms.event.AbstractNavigationEvent;
32 import org.dbforms.interfaces.DbEventInterceptorData;
33
34 import org.dbforms.util.*;
35
36 import java.io.UnsupportedEncodingException;
37
38 import java.sql.*;
39
40 import javax.servlet.http.*;
41
42
43
44 /***
45 * DOCUMENT ME!
46 *
47 * @author Joe Peer
48 *
49 * @deprecated This event forces the controller to forward the current request
50 * to a Request-Dispatcher specified by the Application-Developer
51 * in a "org.dbforms.taglib.DbGotoButton".
52 */
53 public class GotoEvent extends AbstractNavigationEvent {
54
55 static Log logCat = LogFactory.getLog(GotoEvent.class.getName());
56 private String childField;
57 private String parentField;
58
59
60 private String position;
61 private String tableList = null;
62 private String whereClause = null;
63 private Table srcTable;
64
65 /***
66 * <p>
67 * constructor - parses the event details
68 * </p>
69 *
70 * <p>
71 * Depending on the way the attributes where provided by the developer,
72 * different ways are used for resolving the dispatcher the user wants to
73 * get called and the position he wants the ResultSet to be scrolled to.
74 * </p>
75 *
76 * @param action DOCUMENT ME!
77 * @param request DOCUMENT ME!
78 * @param config DOCUMENT ME!
79 */
80 public GotoEvent(String action,
81 HttpServletRequest request,
82 DbFormsConfig config) {
83 super(action, request, config);
84
85 String destTable = ParseUtil.getParameter(request,
86 "data" + action + "_destTable");
87
88 if (destTable == null) {
89 setTable(null);
90
91 return;
92 }
93
94
95 setTable(config.getTableByName(destTable));
96
97 if (getTable() == null) {
98 setTable(config.getTable(Integer.parseInt(destTable)));
99 }
100
101 String psrcTable = ParseUtil.getParameter(request,
102 "data" + action + "_srcTable");
103
104 if (psrcTable != null) {
105 this.srcTable = config.getTableByName(psrcTable);
106
107 if (this.srcTable == null) {
108 this.srcTable = config.getTable(Integer.parseInt(psrcTable));
109 }
110
111 childField = ParseUtil.getParameter(request,
112 "data" + action + "_childField");
113 parentField = ParseUtil.getParameter(request,
114 "data" + action + "_parentField");
115 }
116
117
118
119 String destPos = ParseUtil.getParameter(request,
120 "data" + action + "_destPos");
121
122
123 if (destPos != null) {
124 this.position = destPos;
125 } else {
126 String keyToDestPos = ParseUtil.getParameter(request,
127 "data" + action
128 + "_keyToDestPos");
129
130
131 if (keyToDestPos != null) {
132 this.position = ParseUtil.getParameter(request, keyToDestPos);
133 } else {
134 String keyToKeyToDestPos = ParseUtil.getParameter(request,
135 "data" + action
136 + "_keyToKeyToDestPos");
137
138
139
140 if (keyToKeyToDestPos != null) {
141 String widgetValue = ParseUtil.getParameter(request,
142 keyToKeyToDestPos);
143
144 this.position = ParseUtil.getParameter(request,
145 "k_" + widgetValue);
146 }
147 }
148 }
149
150 logCat.info("--->pos=" + position);
151 }
152
153
154 /***
155 * this constructer is not called by the controller but, actually, BY THE
156 * VIEW for example if the FormTag "gotoPrefix" attribute is set an a
157 * GotoEvent needs to be instanciated
158 *
159 * @param table DOCUMENT ME!
160 * @param request DOCUMENT ME!
161 * @param config DOCUMENT ME!
162 * @param position DOCUMENT ME!
163 */
164 public GotoEvent(Table table,
165 HttpServletRequest request,
166 DbFormsConfig config,
167 String position) {
168 super(table, request, config);
169 this.position = position;
170
171 try {
172 this.position = Util.encode(this.position, getRequest().getCharacterEncoding());
173 } catch (UnsupportedEncodingException e) {
174 logCat.error(e);
175 }
176 }
177
178
179 /***
180 * this constructer is not called by the controller but, actually, BY THE
181 * VIEW for example if the FormTag needs a free form select, this
182 * constructor is called
183 *
184 * @param table DOCUMENT ME!
185 * @param request DOCUMENT ME!
186 * @param config DOCUMENT ME!
187 * @param whereClause DOCUMENT ME!
188 * @param tableList DOCUMENT ME!
189 */
190 public GotoEvent(Table table,
191 HttpServletRequest request,
192 DbFormsConfig config,
193 String whereClause,
194 String tableList) {
195 super(table, request, config);
196 this.whereClause = whereClause;
197 this.tableList = tableList;
198 }
199
200 /***
201 * Process the current event.
202 *
203 * @param childFieldValues FieldValue array used to restrict a set of data
204 * @param orderConstraint FieldValue array used to build a cumulation of
205 * rules for ordering (sorting) and restricting fields to the actual
206 * block of data
207 * @param firstPosition DOCUMENT ME!
208 * @param sqlFilterParams a string identifying the last resultset position
209 * @param count record count
210 * @param firstPosition a string identifying the first resultset position
211 * @param lastPosition DOCUMENT ME!
212 * @param dbConnectionName name of the used db connection. Can be used to
213 * get an own db connection, e.g. to hold it during the session (see
214 * DataSourceJDBC for example!)
215 * @param con the JDBC Connection object
216 *
217 * @return a ResultSetVector object
218 *
219 * @exception SQLException if any error occurs
220 */
221 public ResultSetVector processEvent(FieldValue[] childFieldValues,
222 FieldValue[] orderConstraint,
223 String sqlFilter,
224 FieldValue[] sqlFilterParams,
225 int count,
226 String firstPosition,
227 String lastPosition,
228 DbEventInterceptorData interceptorData)
229 throws SQLException {
230 if (Util.isNull(whereClause)) {
231 try {
232 position = Util.decode(position, getRequest().getCharacterEncoding());
233 } catch (UnsupportedEncodingException e) {
234 logCat.error(e);
235 throw new SQLException(e.getMessage());
236 }
237
238
239 int compMode = (!Util.isNull(position)) ? Constants.COMPARE_INCLUSIVE
240 : Constants.COMPARE_NONE;
241
242 if (!Util.isNull(position)
243 && (srcTable != null)
244 && !Util.isNull(childField)
245 && !Util.isNull(parentField)) {
246 FieldValues fv = getTable()
247 .mapChildFieldValues(srcTable, parentField,
248 childField, position);
249
250 if (fv != null) {
251 childFieldValues = fv.toArray();
252 compMode = Constants.COMPARE_NONE;
253 }
254 } else if (!Util.isNull(position)) {
255 getTable()
256 .fillWithValues(orderConstraint, position);
257 }
258
259 logCat.info("gotopos = " + position);
260
261 return getTable()
262 .doConstrainedSelect(childFieldValues, orderConstraint,
263 sqlFilter, sqlFilterParams, compMode,
264 count, interceptorData);
265 } else {
266
267 return getTable()
268 .doFreeFormSelect(whereClause,
269 tableList, count, interceptorData);
270 }
271 }
272 }