taylor 2004/10/28 18:29:50 Modified: portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity BridgesVelocityViewServlet.java Added: portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity GenericVelocityPortlet.java Log: Phase I of Generic Velocity Portlet emulating basic functionality provided in the Portlet API (for JSPs) to Velocity portlets and templates. Provides the following Velocity context variables emulating PLT.22 JSP request variables: $renderRequest $renderResponse $portletConfig Constants: $MODE_EDIT, $MODE_HELP, $MODE_VIEW, $STATE_NORMAL, $STATE_MIN, $STATE_MAX Phase II will implement velocity action handling, form to bean conversion and validation, navigations (forwards) Revision Changes Path 1.2 +16 -3 jakarta-jetspeed-2/portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity/BridgesVelocityViewServlet.java Index: BridgesVelocityViewServlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity/BridgesVelocityViewServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BridgesVelocityViewServlet.java 24 Oct 2004 19:32:46 -0000 1.1 +++ BridgesVelocityViewServlet.java 29 Oct 2004 01:29:50 -0000 1.2 @@ -43,7 +43,7 @@ public final static String PORTLET_REQUEST = "javax.portlet.request"; public final static String PORTLET_RESPONSE = "javax.portlet.response"; public final static String PORTLET_CONFIG = "javax.portlet.config"; - + public static final String VELOCITY_WRITER_ATTR = "org.apache.velocity.io.VelocityWriter"; /** Cache of writers */ private static SimplePool writerPool = new SimplePool(40); @@ -63,12 +63,25 @@ if (renderRequest != null) { renderRequest.setAttribute(VELOCITY_CONTEXT_ATTR, ctx); + Context portletContext = (Context)renderRequest.getAttribute(GenericVelocityPortlet.PORTLET_BRIDGE_CONTEXT); + if (portletContext != null) + { + // merge in portletContext + Object[] keys = portletContext.getKeys(); + for (int ix = 0; ix < keys.length; ix++) + { + // is this api f'd in the head or what + ctx.put((String)keys[ix], portletContext.get((String)keys[ix])); + } + } + } + // standard render request and response also available in context ctx.put(PORTLET_REQUEST, renderRequest); ctx.put(PORTLET_RESPONSE, renderResponse); - + return super.handleRequest(request, response, ctx); } 1.1 jakarta-jetspeed-2/portals-bridges/velocity/src/java/org/apache/portals/bridges/velocity/GenericVelocityPortlet.java Index: GenericVelocityPortlet.java =================================================================== /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.portals.bridges.velocity; import java.io.IOException; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.WindowState; import org.apache.portals.bridges.common.GenericServletPortlet; import org.apache.velocity.VelocityContext; import org.apache.velocity.context.Context; /** * <p> * Generic Velocity Portlet emulating basic functionality provided in the Portlet API (for JSPs) * to Velocity portlets and templates. Provides the following Velocity context variables emulating * PLT.22 JSP request variables: * * <ul> * <li>$renderRequest * <li>$renderResponse * <li>$portletConfig * </ul> * </p> * <p> * PLT.22 Tags: * <ul> * <li>$actionURL -- use renderResponse.createActionURL() * <li>$renderURL -- use renderResponse.createRenderURL() * <li>$namespace -- use rennderResponse.getNamespace() (Namespace) * </ul> * Beware that Param tags cannot be added incrementally i.e. $renderURL.setParameter("name","value").setParameter("name","value") * since the portlet api returns void on setParameter (or setWindowState, setPortletMode) * Thus it is required to set each param or state on a single line: * </p> * <p> * #set($max = $renderResponse.createRenderURL()) * $max.setWindowState($STATE_MAX) * $max.setParameter("bush", "war") * </p> * <p> * Constants: * $MODE_EDIT, $MODE_HELP, $MODE_VIEW, $STATE_NORMAL, $STATE_MIN, $STATE_MAX * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: GenericVelocityPortlet.java,v 1.1 2004/10/29 01:29:50 taylor Exp $ */ public class GenericVelocityPortlet extends GenericServletPortlet { public final static String PORTLET_BRIDGE_CONTEXT = "portals.bridges.velocity.context"; public GenericVelocityPortlet() { } public void init(PortletConfig config) throws PortletException { super.init(config); } /** * Execute the servlet as define by the init parameter or preference PARAM_ACTION_PAGE. The value * if the parameter is a relative URL, i.e. /actionPage.jsp will execute the * JSP editPage.jsp in the portlet application's web app. The action should * not generate any content. The content will be generate by doCustom(), * doHelp() , doEdit(), or doView(). * * See section PLT.16.2 of the JSR 168 Portlet Spec for more information * around executing a servlet or JSP in processAction() * * @see javax.portlet.GenericPortlet#processAction * * @task Need to be able to execute a servlet for the action */ public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException { super.processAction(request, actionResponse); } /** * Execute the servlet as define by the init parameter or preference PARAM_EDIT_PAGE. The value * if the parameter is a relative URL, i.e. /editPage.jsp will execute the * JSP editPage.jsp in the portlet application's web app. * * @see javax.portlet.GenericPortlet#doCustom */ public void doCustom(RenderRequest request, RenderResponse response) throws PortletException, IOException { super.doCustom(request, response); } /** * Execute the servlet as define by the init parameter or preference PARAM_EDIT_PAGE. * The value if the parameter is a relative URL, i.e. /editPage.jsp will execute the * JSP editPage.jsp in the portlet application's web app. * * @see javax.portlet.GenericPortlet#doEdit */ public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { super.doEdit(request, response); } /** * Execute the servlet as define by the init parameter or preference PARAM_HELP_PAGE. * The value if the parameter is a relative URL, i.e. /helpPage.jsp will exeute the * JSP helpPage.jsp in the portlet application's web app. * * @see javax.portlet.GenericPortlet#doView */ public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException { super.doHelp(request, response); } /** * Execute the servlet as define by the init parameter or preference PARAM_VIEW_PAGE. * The value if the parameter is a relative URL, i.e. /viewPage.jsp will execute the * JSP viewPage.jsp in the portlet application's web app. * * @see javax.portlet.GenericPortlet#doView */ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { super.doView(request, response); } public void render(RenderRequest request, RenderResponse response) throws PortletException, java.io.IOException { createPortletVelocityContext(request, response); super.render(request, response); } private Context createPortletVelocityContext(RenderRequest request, RenderResponse response) { Context ctx = new VelocityContext(); request.setAttribute(PORTLET_BRIDGE_CONTEXT, ctx); // PLT.22 ctx.put("renderRequest", request); ctx.put("renderResponse", response); ctx.put("portletConfig", getPortletConfig()); // constants ctx.put("STATE_NORMAL", WindowState.NORMAL); ctx.put("STATE_MAX", WindowState.MAXIMIZED); ctx.put("STATE_MIN", WindowState.MINIMIZED); ctx.put("MODE_VIEW", PortletMode.VIEW); ctx.put("MODE_EDIT", PortletMode.EDIT); ctx.put("MODE_HELP", PortletMode.HELP); return ctx; } public Context getContext(RenderRequest request) { return (Context)request.getAttribute(PORTLET_BRIDGE_CONTEXT); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]