1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.velocity;
23
24 import org.apache.velocity.VelocityContext;
25
26 import com.opensymphony.xwork2.util.ValueStack;
27
28
29 /***
30 */
31 public class StrutsVelocityContext extends VelocityContext {
32
33 private static final long serialVersionUID = 8497212428904436963L;
34 ValueStack stack;
35 VelocityContext[] chainedContexts;
36
37
38 public StrutsVelocityContext(ValueStack stack) {
39 this(null, stack);
40 }
41
42 public StrutsVelocityContext(VelocityContext[] chainedContexts, ValueStack stack) {
43 this.chainedContexts = chainedContexts;
44 this.stack = stack;
45 }
46
47
48 public boolean internalContainsKey(Object key) {
49 boolean contains = super.internalContainsKey(key);
50
51
52 if (contains) {
53 return true;
54 }
55
56
57 if (stack != null) {
58 Object o = stack.findValue(key.toString());
59
60 if (o != null) {
61 return true;
62 }
63
64 o = stack.getContext().get(key.toString());
65 if (o != null) {
66 return true;
67 }
68 }
69
70
71 if (chainedContexts != null) {
72 for (int index = 0; index < chainedContexts.length; index++) {
73 if (chainedContexts[index].containsKey(key)) {
74 return true;
75 }
76 }
77 }
78
79
80 return false;
81 }
82
83 public Object internalGet(String key) {
84
85 if (super.internalContainsKey(key)) {
86 return super.internalGet(key);
87 }
88
89
90 if (stack != null) {
91 Object object = stack.findValue(key);
92
93 if (object != null) {
94 return object;
95 }
96
97 object = stack.getContext().get(key);
98 if (object != null) {
99 return object;
100 }
101
102 }
103
104
105 if (chainedContexts != null) {
106 for (int index = 0; index < chainedContexts.length; index++) {
107 if (chainedContexts[index].containsKey(key)) {
108 return chainedContexts[index].internalGet(key);
109 }
110 }
111 }
112
113
114 return null;
115 }
116 }