This project has retired. For details please refer to its
Attic page.
ScopeELResolver xref
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.ArrayList;
25 import java.util.Collections;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29
30 import javax.el.ELContext;
31 import javax.el.ELResolver;
32
33 import org.apache.tiles.request.Request;
34
35
36
37
38
39
40
41 public class ScopeELResolver extends ELResolver {
42
43
44
45
46 private static final int SUFFIX_LENGTH = 5;
47
48
49 @Override
50 public Class<?> getCommonPropertyType(ELContext context, Object base) {
51
52 if (base != null) {
53 return null;
54 }
55
56 return Map.class;
57 }
58
59
60 @Override
61 public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
62 Object base) {
63 if (base != null) {
64 List<FeatureDescriptor> retValue = Collections.emptyList();
65 return retValue.iterator();
66 }
67
68 List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
69
70 Request request = (Request) context
71 .getContext(Request.class);
72 for (String scope : request.getAvailableScopes()) {
73 FeatureDescriptor descriptor = new FeatureDescriptor();
74 descriptor.setDisplayName(scope + "Scope");
75 descriptor.setExpert(false);
76 descriptor.setHidden(false);
77 descriptor.setName(scope + "Scope");
78 descriptor.setPreferred(true);
79 descriptor.setShortDescription("");
80 descriptor.setValue("type", Map.class);
81 descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
82 list.add(descriptor);
83 }
84
85 return list.iterator();
86 }
87
88
89 @Override
90 public Class<?> getType(ELContext context, Object base, Object property) {
91 if (base != null || property == null || !(property instanceof String)
92 || !((String) property).endsWith("Scope")) {
93 return null;
94 }
95
96 return Map.class;
97 }
98
99
100 @Override
101 public Object getValue(ELContext context, Object base, Object property) {
102 if (base != null) {
103 return null;
104 }
105
106 Object retValue = null;
107 String propertyString = (String) property;
108 if (property instanceof String && propertyString.endsWith("Scope")) {
109 Request request = (Request) context
110 .getContext(Request.class);
111 retValue = request.getContext(propertyString.substring(0,
112 propertyString.length() - SUFFIX_LENGTH));
113 }
114
115 if (retValue != null) {
116 context.setPropertyResolved(true);
117 }
118
119 return retValue;
120 }
121
122
123 @Override
124 public boolean isReadOnly(ELContext context, Object base, Object property) {
125 if (context == null) {
126 throw new NullPointerException();
127 }
128
129 return true;
130 }
131
132
133 @Override
134 public void setValue(ELContext context, Object base, Object property,
135 Object value) {
136
137 }
138 }