1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.portlet; |
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.portlet.PortletContext; |
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 |
| import org.apache.tapestry.web.WebContext; |
30 |
| import org.apache.tapestry.web.WebUtils; |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| public class PortletWebContext implements WebContext |
39 |
| { |
40 |
| private static final Log LOG = LogFactory.getLog(PortletWebContext.class); |
41 |
| |
42 |
| private final PortletContext _portletContext; |
43 |
| |
44 |
10
| public PortletWebContext(PortletContext portletContext)
|
45 |
| { |
46 |
10
| Defense.notNull(portletContext, "portletContext");
|
47 |
| |
48 |
10
| _portletContext = portletContext;
|
49 |
| } |
50 |
| |
51 |
8
| public URL getResource(String path)
|
52 |
| { |
53 |
8
| try
|
54 |
| { |
55 |
8
| return _portletContext.getResource(path);
|
56 |
| } |
57 |
| catch (MalformedURLException ex) |
58 |
| { |
59 |
1
| LOG.error(PortletMessages.errorGettingResource(path, ex), ex);
|
60 |
| |
61 |
1
| return null;
|
62 |
| } |
63 |
| } |
64 |
| |
65 |
1
| public List getAttributeNames()
|
66 |
| { |
67 |
1
| return WebUtils.toSortedList(_portletContext.getAttributeNames());
|
68 |
| } |
69 |
| |
70 |
1
| public Object getAttribute(String name)
|
71 |
| { |
72 |
1
| return _portletContext.getAttribute(name);
|
73 |
| } |
74 |
| |
75 |
2
| public void setAttribute(String name, Object attribute)
|
76 |
| { |
77 |
2
| if (attribute == null)
|
78 |
1
| _portletContext.removeAttribute(name);
|
79 |
| else |
80 |
1
| _portletContext.setAttribute(name, attribute);
|
81 |
| } |
82 |
| |
83 |
1
| public List getInitParameterNames()
|
84 |
| { |
85 |
1
| return WebUtils.toSortedList(_portletContext.getInitParameterNames());
|
86 |
| } |
87 |
| |
88 |
1
| public String getInitParameterValue(String name)
|
89 |
| { |
90 |
1
| return _portletContext.getInitParameter(name);
|
91 |
| } |
92 |
| |
93 |
0
| public String getMimeType(String resourcePath)
|
94 |
| { |
95 |
0
| return _portletContext.getMimeType(resourcePath);
|
96 |
| } |
97 |
| |
98 |
0
| public void describeTo(DescriptionReceiver receiver)
|
99 |
| { |
100 |
0
| receiver.describeAlternate(_portletContext);
|
101 |
| } |
102 |
| |
103 |
0
| public String getRealPath(String path) {
|
104 |
0
| return _portletContext.getRealPath(path);
|
105 |
| } |
106 |
| |
107 |
0
| public InputStream getResourceAsStream(String path) {
|
108 |
0
| return _portletContext.getResourceAsStream(path);
|
109 |
| } |
110 |
| |
111 |
0
| public Set getResourcePaths(String path) {
|
112 |
0
| return _portletContext.getResourcePaths(path);
|
113 |
| } |
114 |
| } |