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