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 public TilesContextELResolver(ELResolver beanElResolver) {
53 this.beanElResolver = beanElResolver;
54 }
55
56
57
58
59 private CombinedBeanInfo requestBeanInfo = new CombinedBeanInfo(
60 Request.class, ApplicationContext.class);
61
62
63 @Override
64 public Class<?> getCommonPropertyType(ELContext context, Object base) {
65
66 if (base != null) {
67 return null;
68 }
69
70 return String.class;
71 }
72
73
74 @Override
75 public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
76 Object base) {
77
78 if (base != null) {
79 return null;
80 }
81
82 return requestBeanInfo.getDescriptors().iterator();
83 }
84
85
86 @Override
87 public Class<?> getType(ELContext context, Object base, Object property) {
88
89 if (base != null) {
90 return null;
91 }
92
93 Class<?> retValue = null;
94 if (requestBeanInfo.getProperties(Request.class).contains(property)) {
95 Request request = (Request) context
96 .getContext(Request.class);
97 retValue = beanElResolver.getType(context, request, property);
98 } else if (requestBeanInfo.getProperties(ApplicationContext.class).contains(property)) {
99 ApplicationContext applicationContext = (ApplicationContext) context
100 .getContext(ApplicationContext.class);
101 retValue = beanElResolver.getType(context, applicationContext, property);
102 }
103
104 if (retValue != null) {
105 context.setPropertyResolved(true);
106 }
107
108 return retValue;
109 }
110
111
112 @Override
113 public Object getValue(ELContext context, Object base, Object property) {
114
115 if (base != null) {
116 return null;
117 }
118
119 Object retValue = null;
120
121 if (requestBeanInfo.getProperties(Request.class).contains(property)) {
122 Request request = (Request) context
123 .getContext(Request.class);
124 retValue = beanElResolver.getValue(context, request, property);
125 } else if (requestBeanInfo.getProperties(ApplicationContext.class)
126 .contains(property)) {
127 ApplicationContext applicationContext = (ApplicationContext) context
128 .getContext(ApplicationContext.class);
129 retValue = beanElResolver.getValue(context, applicationContext, property);
130 }
131
132 if (retValue != null) {
133 context.setPropertyResolved(true);
134 }
135
136 return retValue;
137 }
138
139
140 @Override
141 public boolean isReadOnly(ELContext context, Object base, Object property) {
142 if (context == null) {
143 throw new NullPointerException();
144 }
145
146 return true;
147 }
148
149
150 @Override
151 public void setValue(ELContext context, Object base, Object property,
152 Object value) {
153
154 }
155 }