2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.test.mock;
19
20 import java.util.Map;
21
22 import javax.faces.context.ExternalContext;
23 import javax.faces.context.FacesContext;
24 import javax.faces.el.VariableResolver;
25
26 /***
27 * <p>Mock implementation of <code>VariableResolver</code>.</p>
28 *
29 * <p>This implementation recognizes the standard scope names
30 * <code>applicationScope</code>, <code>facesContext</code>,
31 * <code>RequestScope</code>, and
32 * <code>sessionScope</code>, plus it knows how to search in ascending
33 * scopes for non-reserved names.</p>
34 *
35 * $Id$
36 */
37
38 public class MockVariableResolver extends VariableResolver {
39
40
41
42
43
44 /***
45 * <p>Construct a default instance.</p>
46 */
47 public MockVariableResolver() {
48 }
49
50
51
52
53
54
55
56
57
58
59
60 /*** {@inheritDoc} */
61 public Object resolveVariable(FacesContext context, String name) {
62
63 if ((context == null) || (name == null)) {
64 throw new NullPointerException();
65 }
66
67
68 if ("application".equals(name)) {
69 return external().getContext();
70 } else if ("applicationScope".equals(name)) {
71 return external().getApplicationMap();
72 } else if ("cookie".equals(name)) {
73 return external().getRequestCookieMap();
74 } else if ("facesContext".equals(name)) {
75 return FacesContext.getCurrentInstance();
76 } else if ("header".equals(name)) {
77 return external().getRequestHeaderMap();
78 } else if ("headerValues".equals(name)) {
79 return external().getRequestHeaderValuesMap();
80 } else if ("param".equals(name)) {
81 return external().getRequestParameterMap();
82 } else if ("paramValues".equals(name)) {
83 return external().getRequestParameterValuesMap();
84 } else if ("request".equals(name)) {
85 return external().getRequest();
86 } else if ("requestScope".equals(name)) {
87 return external().getRequestMap();
88 } else if ("response".equals(name)) {
89 return external().getResponse();
90 } else if ("session".equals(name)) {
91 return external().getSession(true);
92 } else if ("sessionScope".equals(name)) {
93 return external().getSessionMap();
94 } else if ("view".equals(name)) {
95 return FacesContext.getCurrentInstance().getViewRoot();
96 }
97
98
99 Map map = null;
100 map = external().getRequestMap();
101 if (map.containsKey(name)) {
102 return map.get(name);
103 }
104 map = external().getSessionMap();
105 if ((map != null) && (map.containsKey(name))) {
106 return map.get(name);
107 }
108 map = external().getApplicationMap();
109 if (map.containsKey(name)) {
110 return map.get(name);
111 }
112
113
114 return null;
115
116 }
117
118
119
120
121
122
123 /***
124 * <p>Return the <code>ExternalContext</code> for this request.</p>
125 */
126 private ExternalContext external() {
127
128 return FacesContext.getCurrentInstance().getExternalContext();
129
130 }
131
132
133 }