1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container;
18
19 import java.io.IOException;
20 import java.util.Properties;
21
22 import javax.portlet.PortletException;
23 import javax.servlet.ServletConfig;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.jetspeed.engine.servlet.ServletRequestFactory;
30 import org.apache.jetspeed.engine.servlet.ServletResponseFactory;
31 import org.apache.pluto.PortletContainer;
32 import org.apache.pluto.PortletContainerException;
33 import org.apache.pluto.om.window.PortletWindow;
34 import org.apache.pluto.services.PortletContainerEnvironment;
35
36 /***
37 * Portlet Container Wrapper to secure access to portlet container.
38 *
39 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
40 * @version $Id: JetspeedPortletContainerWrapper.java 516448 2007-03-09 16:25:47Z ate $
41 */
42 public class JetspeedPortletContainerWrapper implements PortletContainerWrapper
43 {
44 private boolean initialized = false;
45 private static final Log log = LogFactory.getLog(JetspeedPortletContainerWrapper.class);
46 private final PortletContainer pluto;
47 private final String containerId;
48 private final Properties properties;
49 private final PortletContainerEnvironment environment;
50 private final ServletConfig servletConfig;
51
52 private ServletRequestFactory requestFactory;
53 private ServletResponseFactory responseFactory;
54
55 public JetspeedPortletContainerWrapper(PortletContainer pluto, String containerId,
56 ServletConfig servletConfig, PortletContainerEnvironment env, Properties properties)
57 {
58 this.pluto = pluto;
59 this.containerId = containerId;
60 this.environment = env;
61 this.properties = properties;
62 this.servletConfig = servletConfig;
63 }
64
65 public JetspeedPortletContainerWrapper(PortletContainer pluto, String containerId,
66 ServletConfig servletConfig, PortletContainerEnvironment env)
67 {
68 this(pluto, containerId, servletConfig, env, new Properties());
69 }
70
71 /***
72 * Allows starting of the container without providing calling the
73 * <code>init()</code> method without all of the arguments as the
74 * arguments have already been provided in the constructor.
75 *
76 * @throws PortletContainerException
77 */
78 public void start() throws PortletContainerException
79 {
80 log.info("Attmepting to start Pluto portal container...");
81 this.init(containerId, servletConfig, environment, properties);
82 log.info("Pluto portlet container successfully started.");
83 }
84
85 /***
86 * initialization is still handled outside component architecture, since Pluto is not a component
87 */
88 public synchronized void init(
89 String uniqueContainerId,
90 ServletConfig servletConfig,
91 PortletContainerEnvironment environment,
92 Properties props)
93 throws PortletContainerException
94 {
95
96 pluto.init(uniqueContainerId, servletConfig, environment, props);
97 initialized = true;
98 }
99
100 public synchronized void shutdown() throws PortletContainerException
101 {
102 initialized = false;
103 pluto.shutdown();
104 }
105
106 public void renderPortlet(PortletWindow portletWindow, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
107 throws PortletException, IOException, PortletContainerException
108 {
109
110 if(portletWindow.getPortletEntity() == null)
111 {
112 log.warn("Could not render PortletWindow "+ portletWindow.getId() + " as it has no PortletEntity defined.");
113 return;
114 }
115
116 if(portletWindow.getPortletEntity().getPortletDefinition() == null)
117 {
118 log.warn("Could not render PortletWindow"+ portletWindow.getId() + " as it has no PortletDefintion defined.");
119 return;
120 }
121 pluto.renderPortlet(portletWindow, servletRequest, servletResponse);
122
123
124
125 }
126
127 public void processPortletAction(
128 PortletWindow portletWindow,
129 HttpServletRequest servletRequest,
130 HttpServletResponse servletResponse)
131 throws PortletException, IOException, PortletContainerException
132 {
133 pluto.processPortletAction(portletWindow, servletRequest, servletResponse);
134
135
136 }
137
138 public void portletLoad(PortletWindow portletWindow, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
139 throws PortletException, PortletContainerException
140 {
141 pluto.portletLoad(
142 portletWindow,
143 requestFactory.getServletRequest(servletRequest, portletWindow),
144 responseFactory.getServletResponse(servletResponse));
145 }
146
147 /***
148 * <p>
149 * isInitialized
150 * </p>
151 *
152 * @see org.apache.pluto.PortletContainer#isInitialized()
153 * @return
154 */
155 public boolean isInitialized()
156 {
157 return initialized;
158 }
159
160 public void setRequestFactory(ServletRequestFactory requestFactory)
161 {
162 this.requestFactory = requestFactory;
163 }
164
165 public void setResponseFactory(ServletResponseFactory responseFactory)
166 {
167 this.responseFactory = responseFactory;
168 }
169
170 }