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