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