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