View Javadoc

1   package org.apache.velocity.tools.view.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.HashMap;
23  import java.util.Map;
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  import javax.servlet.ServletContext;
27  import org.apache.velocity.app.VelocityEngine;
28  import org.apache.velocity.context.Context;
29  import org.apache.velocity.tools.view.ViewToolContext;
30  import org.apache.velocity.tools.view.context.ViewContext;
31  
32  /**
33   * @deprecated Use {@link ViewToolContext} instead
34   * @version $Id: ChainedContext.java 608694 2008-01-04 00:53:32Z nbubna $
35   */
36  @Deprecated
37  public class ChainedContext extends ViewToolContext implements ViewContext
38  {
39      private Map<String,Object> oldToolbox;
40  
41      public ChainedContext(VelocityEngine velocity,
42                            HttpServletRequest request,
43                            HttpServletResponse response,
44                            ServletContext application)
45      {
46          super(velocity, request, response, application);
47      }
48  
49      public ChainedContext(Context ctx,
50                            VelocityEngine velocity,
51                            HttpServletRequest request,
52                            HttpServletResponse response,
53                            ServletContext application)
54      {
55          this(velocity, request, response, application);
56  
57          if (ctx != null)
58          {
59              // copy all values from the context into this
60              for (Object key : ctx.getKeys())
61              {
62                  String skey = String.valueOf(key);
63                  put(skey, ctx.get(skey));
64              }
65          }
66      }
67  
68  
69      /**
70       * Sets a "toolbox" in the style of VelocityTools 1.x.
71       * @deprecated
72       */
73      public void setToolbox(Map<String,Object> box)
74      {
75          this.oldToolbox = box;
76      }
77  
78      /**
79       * <p>Returns the tools for this context</p>
80       * @since VelocityTools 1.3
81       * @return any tools passed in via setToolbox() plus the results
82       *         of {@link ViewToolContext#getToolbox()}.
83       */
84      public Map<String,Object> getToolbox()
85      {
86          if (this.oldToolbox != null)
87          {
88              Map<String,Object> box = new HashMap<String,Object>(this.oldToolbox);
89              box.putAll(super.getToolbox());
90              return box;
91          }
92          return super.getToolbox();
93      }
94  
95      protected Object internalGet( String key )
96      {
97          Object o = null;
98  
99          /* search the toolbox */
100         if (oldToolbox != null)
101         {
102             o = oldToolbox.get(key);
103             if (o != null)
104             {
105                 return o;
106             }
107         }
108 
109         /* try the local hashtable */
110         return super.internalGet(key);
111     }
112 
113 }