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 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class MockVariableResolver extends VariableResolver { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 18 | public MockVariableResolver() { |
48 | 18 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public Object resolveVariable(FacesContext context, String name) { |
62 | |
|
63 | 30 | if ((context == null) || (name == null)) { |
64 | |
throw new NullPointerException(); |
65 | |
} |
66 | |
|
67 | |
|
68 | 30 | if ("application".equals(name)) { |
69 | |
return external().getContext(); |
70 | 30 | } else if ("applicationScope".equals(name)) { |
71 | 3 | return external().getApplicationMap(); |
72 | 27 | } else if ("cookie".equals(name)) { |
73 | |
return external().getRequestCookieMap(); |
74 | 27 | } else if ("facesContext".equals(name)) { |
75 | |
return FacesContext.getCurrentInstance(); |
76 | 27 | } else if ("header".equals(name)) { |
77 | |
return external().getRequestHeaderMap(); |
78 | 27 | } else if ("headerValues".equals(name)) { |
79 | |
return external().getRequestHeaderValuesMap(); |
80 | 27 | } else if ("param".equals(name)) { |
81 | |
return external().getRequestParameterMap(); |
82 | 27 | } else if ("paramValues".equals(name)) { |
83 | |
return external().getRequestParameterValuesMap(); |
84 | 27 | } else if ("request".equals(name)) { |
85 | |
return external().getRequest(); |
86 | 27 | } else if ("requestScope".equals(name)) { |
87 | 5 | return external().getRequestMap(); |
88 | 22 | } else if ("response".equals(name)) { |
89 | |
return external().getResponse(); |
90 | 22 | } else if ("session".equals(name)) { |
91 | |
return external().getSession(true); |
92 | 22 | } else if ("sessionScope".equals(name)) { |
93 | 3 | return external().getSessionMap(); |
94 | 19 | } else if ("view".equals(name)) { |
95 | |
return FacesContext.getCurrentInstance().getViewRoot(); |
96 | |
} |
97 | |
|
98 | |
|
99 | 19 | Map map = null; |
100 | 19 | map = external().getRequestMap(); |
101 | 19 | if (map.containsKey(name)) { |
102 | 16 | return map.get(name); |
103 | |
} |
104 | 3 | map = external().getSessionMap(); |
105 | 3 | if ((map != null) && (map.containsKey(name))) { |
106 | 1 | return map.get(name); |
107 | |
} |
108 | 2 | map = external().getApplicationMap(); |
109 | 2 | if (map.containsKey(name)) { |
110 | 1 | return map.get(name); |
111 | |
} |
112 | |
|
113 | |
|
114 | 1 | return null; |
115 | |
|
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private ExternalContext external() { |
127 | |
|
128 | 35 | return FacesContext.getCurrentInstance().getExternalContext(); |
129 | |
|
130 | |
} |
131 | |
|
132 | |
|
133 | |
} |