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 |
|
|
37 |
|
public class ServletWebContext implements WebContext |
38 |
|
{ |
39 |
|
|
40 |
2 |
private static final Log LOG = LogFactory.getLog(ServletWebContext.class); |
41 |
|
|
42 |
|
private final ServletContext _servletContext; |
43 |
|
|
44 |
|
public ServletWebContext(ServletContext context) |
45 |
9 |
{ |
46 |
9 |
Defense.notNull(context, "context"); |
47 |
|
|
48 |
9 |
_servletContext = context; |
49 |
9 |
} |
50 |
|
|
51 |
|
public void describeTo(DescriptionReceiver receiver) |
52 |
|
{ |
53 |
0 |
receiver.describeAlternate(_servletContext); |
54 |
0 |
} |
55 |
|
|
56 |
|
public List getAttributeNames() |
57 |
|
{ |
58 |
1 |
return WebUtils.toSortedList(_servletContext.getAttributeNames()); |
59 |
|
} |
60 |
|
|
61 |
|
public Object getAttribute(String name) |
62 |
|
{ |
63 |
1 |
return _servletContext.getAttribute(name); |
64 |
|
} |
65 |
|
|
66 |
|
public void setAttribute(String name, Object attribute) |
67 |
|
{ |
68 |
2 |
if (attribute == null) |
69 |
1 |
_servletContext.removeAttribute(name); |
70 |
1 |
else _servletContext.setAttribute(name, attribute); |
71 |
|
|
72 |
2 |
} |
73 |
|
|
74 |
|
public URL getResource(String path) |
75 |
|
{ |
76 |
|
try |
77 |
|
{ |
78 |
2 |
return _servletContext.getResource(path); |
79 |
|
} |
80 |
1 |
catch (MalformedURLException ex) |
81 |
|
{ |
82 |
1 |
LOG.error(WebMessages.errorGettingResource(path, ex), ex); |
83 |
|
|
84 |
1 |
return null; |
85 |
|
} |
86 |
|
} |
87 |
|
|
88 |
|
public String getInitParameterValue(String name) |
89 |
|
{ |
90 |
1 |
return _servletContext.getInitParameter(name); |
91 |
|
} |
92 |
|
|
93 |
|
public List getInitParameterNames() |
94 |
|
{ |
95 |
1 |
return WebUtils.toSortedList(_servletContext.getInitParameterNames()); |
96 |
|
} |
97 |
|
|
98 |
|
public String getMimeType(String resourcePath) |
99 |
|
{ |
100 |
0 |
return _servletContext.getMimeType(resourcePath); |
101 |
|
} |
102 |
|
|
103 |
|
public String getRealPath(String path) |
104 |
|
{ |
105 |
0 |
return _servletContext.getRealPath(path); |
106 |
|
} |
107 |
|
|
108 |
|
public InputStream getResourceAsStream(String path) |
109 |
|
{ |
110 |
0 |
return _servletContext.getResourceAsStream(path); |
111 |
|
} |
112 |
|
|
113 |
|
public Set getResourcePaths(String path) |
114 |
|
{ |
115 |
0 |
return _servletContext.getResourcePaths(path); |
116 |
|
} |
117 |
|
} |