1
2
3
4
5
6 package pt.digitalis.dif.controller.objects;
7
8 import java.util.HashMap;
9 import java.util.Map;
10 import java.util.Map.Entry;
11
12 import pt.digitalis.dif.controller.interfaces.IDIFRequest;
13 import pt.digitalis.dif.controller.interfaces.IDIFSession;
14 import pt.digitalis.dif.dem.interfaces.IStage;
15 import pt.digitalis.dif.dem.managers.IDEMManager;
16 import pt.digitalis.dif.ioc.DIFIoCRegistry;
17 import pt.digitalis.dif.utils.ObjectFormatter;
18
19
20
21
22
23
24
25
26 public class DIFRequest implements IDIFRequest {
27
28
29 final static public String ORIGINAL_REQUEST = "originalRequest";
30
31
32 private boolean ajaxMode = false;
33
34
35
36
37 private Map<String, Object> attributes = new HashMap<String, Object>();
38
39
40 private ClientDescriptor client;
41
42
43 private boolean componentMode = false;
44
45
46 private String format;
47
48
49 private boolean helpMode = false;
50
51
52
53
54 private Map<String, Object> parameters = new HashMap<String, Object>();
55
56
57 private boolean popupMode = false;
58
59
60 RESTAction restAction = null;
61
62
63 private boolean restCall = false;
64
65
66 private String stage;
67
68
69 private boolean templateMode = false;
70
71
72 private IDIFSession theSession;
73
74
75
76
77 public void addAttribute(String attributeName, Object attributeValue)
78 {
79 attributes.put(attributeName, attributeValue);
80 }
81
82
83
84
85 public void addParameter(String parameterName, Object parameterValue)
86 {
87 parameters.put(parameterName.toLowerCase(), parameterValue);
88 }
89
90
91
92
93 public Object getAttribute(String name)
94 {
95 return this.attributes.get(name);
96 }
97
98
99
100
101 public Map<String, Object> getAttributes()
102 {
103 return this.attributes;
104 }
105
106
107
108
109 public ClientDescriptor getClient()
110 {
111 return client;
112 }
113
114
115
116
117 public String getFormat()
118 {
119 return format;
120 }
121
122
123
124
125 public Object getParameter(String name)
126 {
127 return this.parameters.get(name.toLowerCase());
128 }
129
130
131
132
133 public Map<String, Object> getParameters()
134 {
135 return this.parameters;
136 }
137
138
139
140
141 public RESTAction getRestAction()
142 {
143 return restAction;
144 }
145
146
147
148
149 public IDIFSession getSession()
150 {
151 return this.theSession;
152 }
153
154
155
156
157 public String getStage()
158 {
159 return stage;
160 }
161
162
163
164
165 public IStage getStageProxy()
166 {
167 return DIFIoCRegistry.getRegistry().getImplementation(IDEMManager.class).getStage(getStage());
168 }
169
170
171
172
173 public boolean isAjaxMode()
174 {
175 return ajaxMode;
176 }
177
178
179
180
181 public boolean isComponentMode()
182 {
183 return componentMode;
184 }
185
186
187
188
189 public boolean isHelpMode()
190 {
191 return helpMode;
192 }
193
194
195
196
197 public boolean isPopupMode()
198 {
199 return popupMode;
200 }
201
202
203
204
205
206
207 public boolean isRestCall()
208 {
209 return restCall;
210 }
211
212
213
214
215 public boolean isTemplateMode()
216 {
217 return templateMode;
218 }
219
220
221
222
223
224
225
226 public void setAjaxMode(boolean ajaxMode)
227 {
228 this.ajaxMode = ajaxMode;
229 }
230
231
232
233
234 public void setAttributes(Map<String, Object> attributes)
235 {
236 this.attributes = attributes;
237 }
238
239
240
241
242 public void setClient(ClientDescriptor client)
243 {
244 this.client = client;
245 }
246
247
248
249
250 public void setComponentMode(boolean componentMode)
251 {
252 this.componentMode = componentMode;
253 }
254
255
256
257
258 public void setFormat(String format)
259 {
260 this.format = format;
261 }
262
263
264
265
266 public void setHelpMode(boolean helpMode)
267 {
268 this.helpMode = helpMode;
269 }
270
271
272
273
274 public void setParameters(Map<String, Object> parameters)
275 {
276 for (Entry<String, Object> entry: parameters.entrySet())
277 addParameter(entry.getKey().toLowerCase(), entry.getValue());
278 }
279
280
281
282
283 public void setPopupMode(boolean popupMode)
284 {
285 this.popupMode = popupMode;
286 }
287
288
289
290
291 public void setRestAction(RESTAction restAction)
292 {
293 this.restAction = restAction;
294 }
295
296
297
298
299
300
301
302 public void setRestCall(boolean restCall)
303 {
304 this.restCall = restCall;
305 }
306
307
308
309
310 public void setSession(IDIFSession session)
311 {
312 this.theSession = session;
313
314 }
315
316
317
318
319 public void setStage(String newStage)
320 {
321 this.stage = newStage;
322 }
323
324
325
326
327 public void setTemplateMode(boolean templateMode)
328 {
329 this.templateMode = templateMode;
330 }
331
332
333
334
335
336
337 @Override
338 public String toString()
339 {
340
341 ObjectFormatter formatter = new ObjectFormatter();
342 formatter.addItem("Client", client);
343 formatter.addItem("stage", stage);
344 formatter.addItem("Template Mode", templateMode);
345 formatter.addItem("Component Mode", componentMode);
346 formatter.addItem("Popup Mode", isPopupMode());
347 formatter.addItem("REST URL Mode", isRestCall());
348 formatter.addItem("Help Mode", helpMode);
349 formatter.addItem("Session", theSession);
350
351 Map<String, Object> allowedAttributes = new HashMap<String, Object>();
352 allowedAttributes.putAll(attributes);
353 allowedAttributes.remove("PageContentAttribute");
354 formatter.addItem("Attributes", allowedAttributes);
355
356 Map<String, Object> allowedParams = new HashMap<String, Object>();
357 allowedParams.putAll(parameters);
358 if (allowedParams.containsKey(PASSWORD_PARAMETER_ID))
359 allowedParams.put(PASSWORD_PARAMETER_ID, "*****");
360 if (allowedParams.containsKey("password"))
361 allowedParams.put("password", "*****");
362 formatter.addItem("Parameters", allowedParams);
363
364 return formatter.getFormatedObject();
365 }
366 }