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.ognl; |
22 | |
|
23 | |
import java.util.Map; |
24 | |
|
25 | |
import ognl.OgnlContext; |
26 | |
import ognl.PropertyAccessor; |
27 | |
|
28 | |
import org.apache.tiles.request.Request; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 8 | public class ScopePropertyAccessor implements PropertyAccessor { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
static final int SCOPE_SUFFIX_LENGTH = 5; |
41 | |
|
42 | |
@Override |
43 | |
public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { |
44 | 8 | Request request = (Request) target; |
45 | 8 | String scope = (String) name; |
46 | 8 | if (scope.endsWith("Scope")) { |
47 | 7 | String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH); |
48 | 7 | return request.getContext(scopeName); |
49 | |
} |
50 | 1 | return null; |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public String getSourceAccessor(OgnlContext context, Object target, |
55 | |
Object index) { |
56 | 2 | String scope = (String) index; |
57 | 2 | if (scope.endsWith("Scope")) { |
58 | 1 | String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH); |
59 | 1 | return ".getContext(\"" + scopeName + "\")"; |
60 | |
} |
61 | 1 | return null; |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public String getSourceSetter(OgnlContext context, Object target, |
66 | |
Object index) { |
67 | 1 | return null; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name, |
72 | |
Object value) { |
73 | |
|
74 | 1 | } |
75 | |
|
76 | |
} |