1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
package org.apache.tiles.web.util; |
22 | |
|
23 | |
import java.io.InputStream; |
24 | |
import java.net.MalformedURLException; |
25 | |
import java.net.URL; |
26 | |
import java.util.Enumeration; |
27 | |
import java.util.Hashtable; |
28 | |
import java.util.Set; |
29 | |
|
30 | |
import javax.servlet.RequestDispatcher; |
31 | |
import javax.servlet.Servlet; |
32 | |
import javax.servlet.ServletConfig; |
33 | |
import javax.servlet.ServletContext; |
34 | |
import javax.servlet.ServletException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@SuppressWarnings("deprecation") |
43 | |
public class ServletContextAdapter implements ServletContext { |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
private ServletContext rootContext; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private Hashtable<String, String> initParameters; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@SuppressWarnings("unchecked") |
63 | 26 | public ServletContextAdapter(ServletConfig config) { |
64 | 26 | this.rootContext = config.getServletContext(); |
65 | 26 | initParameters = new Hashtable<String, String>(); |
66 | 26 | Enumeration<String> enumeration = rootContext |
67 | |
.getInitParameterNames(); |
68 | 76 | while (enumeration.hasMoreElements()) { |
69 | 50 | String paramName = enumeration.nextElement(); |
70 | 50 | initParameters.put(paramName, rootContext |
71 | |
.getInitParameter(paramName)); |
72 | 50 | } |
73 | 26 | enumeration = config.getInitParameterNames(); |
74 | 76 | while (enumeration.hasMoreElements()) { |
75 | 50 | String paramName = enumeration.nextElement(); |
76 | 50 | initParameters.put(paramName, config.getInitParameter(paramName)); |
77 | 50 | } |
78 | 26 | } |
79 | |
|
80 | |
|
81 | |
public ServletContext getContext(String string) { |
82 | 1 | return rootContext.getContext(string); |
83 | |
} |
84 | |
|
85 | |
|
86 | |
public int getMajorVersion() { |
87 | 1 | return rootContext.getMajorVersion(); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
public int getMinorVersion() { |
92 | 1 | return rootContext.getMinorVersion(); |
93 | |
} |
94 | |
|
95 | |
|
96 | |
public String getMimeType(String string) { |
97 | 1 | return rootContext.getMimeType(string); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
@SuppressWarnings({ "rawtypes" }) |
102 | |
public Set getResourcePaths(String string) { |
103 | 1 | return rootContext.getResourcePaths(string); |
104 | |
} |
105 | |
|
106 | |
|
107 | |
public URL getResource(String string) throws MalformedURLException { |
108 | 1 | return rootContext.getResource(string); |
109 | |
} |
110 | |
|
111 | |
|
112 | |
public InputStream getResourceAsStream(String string) { |
113 | 1 | return rootContext.getResourceAsStream(string); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
public RequestDispatcher getRequestDispatcher(String string) { |
118 | 1 | return rootContext.getRequestDispatcher(string); |
119 | |
} |
120 | |
|
121 | |
|
122 | |
public RequestDispatcher getNamedDispatcher(String string) { |
123 | 1 | return rootContext.getNamedDispatcher(string); |
124 | |
} |
125 | |
|
126 | |
|
127 | |
public Servlet getServlet(String string) throws ServletException { |
128 | 1 | return rootContext.getServlet(string); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
@SuppressWarnings("rawtypes") |
133 | |
public Enumeration getServlets() { |
134 | 1 | return rootContext.getServlets(); |
135 | |
} |
136 | |
|
137 | |
|
138 | |
@SuppressWarnings("rawtypes") |
139 | |
public Enumeration getServletNames() { |
140 | 1 | return rootContext.getServletNames(); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
public void log(String string) { |
145 | 1 | rootContext.log(string); |
146 | 1 | } |
147 | |
|
148 | |
|
149 | |
public void log(Exception exception, String string) { |
150 | 1 | rootContext.log(exception, string); |
151 | 1 | } |
152 | |
|
153 | |
|
154 | |
public void log(String string, Throwable throwable) { |
155 | 1 | rootContext.log(string, throwable); |
156 | 1 | } |
157 | |
|
158 | |
|
159 | |
public String getRealPath(String string) { |
160 | 1 | return rootContext.getRealPath(string); |
161 | |
} |
162 | |
|
163 | |
|
164 | |
public String getServerInfo() { |
165 | 1 | return rootContext.getServerInfo(); |
166 | |
} |
167 | |
|
168 | |
|
169 | |
public String getInitParameter(String string) { |
170 | 3 | return initParameters.get(string); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
@SuppressWarnings("rawtypes") |
175 | |
public Enumeration getInitParameterNames() { |
176 | 1 | return initParameters.keys(); |
177 | |
} |
178 | |
|
179 | |
|
180 | |
public Object getAttribute(String string) { |
181 | 1 | return rootContext.getAttribute(string); |
182 | |
} |
183 | |
|
184 | |
|
185 | |
@SuppressWarnings("rawtypes") |
186 | |
public Enumeration getAttributeNames() { |
187 | 1 | return rootContext.getAttributeNames(); |
188 | |
} |
189 | |
|
190 | |
|
191 | |
public void setAttribute(String string, Object object) { |
192 | 1 | rootContext.setAttribute(string, object); |
193 | 1 | } |
194 | |
|
195 | |
|
196 | |
public void removeAttribute(String string) { |
197 | 1 | rootContext.removeAttribute(string); |
198 | 1 | } |
199 | |
|
200 | |
|
201 | |
public String getServletContextName() { |
202 | 1 | return rootContext.getServletContextName(); |
203 | |
} |
204 | |
|
205 | |
|
206 | |
public String getContextPath() { |
207 | 1 | return rootContext.getContextPath(); |
208 | |
} |
209 | |
} |