01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.velocity;
06:
07: import com.opensymphony.xwork.util.OgnlValueStack;
08: import org.apache.velocity.VelocityContext;
09:
10: /**
11: * @author $Author: plightbo $
12: * @version $Revision: 1669 $
13: */
14: public class WebWorkVelocityContext extends VelocityContext {
15:
16: OgnlValueStack stack;
17: VelocityContext[] chainedContexts;
18:
19: public WebWorkVelocityContext(OgnlValueStack stack) {
20: this (null, stack);
21: }
22:
23: public WebWorkVelocityContext(VelocityContext[] chainedContexts,
24: OgnlValueStack stack) {
25: this .chainedContexts = chainedContexts;
26: this .stack = stack;
27: }
28:
29: public boolean internalContainsKey(Object key) {
30: boolean contains = super .internalContainsKey(key);
31:
32: // first let's check to see if we contain the requested key
33: if (contains) {
34: return true;
35: }
36:
37: // if not, let's search for the key in the ognl value stack
38: if (stack != null) {
39: Object o = stack.findValue(key.toString());
40:
41: if (o != null) {
42: return true;
43: }
44:
45: o = stack.getContext().get(key.toString());
46: if (o != null) {
47: return true;
48: }
49: }
50:
51: // if we still haven't found it, le's search through our chained contexts
52: if (chainedContexts != null) {
53: for (int index = 0; index < chainedContexts.length; index++) {
54: if (chainedContexts[index].containsKey(key)) {
55: return true;
56: }
57: }
58: }
59:
60: // nope, i guess it's really not here
61: return false;
62: }
63:
64: public Object internalGet(String key) {
65: // first, let's check to see if have the requested value
66: if (super .internalContainsKey(key)) {
67: return super .internalGet(key);
68: }
69:
70: // still no luck? let's look against the value stack
71: if (stack != null) {
72: Object object = stack.findValue(key);
73:
74: if (object != null) {
75: return object;
76: }
77:
78: object = stack.getContext().get(key);
79: if (object != null) {
80: return object;
81: }
82:
83: }
84:
85: // finally, if we're chained to other contexts, let's look in them
86: if (chainedContexts != null) {
87: for (int index = 0; index < chainedContexts.length; index++) {
88: if (chainedContexts[index].containsKey(key)) {
89: return chainedContexts[index].internalGet(key);
90: }
91: }
92: }
93:
94: // nope, i guess it's really not here
95: return null;
96: }
97: }
|