18
18
*/
19
19
package org .apache .struts2 .views .velocity ;
20
20
21
- import org .apache .velocity .VelocityContext ;
22
-
23
21
import com .opensymphony .xwork2 .util .ValueStack ;
22
+ import org .apache .velocity .VelocityContext ;
24
23
25
24
import java .util .ArrayList ;
26
25
import java .util .Arrays ;
27
26
import java .util .List ;
28
27
29
28
public class StrutsVelocityContext extends VelocityContext {
30
29
31
- private ValueStack stack ;
32
- private List <VelocityContext > chainedContexts ;
30
+ private final ValueStack stack ;
31
+ private final List <VelocityContext > chainedContexts ;
33
32
34
33
/**
35
34
* Creates a content with link to the ValueStack and any other Velocity contexts
@@ -44,7 +43,7 @@ public StrutsVelocityContext(List<VelocityContext> chainedContexts, ValueStack s
44
43
}
45
44
46
45
/**
47
- * @deprecated please use newly added {@link StrutsVelocityContext(List<VelocityContext)} constructor instead
46
+ * @deprecated please use {@link # StrutsVelocityContext(List, ValueStack)}
48
47
* and pass {null} or empty list if no chained contexts were defined
49
48
*/
50
49
@ Deprecated
@@ -53,79 +52,40 @@ public StrutsVelocityContext(ValueStack stack) {
53
52
}
54
53
55
54
/**
56
- * @deprecated please use newly added {@link StrutsVelocityContext(List<VelocityContext)} constructor instead
55
+ * @deprecated please use {@link # StrutsVelocityContext(List, ValueStack)}
57
56
*/
58
57
@ Deprecated ()
59
58
public StrutsVelocityContext (VelocityContext [] chainedContexts , ValueStack stack ) {
60
59
this (new ArrayList <>(Arrays .asList (chainedContexts )), stack );
61
60
}
62
61
63
62
public boolean internalContainsKey (String key ) {
64
- boolean contains = super .internalContainsKey (key );
65
-
66
- // first let's check to see if we contain the requested key
67
- if (contains ) {
68
- return true ;
69
- }
70
-
71
- // if not, let's search for the key in the ognl value stack
72
- if (stack != null ) {
73
- Object o = stack .findValue (key );
74
-
75
- if (o != null ) {
76
- return true ;
77
- }
78
-
79
- o = stack .getContext ().get (key );
80
- if (o != null ) {
81
- return true ;
82
- }
83
- }
84
-
85
- // if we still haven't found it, le's search through our chained contexts
86
- if (chainedContexts != null ) {
87
- for (VelocityContext chainedContext : chainedContexts ) {
88
- if (chainedContext .containsKey (key )) {
89
- return true ;
90
- }
91
- }
92
- }
93
-
94
- // nope, i guess it's really not here
95
- return false ;
63
+ return internalGet (key ) != null ;
96
64
}
97
65
98
66
public Object internalGet (String key ) {
99
- // first, let's check to see if have the requested value
100
- if (super . internalContainsKey ( key ) ) {
101
- return super . internalGet ( key ) ;
67
+ Object val = super . internalGet ( key );
68
+ if (val != null ) {
69
+ return val ;
102
70
}
103
-
104
- // still no luck? let's look against the value stack
105
71
if (stack != null ) {
106
- Object object = stack .findValue (key );
107
-
108
- if (object != null ) {
109
- return object ;
72
+ val = stack .findValue (key );
73
+ if (val != null ) {
74
+ return val ;
110
75
}
111
-
112
- object = stack .getContext ().get (key );
113
- if (object != null ) {
114
- return object ;
76
+ val = stack .getContext ().get (key );
77
+ if (val != null ) {
78
+ return val ;
115
79
}
116
-
117
80
}
118
-
119
- // finally, if we're chained to other contexts, let's look in them
120
81
if (chainedContexts != null ) {
121
82
for (VelocityContext chainedContext : chainedContexts ) {
122
- if (chainedContext .containsKey (key )) {
123
- return chainedContext .internalGet (key );
83
+ val = chainedContext .internalGet (key );
84
+ if (val != null ) {
85
+ return val ;
124
86
}
125
87
}
126
88
}
127
-
128
- // nope, i guess it's really not here
129
89
return null ;
130
90
}
131
91
}
0 commit comments