1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.web; |
16 |
| |
17 |
| import java.net.MalformedURLException; |
18 |
| import java.net.URL; |
19 |
| import java.util.List; |
20 |
| |
21 |
| import javax.servlet.ServletContext; |
22 |
| |
23 |
| import org.apache.commons.logging.Log; |
24 |
| import org.apache.commons.logging.LogFactory; |
25 |
| import org.apache.hivemind.util.Defense; |
26 |
| import org.apache.tapestry.describe.DescriptionReceiver; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public class ServletWebContext implements WebContext |
35 |
| { |
36 |
| private static final Log LOG = LogFactory.getLog(ServletWebContext.class); |
37 |
| |
38 |
| private final ServletContext _servletContext; |
39 |
| |
40 |
21
| public void describeTo(DescriptionReceiver receiver)
|
41 |
| { |
42 |
21
| receiver.describeAlternate(_servletContext);
|
43 |
| } |
44 |
| |
45 |
49
| public ServletWebContext(ServletContext context)
|
46 |
| { |
47 |
49
| Defense.notNull(context, "context");
|
48 |
| |
49 |
49
| _servletContext = context;
|
50 |
| } |
51 |
| |
52 |
1
| public List getAttributeNames()
|
53 |
| { |
54 |
1
| return WebUtils.toSortedList(_servletContext.getAttributeNames());
|
55 |
| } |
56 |
| |
57 |
1
| public Object getAttribute(String name)
|
58 |
| { |
59 |
1
| return _servletContext.getAttribute(name);
|
60 |
| } |
61 |
| |
62 |
2
| public void setAttribute(String name, Object attribute)
|
63 |
| { |
64 |
2
| if (attribute == null)
|
65 |
1
| _servletContext.removeAttribute(name);
|
66 |
| else |
67 |
1
| _servletContext.setAttribute(name, attribute);
|
68 |
| |
69 |
| } |
70 |
| |
71 |
732
| public URL getResource(String path)
|
72 |
| { |
73 |
732
| try
|
74 |
| { |
75 |
732
| return _servletContext.getResource(path);
|
76 |
| } |
77 |
| catch (MalformedURLException ex) |
78 |
| { |
79 |
1
| LOG.error(WebMessages.errorGettingResource(path, ex), ex);
|
80 |
| |
81 |
1
| return null;
|
82 |
| } |
83 |
| } |
84 |
| |
85 |
1221
| public String getInitParameterValue(String name)
|
86 |
| { |
87 |
1221
| return _servletContext.getInitParameter(name);
|
88 |
| } |
89 |
| |
90 |
1
| public List getInitParameterNames()
|
91 |
| { |
92 |
1
| return WebUtils.toSortedList(_servletContext.getInitParameterNames());
|
93 |
| } |
94 |
| |
95 |
1
| public String getMimeType(String resourcePath)
|
96 |
| { |
97 |
1
| return _servletContext.getMimeType(resourcePath);
|
98 |
| } |
99 |
| } |