1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
package org.apache.tiles.el; |
22 | |
|
23 | |
import java.beans.FeatureDescriptor; |
24 | |
import java.util.Iterator; |
25 | |
|
26 | |
import javax.el.ELContext; |
27 | |
import javax.el.ELResolver; |
28 | |
|
29 | |
import org.apache.tiles.request.ApplicationContext; |
30 | |
import org.apache.tiles.request.Request; |
31 | |
import org.apache.tiles.util.CombinedBeanInfo; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class TilesContextELResolver extends ELResolver { |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private ELResolver beanElResolver; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 9 | public TilesContextELResolver(ELResolver beanElResolver) { |
53 | 9 | this.beanElResolver = beanElResolver; |
54 | 9 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 9 | private CombinedBeanInfo requestBeanInfo = new CombinedBeanInfo( |
60 | |
Request.class, ApplicationContext.class); |
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public Class<?> getCommonPropertyType(ELContext context, Object base) { |
65 | |
|
66 | 2 | if (base != null) { |
67 | 1 | return null; |
68 | |
} |
69 | |
|
70 | 1 | return String.class; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
@Override |
75 | |
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, |
76 | |
Object base) { |
77 | |
|
78 | 2 | if (base != null) { |
79 | 1 | return null; |
80 | |
} |
81 | |
|
82 | 1 | return requestBeanInfo.getDescriptors().iterator(); |
83 | |
} |
84 | |
|
85 | |
|
86 | |
@Override |
87 | |
public Class<?> getType(ELContext context, Object base, Object property) { |
88 | |
|
89 | 3 | if (base != null) { |
90 | 1 | return null; |
91 | |
} |
92 | |
|
93 | 2 | Class<?> retValue = null; |
94 | 2 | if (requestBeanInfo.getProperties(Request.class).contains(property)) { |
95 | 1 | Request request = (Request) context |
96 | |
.getContext(Request.class); |
97 | 1 | retValue = beanElResolver.getType(context, request, property); |
98 | 1 | } else if (requestBeanInfo.getProperties(ApplicationContext.class).contains(property)) { |
99 | 1 | ApplicationContext applicationContext = (ApplicationContext) context |
100 | |
.getContext(ApplicationContext.class); |
101 | 1 | retValue = beanElResolver.getType(context, applicationContext, property); |
102 | |
} |
103 | |
|
104 | 2 | if (retValue != null) { |
105 | 2 | context.setPropertyResolved(true); |
106 | |
} |
107 | |
|
108 | 2 | return retValue; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
public Object getValue(ELContext context, Object base, Object property) { |
114 | |
|
115 | 19 | if (base != null) { |
116 | 9 | return null; |
117 | |
} |
118 | |
|
119 | 10 | Object retValue = null; |
120 | |
|
121 | 10 | if (requestBeanInfo.getProperties(Request.class).contains(property)) { |
122 | 1 | Request request = (Request) context |
123 | |
.getContext(Request.class); |
124 | 1 | retValue = beanElResolver.getValue(context, request, property); |
125 | 1 | } else if (requestBeanInfo.getProperties(ApplicationContext.class) |
126 | |
.contains(property)) { |
127 | 1 | ApplicationContext applicationContext = (ApplicationContext) context |
128 | |
.getContext(ApplicationContext.class); |
129 | 1 | retValue = beanElResolver.getValue(context, applicationContext, property); |
130 | |
} |
131 | |
|
132 | 10 | if (retValue != null) { |
133 | 2 | context.setPropertyResolved(true); |
134 | |
} |
135 | |
|
136 | 10 | return retValue; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public boolean isReadOnly(ELContext context, Object base, Object property) { |
142 | 2 | if (context == null) { |
143 | 1 | throw new NullPointerException(); |
144 | |
} |
145 | |
|
146 | 1 | return true; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
@Override |
151 | |
public void setValue(ELContext context, Object base, Object property, |
152 | |
Object value) { |
153 | |
|
154 | 1 | } |
155 | |
} |