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