1 package org.apache.velocity.context;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.HashSet;
23 import java.util.Set;
24 import java.util.List;
25
26 import org.apache.velocity.VelocityContext;
27 import org.apache.velocity.app.event.EventCartridge;
28 import org.apache.velocity.runtime.RuntimeConstants;
29 import org.apache.velocity.runtime.RuntimeServices;
30 import org.apache.velocity.runtime.resource.Resource;
31 import org.apache.velocity.util.ClassUtils;
32 import org.apache.velocity.util.introspection.IntrospectionCacheData;
33
34 /**
35 * This is an abstract internal-use-only context implementation to be
36 * used as a subclass for other internal-use-only contexts that wrap
37 * other internal-use-only contexts.
38 *
39 * We use this context to make it easier to chain an existing context
40 * as part of a new context implementation. It just delegates everything
41 * to the inner/parent context. Subclasses then only need to override
42 * the methods relevant to them.
43 *
44 * @author Nathan Bubna
45 * @version $Id: ChainedInternalContextAdapter.java 685724 2008-08-13 23:12:12Z nbubna $
46 * @since 1.6
47 */
48 public abstract class ChainedInternalContextAdapter implements InternalContextAdapter
49 {
50 /** the parent context */
51 protected InternalContextAdapter innerContext = null;
52
53 /**
54 * CTOR, wraps an ICA
55 * @param inner context
56 */
57 public ChainedInternalContextAdapter(InternalContextAdapter inner)
58 {
59 innerContext = inner;
60 }
61
62 /**
63 * Return the inner / user context.
64 * @return The inner / user context.
65 */
66 public Context getInternalUserContext()
67 {
68 return innerContext.getInternalUserContext();
69 }
70
71 /**
72 * @see org.apache.velocity.context.InternalWrapperContext#getBaseContext()
73 */
74 public InternalContextAdapter getBaseContext()
75 {
76 return innerContext.getBaseContext();
77 }
78
79 /**
80 * Retrieves from parent context.
81 *
82 * @param key name of item to get
83 * @return stored object or null
84 */
85 public Object get(String key)
86 {
87 return innerContext.get(key);
88 }
89
90 /**
91 * Put method also stores values in parent context
92 *
93 * @param key name of item to set
94 * @param value object to set to key
95 * @return old stored object
96 */
97 public Object put(String key, Object value)
98 {
99 /*
100 * just put in the local context
101 */
102 return innerContext.put(key, value);
103 }
104
105 /**
106 * @see org.apache.velocity.context.Context#containsKey(java.lang.Object)
107 */
108 public boolean containsKey(Object key)
109 {
110 return innerContext.containsKey(key);
111 }
112
113 /**
114 * @see org.apache.velocity.context.Context#getKeys()
115 */
116 public Object[] getKeys()
117 {
118 return innerContext.getKeys();
119 }
120
121 /**
122 * @see org.apache.velocity.context.Context#remove(java.lang.Object)
123 */
124 public Object remove(Object key)
125 {
126 return innerContext.remove(key);
127 }
128
129 /**
130 * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentTemplateName(java.lang.String)
131 */
132 public void pushCurrentTemplateName(String s)
133 {
134 innerContext.pushCurrentTemplateName(s);
135 }
136
137 /**
138 * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentTemplateName()
139 */
140 public void popCurrentTemplateName()
141 {
142 innerContext.popCurrentTemplateName();
143 }
144
145 /**
146 * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentTemplateName()
147 */
148 public String getCurrentTemplateName()
149 {
150 return innerContext.getCurrentTemplateName();
151 }
152
153 /**
154 * @see org.apache.velocity.context.InternalHousekeepingContext#getTemplateNameStack()
155 */
156 public Object[] getTemplateNameStack()
157 {
158 return innerContext.getTemplateNameStack();
159 }
160
161 /**
162 * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentMacroName(java.lang.String)
163 */
164 public void pushCurrentMacroName(String s)
165 {
166 innerContext.pushCurrentMacroName(s);
167 }
168
169 /**
170 * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentMacroName()
171 */
172 public void popCurrentMacroName()
173 {
174 innerContext.popCurrentMacroName();
175 }
176
177 /**
178 * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroName()
179 */
180 public String getCurrentMacroName()
181 {
182 return innerContext.getCurrentMacroName();
183 }
184
185 /**
186 * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroCallDepth()
187 */
188 public int getCurrentMacroCallDepth()
189 {
190 return innerContext.getCurrentMacroCallDepth();
191 }
192
193 /**
194 * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroNameStack()
195 */
196 public Object[] getMacroNameStack()
197 {
198 return innerContext.getMacroNameStack();
199 }
200
201 /**
202 * @see org.apache.velocity.context.InternalHousekeepingContext#icacheGet(java.lang.Object)
203 */
204 public IntrospectionCacheData icacheGet(Object key)
205 {
206 return innerContext.icacheGet(key);
207 }
208
209 /**
210 * @see org.apache.velocity.context.InternalWrapperContext#localPut(java.lang.String,java.lang.Object)
211 */
212 public Object localPut(final String key, final Object value)
213 {
214 return innerContext.put(key, value);
215 }
216
217 /**
218 * @see org.apache.velocity.context.InternalHousekeepingContext#icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)
219 */
220 public void icachePut(Object key, IntrospectionCacheData o)
221 {
222 innerContext.icachePut(key, o);
223 }
224
225 /**
226 * @see org.apache.velocity.context.InternalHousekeepingContext#getAllowRendering()
227 */
228 public boolean getAllowRendering()
229 {
230 return innerContext.getAllowRendering();
231 }
232
233 /**
234 * @see org.apache.velocity.context.InternalHousekeepingContext#setAllowRendering(boolean)
235 */
236 public void setAllowRendering(boolean v)
237 {
238 innerContext.setAllowRendering(v);
239 }
240
241 /**
242 * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List)
243 */
244 public void setMacroLibraries(List macroLibraries)
245 {
246 innerContext.setMacroLibraries(macroLibraries);
247 }
248
249 /**
250 * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries()
251 */
252 public List getMacroLibraries()
253 {
254 return innerContext.getMacroLibraries();
255 }
256
257 /**
258 * @see org.apache.velocity.context.InternalEventContext#attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
259 */
260 public EventCartridge attachEventCartridge(EventCartridge ec)
261 {
262 return innerContext.attachEventCartridge(ec);
263 }
264
265 /**
266 * @see org.apache.velocity.context.InternalEventContext#getEventCartridge()
267 */
268 public EventCartridge getEventCartridge()
269 {
270 return innerContext.getEventCartridge();
271 }
272
273
274 /**
275 * @see org.apache.velocity.context.InternalHousekeepingContext#setCurrentResource(org.apache.velocity.runtime.resource.Resource)
276 */
277 public void setCurrentResource(Resource r)
278 {
279 innerContext.setCurrentResource(r);
280 }
281
282 /**
283 * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentResource()
284 */
285 public Resource getCurrentResource()
286 {
287 return innerContext.getCurrentResource();
288 }
289 }