1 16 package org.apache.pluto; 17 18 import java.io.IOException ; 19 import java.util.Map ; 20 import java.util.Properties ; 21 22 import javax.portlet.ActionRequest; 23 import javax.portlet.ActionResponse; 24 import javax.portlet.PortletException; 25 import javax.portlet.PortletMode; 26 import javax.portlet.RenderRequest; 27 import javax.portlet.RenderResponse; 28 import javax.portlet.WindowState; 29 import javax.servlet.ServletConfig ; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import org.apache.pluto.core.InternalActionResponse; 34 import org.apache.pluto.factory.PortletObjectAccess; 35 import org.apache.pluto.invoker.PortletInvoker; 36 import org.apache.pluto.invoker.PortletInvokerAccess; 37 import org.apache.pluto.om.window.PortletWindow; 38 import org.apache.pluto.services.PortletContainerEnvironment; 39 import org.apache.pluto.services.information.DynamicInformationProvider; 40 import org.apache.pluto.services.information.InformationProviderAccess; 41 import org.apache.pluto.services.information.PortletURLProvider; 42 import org.apache.pluto.services.log.LogService; 43 import org.apache.pluto.services.log.Logger; 44 45 50 public class PortletContainerImpl implements PortletContainer 51 { 52 53 private String uniqueContainerName; 54 private boolean initialized; 55 56 private Logger log = null; 57 58 public void init(String uniqueContainerName, 59 ServletConfig servletConfig, 60 PortletContainerEnvironment environment, 61 Properties properties) 62 throws PortletContainerException 63 { 64 this.uniqueContainerName = uniqueContainerName; 65 PortletContainerServices.createReference(uniqueContainerName, environment); 66 initialized = true; 67 68 log = ((LogService)environment 71 .getContainerService(LogService.class)) 72 .getLogger(getClass()); 73 } 74 75 public void shutdown() throws PortletContainerException 76 { 77 PortletContainerServices.destroyReference(uniqueContainerName); 78 } 79 80 81 public void renderPortlet(PortletWindow portletWindow, 82 HttpServletRequest servletRequest, 83 HttpServletResponse servletResponse ) 84 throws PortletException, IOException , PortletContainerException 85 { 86 PortletContainerServices.prepare(uniqueContainerName); 87 PortletInvoker invoker = null; 88 89 if (log.isDebugEnabled()) 90 { 91 log.debug("PortletContainerImpl.portletService(" + portletWindow.getId() + ") called."); 92 } 93 94 try 95 { 96 RenderRequest renderRequest = PortletObjectAccess.getRenderRequest(portletWindow, 97 servletRequest, 98 servletResponse); 99 100 RenderResponse renderResponse = PortletObjectAccess.getRenderResponse(portletWindow, 101 servletRequest, 102 servletResponse); 103 104 invoker = PortletInvokerAccess.getPortletInvoker(portletWindow.getPortletEntity().getPortletDefinition()); 105 invoker.render(renderRequest, renderResponse); 106 } 107 finally 108 { 109 PortletInvokerAccess.releasePortletInvoker(invoker); 110 PortletContainerServices.release(); 111 } 112 113 } 114 115 116 public void processPortletAction(PortletWindow portletWindow, 117 HttpServletRequest servletRequest, 118 HttpServletResponse servletResponse) 119 throws PortletException, IOException , PortletContainerException 120 { 121 PortletContainerServices.prepare(uniqueContainerName); 122 PortletInvoker invoker = null; 123 124 if (log.isDebugEnabled()) 125 { 126 log.debug("PortletContainerImpl.performPortletAction(" + portletWindow.getId() + ") called."); 127 } 128 129 String location = null; 130 131 InternalActionResponse _actionResponse = null; 132 ActionRequest actionRequest = null; 133 134 try 135 { 136 137 actionRequest = 138 PortletObjectAccess.getActionRequest(portletWindow, 139 servletRequest, 140 servletResponse); 141 142 ActionResponse actionResponse = PortletObjectAccess.getActionResponse(portletWindow, 143 servletRequest, 144 servletResponse); 145 invoker = PortletInvokerAccess.getPortletInvoker(portletWindow.getPortletEntity().getPortletDefinition()); 146 147 _actionResponse = (InternalActionResponse)actionResponse; 148 149 invoker.action(actionRequest, actionResponse); 151 152 location = _actionResponse.getRedirectLocation(); 153 } 154 catch (PortletException e) 155 { 156 throw e; 157 } 158 catch (IOException e) 159 { 160 throw e; 161 } 162 catch (RuntimeException e) 163 { 164 throw e; 165 } 166 finally 167 { 168 try 169 { 170 redirect(location, portletWindow, servletRequest, servletResponse, _actionResponse); 171 } 172 finally 173 { 174 PortletInvokerAccess.releasePortletInvoker(invoker); 175 PortletContainerServices.release(); 176 } 177 } 178 } 179 180 public void portletLoad ( PortletWindow portletWindow, 181 HttpServletRequest servletRequest, 182 HttpServletResponse servletResponse ) 183 throws PortletException, PortletContainerException 184 { 185 PortletContainerServices.prepare(uniqueContainerName); 186 PortletInvoker invoker = null; 187 188 if (log.isDebugEnabled()) 189 log.debug("PortletContainerImpl.portletLoad("+portletWindow.getId()+") called."); 190 191 RenderRequest renderRequest = PortletObjectAccess.getRenderRequest(portletWindow, 192 servletRequest, 193 servletResponse); 194 195 RenderResponse renderResponse = PortletObjectAccess.getRenderResponse(portletWindow, 196 servletRequest, 197 servletResponse); 198 199 invoker = PortletInvokerAccess.getPortletInvoker(portletWindow.getPortletEntity().getPortletDefinition()); 200 201 try 202 { 203 invoker.load(renderRequest, renderResponse); 204 } 205 finally 206 { 207 PortletInvokerAccess.releasePortletInvoker(invoker); 208 PortletContainerServices.release(); 209 } 210 211 } 212 213 public boolean isInitialized() 214 { 215 return initialized; 216 } 217 218 protected void redirect(String location, 219 PortletWindow portletWindow, 220 HttpServletRequest servletRequest, 221 HttpServletResponse servletResponse, 222 InternalActionResponse _actionResponse) 223 throws IOException { 224 if (location == null && _actionResponse != null) 225 { 226 DynamicInformationProvider provider = InformationProviderAccess.getDynamicProvider(servletRequest); 227 228 230 PortletMode portletMode = provider.getPortletMode(portletWindow); 231 WindowState windowState = provider.getWindowState(portletWindow); 232 233 if (_actionResponse.getChangedPortletMode() != null) 236 { 237 portletMode = _actionResponse.getChangedPortletMode(); 238 InformationProviderAccess.getDynamicProvider(servletRequest) 239 .getPortletActionProvider(portletWindow) 240 .changePortletMode(portletMode); 241 } 242 if (_actionResponse.getChangedWindowState() != null) 244 { 245 windowState = _actionResponse.getChangedWindowState(); 246 InformationProviderAccess.getDynamicProvider(servletRequest) 247 .getPortletActionProvider(portletWindow) 248 .changePortletWindowState(windowState); 249 } 250 Map renderParameter = _actionResponse.getRenderParameters(); 252 253 PortletURLProvider redirectURL = provider.getPortletURLProvider(portletWindow); 254 255 if (provider.getPortletMode(portletWindow)!=null) 256 { 257 redirectURL.setPortletMode(portletMode); 258 } 259 if (provider.getWindowState(portletWindow)!=null) 260 { 261 redirectURL.setWindowState(windowState); 262 } 263 if (servletRequest.isSecure()) 264 { 265 redirectURL.setSecure(); } 267 redirectURL.clearParameters(); 268 redirectURL.setParameters(renderParameter); 269 270 location = servletResponse.encodeRedirectURL(redirectURL.toString()); 271 } 272 273 javax.servlet.http.HttpServletResponse redirectResponse = servletResponse; 274 while (redirectResponse instanceof javax.servlet.http.HttpServletResponseWrapper ) 275 { 276 redirectResponse = (javax.servlet.http.HttpServletResponse ) 277 ((javax.servlet.http.HttpServletResponseWrapper )redirectResponse).getResponse(); 278 } 279 redirectResponse.sendRedirect(location); 280 281 } 282 } 283 | Popular Tags |