* @param ctx VelocityContext to fill
* @return Velocity Template object or null
*/
protected Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context ctx) throws Exception
{
RequestContext requestContext = (RequestContext)request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
if(requestContext == null)
{
throw new IllegalStateException("JetspeedVelocityViewServlet unable to handle request because there is no RequestContext in "+
"the HttpServletRequest.");
}
// hook up eventHandlers to the context, specifically our own IgnoringNullSetEventHandling
eventCartridge.attachToContext(ctx);
JetspeedDesktopContext desktopContext = (JetspeedDesktopContext)request.getAttribute(JetspeedDesktopContext.DESKTOP_CONTEXT_ATTRIBUTE);
if (desktopContext != null)
{
// standard render request and response also available in context
ctx.put(JetspeedDesktopContext.DESKTOP_CONTEXT_ATTRIBUTE, desktopContext);
ctx.put("JS2RequestContext", requestContext);
// setup TLS for Context propagation
handlingRequestContext.set(ctx);
return super.handleRequest(request, response, ctx);
}
// configure velocity context
PortletRequest renderRequest = (PortletRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
RenderResponse renderResponse = (RenderResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
PortletConfig portletConfig = (PortletConfig) request.getAttribute(ContainerConstants.PORTLET_CONFIG);
if (renderRequest != null)
{
renderRequest.setAttribute(VELOCITY_CONTEXT_ATTR, ctx);
}
JetspeedVelocityPowerTool jpt = (JetspeedVelocityPowerTool) renderRequest.getAttribute(PortalReservedParameters.JETSPEED_POWER_TOOL_REQ_ATTRIBUTE);
if(jpt == null)
{
throw new IllegalStateException("JetspeedVelocityViewServlet unable to handle request because there is no JetspeedPowerTool in "+
"the HttpServletRequest.");
}
jpt.setVelocityContext(ctx);
ctx.put("jetspeed", jpt);
ctx.put("JS2RequestContext", requestContext);
ctx.put("renderRequest", renderRequest);
ctx.put("renderResponse", renderResponse);
ctx.put("portletConfig", portletConfig);
ctx.put("portletModeView", PortletMode.VIEW);
ctx.put("portletModeEdit", PortletMode.EDIT);
ctx.put("portletModeHelp", PortletMode.HELP);
ctx.put("windowStateNormal", WindowState.NORMAL);
ctx.put("windowStateMinimized", WindowState.MINIMIZED);
ctx.put("windowStateMaximized", WindowState.MAXIMIZED);
ctx.put("rco", requestContext.getObjects());
StringBuffer appRoot = new StringBuffer();
if (!requestContext.getPortalURL().isRelativeOnly())
{
appRoot.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort());
}
appRoot.append(renderRequest.getContextPath());
ctx.put("appRoot", appRoot.toString());