1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.taglibs.velocity;
19
20 import java.util.HashMap;
21 import javax.servlet.jsp.PageContext;
22
23 import org.apache.velocity.context.AbstractContext;
24
25 /***
26 * <p>
27 * Velocity Context implementationfor use in JSP's,
28 * where the servlet API 'scope' is used directly.
29 * </p>
30 * <p>
31 * This context will 'search' the scopes looking for an
32 * item, working outwards
33 * page->request->session->application
34 * </p>
35 *
36 * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
37 * @version $Id: JSPContext.java 516448 2007-03-09 16:25:47Z ate $
38 */
39 public class JSPContext extends AbstractContext
40 {
41 private HashMap context = new HashMap();
42 private PageContext pageContext = null;
43
44 public JSPContext( PageContext pageContext )
45 {
46 this.pageContext = pageContext;
47 }
48
49 public Object internalGet( String key )
50 {
51 Object o = context.get( key );
52
53 if ( o == null)
54 {
55 o = pageContext.getAttribute( key, PageContext.PAGE_SCOPE);
56
57 if (o == null)
58 {
59 o = pageContext.getAttribute( key, PageContext.REQUEST_SCOPE);
60
61 if ( o == null)
62 {
63 o = pageContext.getAttribute( key, PageContext.SESSION_SCOPE);
64
65 if ( o == null )
66 {
67 o = pageContext.getAttribute( key, PageContext.APPLICATION_SCOPE);
68 }
69 }
70 }
71
72 if ( o != null)
73 context.put( key, o );
74 }
75 return o;
76 }
77
78 public Object internalPut( String key, Object value )
79 {
80 return context.put( key, value );
81 }
82
83 public boolean internalContainsKey(Object key)
84 {
85 return context.containsKey( key );
86 }
87
88 public Object[] internalGetKeys()
89 {
90 return context.keySet().toArray();
91 }
92
93 public Object internalRemove(Object key)
94 {
95 return context.remove( key );
96 }
97 }