1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.context;
20
21 import java.awt.Color;
22
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Map;
27 import java.util.Set;
28 import java.util.TimeZone;
29
30 import javax.faces.component.UIComponent;
31 import javax.faces.component.UIViewRoot;
32 import javax.faces.context.FacesContext;
33
34 import org.apache.myfaces.trinidad.change.ChangeManager;
35 import org.apache.myfaces.trinidad.config.RegionManager;
36 import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
37
38
39 public class MockRequestContext extends RequestContext
40 {
41 public MockRequestContext()
42 {
43 attach();
44 }
45
46
47
48
49 public void setAgent(Agent agent)
50 {
51 _agent = agent;
52 }
53
54 @Override
55 public Agent getAgent()
56 {
57 return _agent;
58 }
59
60 @Override
61 public PageResolver getPageResolver()
62 {
63 throw new UnsupportedOperationException("Not implemented yet");
64 }
65
66 @Override
67 public PageFlowScopeProvider getPageFlowScopeProvider()
68 {
69 throw new UnsupportedOperationException("Not implemented yet");
70 }
71
72 @Override
73 public DialogService getDialogService()
74 {
75 throw new UnsupportedOperationException("Not implemented yet");
76 }
77
78 @Override
79 public Map<String, Object> getPageFlowScope()
80 {
81 return new HashMap<String, Object>();
82 }
83
84 @Override
85 public void returnFromDialog(Object returnValue, Map<Object, Object> returnParam)
86 {
87 throw new UnsupportedOperationException("Should not be called during rendering");
88 }
89
90 @Override
91 public void launchDialog(
92 UIViewRoot dialogRoot,
93 Map<String, Object> dialogParameters,
94 UIComponent source,
95 boolean useWindow,
96 Map<String, Object> windowProperties)
97 {
98 throw new UnsupportedOperationException("Should not be called during rendering");
99 }
100
101 @Override
102 public boolean isPostback()
103 {
104 return false;
105 }
106
107 @Override
108 public boolean isPartialRequest(FacesContext context)
109 {
110 return false;
111 }
112
113 @Override
114 public boolean isDebugOutput()
115 {
116 return false;
117 }
118
119 @Override
120 public ClientValidation getClientValidation()
121 {
122 return ClientValidation.ALERT;
123 }
124
125 @Override
126 public boolean isClientValidationDisabled()
127 {
128 return false;
129 }
130
131 @Override
132 public String getOutputMode()
133 {
134 return null;
135 }
136
137 public void setSkinFamily(String skin)
138 {
139 _skin = skin;
140 }
141
142 @Override
143 public String getSkinFamily()
144 {
145 return _skin;
146 }
147
148 @Override
149 public Accessibility getAccessibilityMode()
150 {
151 return _accMode;
152 }
153
154 public void setAccessibilityMode(Accessibility accMode)
155 {
156 _accMode = accMode;
157 }
158
159 @Override
160 public AccessibilityProfile getAccessibilityProfile()
161 {
162 return _accProfile;
163 }
164
165 public void setAccessibilityProfile(AccessibilityProfile accProfile)
166 {
167 _accProfile = accProfile;
168 }
169
170 @Override
171 public boolean isRightToLeft()
172 {
173 return _rtl;
174 }
175
176 public void setRightToLeft(boolean rtl)
177 {
178 _rtl = rtl;
179 }
180
181 public void setAnimationEnabled(boolean animationEnabled)
182 {
183 _animationEnabled = animationEnabled;
184 }
185
186 @Override
187 public boolean isAnimationEnabled()
188 {
189 return _animationEnabled;
190 }
191
192 @Override
193 public Locale getFormattingLocale()
194 {
195 return _formattingLocale;
196 }
197
198 public void setFormattingLocale(Locale formattingLocale)
199 {
200 _formattingLocale = formattingLocale;
201 }
202
203 @Override
204 public char getNumberGroupingSeparator()
205 {
206 return _numberGroupingSeparator;
207 }
208
209 public void setNumberGroupingSeparator(char sep)
210 {
211 _numberGroupingSeparator = sep;
212 }
213
214 @Override
215 public char getDecimalSeparator()
216 {
217 return _decimalSeparator;
218 }
219
220 public void setDecimalSeparator(char sep)
221 {
222 _decimalSeparator = sep;
223 }
224
225 @Override
226 public String getCurrencyCode()
227 {
228 return _currencyCode;
229 }
230
231 public void setCurrencyCode(String code)
232 {
233 _currencyCode = code;
234 }
235
236 @Override
237 public int getTwoDigitYearStart()
238 {
239 return _twoDigitYearStart;
240 }
241
242 public void setTwoDigitYearStart(int start)
243 {
244 _twoDigitYearStart = start;
245 }
246
247 @Override
248 public String getOracleHelpServletUrl()
249 {
250 throw new UnsupportedOperationException("Not implemented yet");
251 }
252
253 @Override
254 public Map<String, Object> getHelpTopic()
255 {
256 throw new UnsupportedOperationException("Not implemented yet");
257 }
258
259 @Override
260 public Map<String, Object> getHelpSystem()
261 {
262 throw new UnsupportedOperationException("Not implemented yet");
263 }
264
265 @Override
266 public TimeZone getTimeZone()
267 {
268 return _timeZone;
269 }
270
271 public void setTimeZone(TimeZone timeZone)
272 {
273 _timeZone = timeZone;
274 }
275
276 public void setUploadedFileMaxMemory(Long maxMemory)
277 {
278 _maxMemory = maxMemory;
279 }
280
281 @Override
282 public Long getUploadedFileMaxMemory()
283 {
284 return _maxMemory;
285 }
286
287 public void setUploadedFileMaxDiskSpace(Long maxDiskSpace)
288 {
289 _maxDiskSpace = maxDiskSpace;
290 }
291
292 @Override
293 public Long getUploadedFileMaxDiskSpace()
294 {
295 return _maxDiskSpace;
296 }
297
298 public void setUploadedFileTempDir(String tempDir)
299 {
300 _tempDir= tempDir;
301 }
302
303 @Override
304 public String getUploadedFileTempDir()
305 {
306 return _tempDir;
307 }
308
309 @Override
310 public void addPartialTarget(UIComponent newTarget)
311 {
312
313 }
314
315
316
317
318 @Override
319 public void addPartialTargets(UIComponent from, String... targets)
320 {
321
322 }
323
324 @Override
325 public Set<UIComponent> getPartialTargets(UIComponent from)
326 {
327 throw new UnsupportedOperationException("Not implemented yet");
328 }
329
330 @Override
331 public void addPartialTriggerListeners(UIComponent listener, String[] trigger)
332 {
333 throw new UnsupportedOperationException("Should not be called during rendering");
334 }
335
336 @Override
337 public void partialUpdateNotify(UIComponent updated)
338 {
339
340 }
341
342 @Override
343 public UploadedFileProcessor getUploadedFileProcessor()
344 {
345 throw new UnsupportedOperationException("Should not be called during rendering");
346 }
347
348 @Override
349 public Map<String, List<Color>> getColorPalette()
350 {
351 throw new UnsupportedOperationException("Not implemented yet");
352 }
353
354 @Override
355 public Map<Object, Map<Object,String>> getFormatter()
356 {
357 throw new UnsupportedOperationException("Not implemented yet");
358 }
359
360 @Override
361 public ChangeManager getChangeManager()
362 {
363 throw new UnsupportedOperationException("Not implemented yet");
364 }
365
366 @Override
367 public RegionManager getRegionManager()
368 {
369 throw new UnsupportedOperationException("Not implemented yet");
370 }
371
372 @Override
373 public Object saveComponent(UIComponent component)
374 {
375 throw new UnsupportedOperationException("Not implemented yet");
376 }
377
378
379 @Override
380 public UIComponent restoreComponent(Object state)
381 {
382 throw new UnsupportedOperationException("Not implemented yet");
383 }
384
385 @Override
386 public boolean isInternalViewRequest(FacesContext context)
387 {
388 return false;
389 }
390
391 @Override
392 public Map<String, Object> getViewMap()
393 {
394 return getViewMap(true);
395 }
396
397 @Override
398 @SuppressWarnings("unchecked")
399 public Map<String, Object> getViewMap(boolean create)
400 {
401
402
403
404 FacesContext facesContext = FacesContext.getCurrentInstance();
405 UIViewRoot viewRoot = facesContext.getViewRoot();
406 Map<String, Object> viewMap = null;
407
408 if (viewRoot != null)
409 {
410 Map<String, Object> attrs = viewRoot.getAttributes();
411
412 viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
413 if (viewMap == null && create)
414 {
415
416
417
418
419 viewMap = new HashMap<String, Object>();
420 attrs.put(_VIEW_MAP_KEY, viewMap);
421 }
422 }
423
424 return viewMap;
425 }
426
427 static private final TimeZone _FIXED_TIME_ZONE =
428 TimeZone.getTimeZone("America/Los_Angeles");
429
430 static private final String _VIEW_MAP_KEY =
431 MockRequestContext.class.getName() + ".VIEW_MAP";
432
433 private char _numberGroupingSeparator = ',';
434 private char _decimalSeparator = '.';
435 private String _currencyCode = null;
436 private int _twoDigitYearStart = 1950;
437 private TimeZone _timeZone = _FIXED_TIME_ZONE;
438
439 private String _skin;
440 private Accessibility _accMode;
441 private AccessibilityProfile _accProfile;
442 private Agent _agent;
443 private boolean _rtl = false;
444 private boolean _animationEnabled = true;
445 private Locale _formattingLocale;
446 private Long _maxMemory;
447 private Long _maxDiskSpace;
448 private String _tempDir;
449 }