KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jpublish > view > velocity > VelocityViewContext


1 /*--
2
3  Copyright (C) 2001-2003 Aetrion LLC.
4  All rights reserved.
5  
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions
8  are met:
9  
10  1. Redistributions of source code must retain the above copyright
11     notice, this list of conditions, and the following disclaimer.
12  
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions, and the disclaimer that follows
15     these conditions in the documentation and/or other materials
16     provided with the distribution.
17
18  3. The name "JPublish" must not be used to endorse or promote products
19     derived from this software without prior written permission. For
20     written permission, please contact info@aetrion.com.
21  
22  4. Products derived from this software may not be called "JPublish", nor
23     may "JPublish" appear in their name, without prior written permission
24     from Aetrion LLC (info@aetrion.com).
25  
26  In addition, the authors of this software request (but do not require)
27  that you include in the end-user documentation provided with the
28  redistribution and/or in the software itself an acknowledgement equivalent
29  to the following:
30      "This product includes software developed by
31       Aetrion LLC (http://www.aetrion.com/)."
32
33  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
37  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  POSSIBILITY OF SUCH DAMAGE.
44
45  For more information on JPublish, please see <http://www.jpublish.org/>.
46  
47  */

48
49 package org.jpublish.view.velocity;
50
51 import org.apache.velocity.context.Context;
52 import org.jpublish.RequestContext;
53
54 /**
55  * Context object which can be passed to the Velocity engine for merging.
56  *
57  * @author Anthony Eden
58  */

59
60 public class VelocityViewContext implements Context {
61
62     private RequestContext context;
63
64     /**
65      * Construct a new VelocityViewContext which wraps the given RequestContext.
66      *
67      * @param context The RequestContext
68      */

69
70     public VelocityViewContext(RequestContext context) {
71         this.context = context;
72     }
73
74     /**
75      * Put an object into the context.
76      *
77      * @param key The key
78      * @param value The value
79      */

80
81     public Object JavaDoc put(String JavaDoc key, Object JavaDoc value) {
82         return context.put(key, value);
83     }
84
85     /**
86      * Get an object from the context.
87      *
88      * @param key The key
89      * @return The value or null
90      */

91
92     public Object JavaDoc get(String JavaDoc key) {
93         return context.get(key);
94     }
95
96     /**
97      * Remove an object from the context.
98      *
99      * @param key The key
100      * @return The object removed or null
101      */

102
103     public Object JavaDoc remove(Object JavaDoc key) {
104         return context.remove(key.toString());
105     }
106
107     /**
108      * Return true if the context contains the given key.
109      *
110      * @param key The key
111      * @return True if the context contains the key
112      */

113
114     public boolean containsKey(Object JavaDoc key) {
115         return context.containsKey(key.toString());
116     }
117
118     /**
119      * Get an array of all keys in the context.
120      *
121      * @return An array of all keys
122      */

123
124     public Object JavaDoc[] getKeys() {
125         return context.getKeys();
126     }
127
128 }
129
Popular Tags