1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.tapestry.event; |
15 | |
|
16 | |
import org.apache.hivemind.ApplicationRuntimeException; |
17 | |
import org.apache.hivemind.util.Defense; |
18 | |
import org.apache.tapestry.IRequestCycle; |
19 | |
import org.apache.tapestry.json.JSONArray; |
20 | |
|
21 | |
import java.text.ParseException; |
22 | |
import java.util.Arrays; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class BrowserEvent |
31 | |
{ |
32 | |
public static final String NAME = "beventname"; |
33 | |
public static final String TYPE = "beventtype"; |
34 | |
public static final String KEYS = "beventkeys"; |
35 | |
public static final String CHAR_CODE = "beventcharCode"; |
36 | |
public static final String PAGE_X = "beventpageX"; |
37 | |
public static final String PAGE_Y = "beventpageY"; |
38 | |
public static final String LAYER_X = "beventlayerX"; |
39 | |
public static final String LAYER_Y = "beventlayerY"; |
40 | |
|
41 | |
public static final String TARGET = "beventtarget"; |
42 | |
public static final String TARGET_ATTR_ID = "id"; |
43 | |
public static final String COMPONENT_ID = "bcomponentid"; |
44 | |
public static final String COMPONENT_ID_PATH = "bcomponentidpath"; |
45 | |
|
46 | |
public static final String METHOD_ARGUMENTS = "methodArguments"; |
47 | |
|
48 | |
private String _name; |
49 | |
private String _type; |
50 | |
private String[] _keys; |
51 | |
private String _charCode; |
52 | |
private String _pageX; |
53 | |
private String _pageY; |
54 | |
private String _layerX; |
55 | |
private String _layerY; |
56 | |
private EventTarget _target; |
57 | |
private String _componentId; |
58 | |
private String _componentIdPath; |
59 | |
|
60 | |
private String _methodArguments; |
61 | |
private JSONArray _methodArgumentsArray; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public BrowserEvent(IRequestCycle cycle) |
71 | 0 | { |
72 | 0 | Defense.notNull(cycle, "cycle"); |
73 | |
|
74 | 0 | _name = cycle.getParameter(NAME); |
75 | 0 | _type = cycle.getParameter(TYPE); |
76 | 0 | _keys = cycle.getParameters(KEYS); |
77 | 0 | _charCode = cycle.getParameter(CHAR_CODE); |
78 | 0 | _pageX = cycle.getParameter(PAGE_X); |
79 | 0 | _pageY = cycle.getParameter(PAGE_Y); |
80 | 0 | _layerX = cycle.getParameter(LAYER_X); |
81 | 0 | _layerY = cycle.getParameter(LAYER_Y); |
82 | 0 | _componentId = cycle.getParameter(COMPONENT_ID); |
83 | 0 | _componentIdPath = cycle.getParameter(COMPONENT_ID_PATH); |
84 | |
|
85 | 0 | Map props = new HashMap(); |
86 | 0 | _target = new EventTarget(props); |
87 | |
|
88 | 0 | String targetId = cycle.getParameter(TARGET + "." + TARGET_ATTR_ID); |
89 | 0 | if (targetId != null) |
90 | |
{ |
91 | 0 | props.put(TARGET_ATTR_ID, targetId); |
92 | |
} |
93 | |
|
94 | 0 | _methodArguments = cycle.getParameter(METHOD_ARGUMENTS); |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public BrowserEvent(String name, EventTarget target) |
105 | |
{ |
106 | 0 | this(name, null, null, target); |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public BrowserEvent(String name, String componentId, String componentIdPath, EventTarget target) |
121 | 0 | { |
122 | 0 | _name = name; |
123 | 0 | _target = target; |
124 | 0 | _componentId = componentId; |
125 | 0 | _componentIdPath = componentIdPath; |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public String getName() |
137 | |
{ |
138 | 0 | return _name; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public EventTarget getTarget() |
147 | |
{ |
148 | 0 | return _target; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public String getComponentId() |
159 | |
{ |
160 | 0 | return _componentId; |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
public String getComponentIdPath() |
170 | |
{ |
171 | 0 | return _componentIdPath; |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public String getCharCode() |
178 | |
{ |
179 | 0 | return _charCode; |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public String[] getKeys() |
186 | |
{ |
187 | 0 | return _keys; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public String getLayerX() |
194 | |
{ |
195 | 0 | return _layerX; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public String getLayerY() |
202 | |
{ |
203 | 0 | return _layerY; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public String getPageX() |
210 | |
{ |
211 | 0 | return _pageX; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public String getPageY() |
218 | |
{ |
219 | 0 | return _pageY; |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public String getType() |
226 | |
{ |
227 | 0 | return _type; |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
public JSONArray getMethodArguments() |
239 | |
{ |
240 | 0 | if ( _methodArgumentsArray == null) |
241 | |
{ |
242 | |
try |
243 | |
{ |
244 | 0 | _methodArgumentsArray = _methodArguments != null |
245 | |
? new JSONArray( _methodArguments ) |
246 | |
: new JSONArray(); |
247 | |
} |
248 | 0 | catch (ParseException ex) |
249 | |
{ |
250 | 0 | throw new ApplicationRuntimeException(ex); |
251 | 0 | } |
252 | |
} |
253 | |
|
254 | 0 | return _methodArgumentsArray; |
255 | |
} |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
public static boolean hasBrowserEvent(IRequestCycle cycle) |
266 | |
{ |
267 | 0 | Defense.notNull(cycle, "cycle"); |
268 | |
|
269 | 0 | return cycle.getParameter(NAME) != null; |
270 | |
} |
271 | |
|
272 | |
public String toString() |
273 | |
{ |
274 | 0 | return "BrowserEvent[" + |
275 | |
"_name='" + _name + '\'' + |
276 | |
'\n' + |
277 | |
", _type='" + _type + '\'' + |
278 | |
'\n' + |
279 | |
", _keys=" + (_keys == null ? null : Arrays.asList(_keys)) + |
280 | |
'\n' + |
281 | |
", _charCode='" + _charCode + '\'' + |
282 | |
'\n' + |
283 | |
", _pageX='" + _pageX + '\'' + |
284 | |
'\n' + |
285 | |
", _pageY='" + _pageY + '\'' + |
286 | |
'\n' + |
287 | |
", _layerX='" + _layerX + '\'' + |
288 | |
'\n' + |
289 | |
", _layerY='" + _layerY + '\'' + |
290 | |
'\n' + |
291 | |
", _target=" + _target + |
292 | |
'\n' + |
293 | |
", _componentId='" + _componentId + '\'' + |
294 | |
'\n' + |
295 | |
", _componentIdPath='" + _componentIdPath + '\'' + |
296 | |
'\n' + |
297 | |
", _methodArguments='" + _methodArguments + '\'' + |
298 | |
'\n' + |
299 | |
", _methodArgumentsArray=" + _methodArgumentsArray + |
300 | |
'\n' + |
301 | |
']'; |
302 | |
} |
303 | |
|
304 | |
public boolean equals(Object o) |
305 | |
{ |
306 | 0 | if (this == o) return true; |
307 | 0 | if (o == null || getClass() != o.getClass()) return false; |
308 | |
|
309 | 0 | BrowserEvent event = (BrowserEvent) o; |
310 | |
|
311 | 0 | if (_charCode != null ? !_charCode.equals(event._charCode) : event._charCode != null) return false; |
312 | 0 | if (!Arrays.equals(_keys, event._keys)) return false; |
313 | 0 | if (_layerX != null ? !_layerX.equals(event._layerX) : event._layerX != null) return false; |
314 | 0 | if (_layerY != null ? !_layerY.equals(event._layerY) : event._layerY != null) return false; |
315 | 0 | if (_methodArguments != null ? !_methodArguments.equals(event._methodArguments) : event._methodArguments != null) return false; |
316 | 0 | if (_methodArgumentsArray != null ? !_methodArgumentsArray.equals(event._methodArgumentsArray) : event._methodArgumentsArray != null) return false; |
317 | 0 | if (_name != null ? !_name.equals(event._name) : event._name != null) return false; |
318 | 0 | if (_pageX != null ? !_pageX.equals(event._pageX) : event._pageX != null) return false; |
319 | 0 | if (_pageY != null ? !_pageY.equals(event._pageY) : event._pageY != null) return false; |
320 | 0 | if (_target != null ? !_target.equals(event._target) : event._target != null) return false; |
321 | 0 | if (_type != null ? !_type.equals(event._type) : event._type != null) return false; |
322 | |
|
323 | 0 | return true; |
324 | |
} |
325 | |
|
326 | |
public int hashCode() |
327 | |
{ |
328 | |
int result; |
329 | 0 | result = (_name != null ? _name.hashCode() : 0); |
330 | 0 | result = 31 * result + (_type != null ? _type.hashCode() : 0); |
331 | 0 | result = 31 * result + (_keys != null ? Arrays.hashCode(_keys) : 0); |
332 | 0 | result = 31 * result + (_charCode != null ? _charCode.hashCode() : 0); |
333 | 0 | result = 31 * result + (_pageX != null ? _pageX.hashCode() : 0); |
334 | 0 | result = 31 * result + (_pageY != null ? _pageY.hashCode() : 0); |
335 | 0 | result = 31 * result + (_layerX != null ? _layerX.hashCode() : 0); |
336 | 0 | result = 31 * result + (_layerY != null ? _layerY.hashCode() : 0); |
337 | 0 | result = 31 * result + (_target != null ? _target.hashCode() : 0); |
338 | 0 | result = 31 * result + (_methodArguments != null ? _methodArguments.hashCode() : 0); |
339 | 0 | result = 31 * result + (_methodArgumentsArray != null ? _methodArgumentsArray.hashCode() : 0); |
340 | 0 | return result; |
341 | |
} |
342 | |
} |