1 package org.apache.velocity.test.misc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.velocity.VelocityContext;
26 import org.apache.velocity.context.Context;
27
28
29
30
31
32
33
34
35 public class TestContext implements Context
36 {
37 Context innerContext = new VelocityContext();
38 Map originalKeys = new HashMap();
39
40 public boolean containsKey(Object key)
41 {
42 return innerContext.containsKey(normalizeKey(key));
43 }
44
45 public Object get(String key)
46 {
47 return innerContext.get(normalizeKey(key));
48 }
49
50 public Object[] getKeys()
51 {
52 return originalKeys.values().toArray();
53 }
54
55 public Object put(String key, Object value)
56 {
57 String normalizedKey = normalizeKey(key);
58 originalKeys.put(key, normalizedKey);
59 return innerContext.put(normalizedKey, value);
60 }
61
62 public Object remove(Object key)
63 {
64 originalKeys.remove(key);
65 return innerContext.remove(normalizeKey(key));
66 }
67
68 private String normalizeKey(Object key)
69 {
70 if (key == null)
71 {
72 return null;
73 }
74 else if (key.toString() == null)
75 {
76 return null;
77 }
78 else
79 {
80 return key.toString().toUpperCase();
81 }
82 }
83 }