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.request.velocity.extractor;
22
23 import java.util.Enumeration;
24
25 import org.apache.tiles.request.attribute.AttributeExtractor;
26 import org.apache.velocity.context.Context;
27
28
29
30
31
32
33 public class VelocityScopeExtractor implements AttributeExtractor {
34
35
36
37
38 private Context context;
39
40
41
42
43
44
45 public VelocityScopeExtractor(Context context) {
46 this.context = context;
47 }
48
49 @Override
50 public void removeValue(String name) {
51 context.remove(name);
52 }
53
54 @Override
55 public Enumeration<String> getKeys() {
56 return new KeyEnumeration(context.getKeys());
57 }
58
59 @Override
60 public Object getValue(String key) {
61 return context.get(key);
62 }
63
64 @Override
65 public void setValue(String key, Object value) {
66 context.put(key, value);
67 }
68
69
70
71
72 private static class KeyEnumeration implements Enumeration<String> {
73
74
75
76
77 private int index = 0;
78
79
80
81
82 private Object[] keys;
83
84
85
86
87
88
89 public KeyEnumeration(Object[] keys) {
90 this.keys = keys;
91 }
92
93 @Override
94 public boolean hasMoreElements() {
95 return index < keys.length;
96 }
97
98 @Override
99 public String nextElement() {
100 return (String) keys[index++];
101 }
102 }
103 }