1 package org.apache.velocity.tools.view.context;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
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
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
71
72
73 public void setToolbox(Map<String,Object> box)
74 {
75 this.oldToolbox = box;
76 }
77
78
79
80
81
82
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
100 if (oldToolbox != null)
101 {
102 o = oldToolbox.get(key);
103 if (o != null)
104 {
105 return o;
106 }
107 }
108
109
110 return super.internalGet(key);
111 }
112
113 }