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 | 0 | private static final Log LOG = LogFactory.getLog(ServletWebContext.class); |
41 | |
|
42 | |
private final ServletContext _servletContext; |
43 | |
|
44 | |
public ServletWebContext(ServletContext context) |
45 | 0 | { |
46 | 0 | Defense.notNull(context, "context"); |
47 | |
|
48 | 0 | _servletContext = context; |
49 | 0 | } |
50 | |
|
51 | |
public void describeTo(DescriptionReceiver receiver) |
52 | |
{ |
53 | 0 | receiver.describeAlternate(_servletContext); |
54 | 0 | } |
55 | |
|
56 | |
public List getAttributeNames() |
57 | |
{ |
58 | 0 | return WebUtils.toSortedList(_servletContext.getAttributeNames()); |
59 | |
} |
60 | |
|
61 | |
public Object getAttribute(String name) |
62 | |
{ |
63 | 0 | return _servletContext.getAttribute(name); |
64 | |
} |
65 | |
|
66 | |
public void setAttribute(String name, Object attribute) |
67 | |
{ |
68 | 0 | if (attribute == null) |
69 | 0 | _servletContext.removeAttribute(name); |
70 | 0 | else _servletContext.setAttribute(name, attribute); |
71 | |
|
72 | 0 | } |
73 | |
|
74 | |
public URL getResource(String path) |
75 | |
{ |
76 | |
try |
77 | |
{ |
78 | 0 | return _servletContext.getResource(path); |
79 | |
} |
80 | 0 | catch (MalformedURLException ex) |
81 | |
{ |
82 | 0 | LOG.error(WebMessages.errorGettingResource(path, ex), ex); |
83 | |
|
84 | 0 | return null; |
85 | |
} |
86 | |
} |
87 | |
|
88 | |
public String getInitParameterValue(String name) |
89 | |
{ |
90 | 0 | return _servletContext.getInitParameter(name); |
91 | |
} |
92 | |
|
93 | |
public List getInitParameterNames() |
94 | |
{ |
95 | 0 | 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 | |
} |