Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 94681 invoked from network); 1 Dec 2008 18:35:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Dec 2008 18:35:31 -0000 Received: (qmail 28473 invoked by uid 500); 1 Dec 2008 18:35:42 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 28440 invoked by uid 500); 1 Dec 2008 18:35:42 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 28431 invoked by uid 99); 1 Dec 2008 18:35:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 10:35:42 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 18:34:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C70102388975; Mon, 1 Dec 2008 10:34:39 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r722163 - in /struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet: context/PortletActionContext.java result/PortletResult.java util/PortletUrlHelper.java Date: Mon, 01 Dec 2008 18:34:39 -0000 To: commits@struts.apache.org From: nilsga@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081201183439.C70102388975@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nilsga Date: Mon Dec 1 10:34:38 2008 New Revision: 722163 URL: http://svn.apache.org/viewvc?rev=722163&view=rev Log: Fix for proper resource rendering (AJAX). Patch by Philipp Anokhin. Thanks! Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java?rev=722163&r1=722162&r2=722163&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java Mon Dec 1 10:34:38 2008 @@ -164,6 +164,13 @@ } /** + * @return true if the Portlet is executing in the resource phase. + */ + public static boolean isResource() { + return SERVE_RESOURCE_PHASE.equals(getPhase()); + } + + /** * @return The current ActionContext. */ private static ActionContext getContext() { Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java?rev=722163&r1=722162&r2=722163&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java Mon Dec 1 10:34:38 2008 @@ -28,7 +28,8 @@ import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.PortletRequestDispatcher; -import javax.portlet.RenderRequest; +import javax.portlet.PortletRequest; +import javax.portlet.MimeResponse; import javax.portlet.RenderResponse; import javax.portlet.StateAwareResponse; import javax.servlet.ServletContext; @@ -87,8 +88,8 @@ */ public void doExecute(String finalLocation, ActionInvocation actionInvocation) throws Exception { - if (PortletActionContext.isRender()) { - executeRenderResult(finalLocation); + if (PortletActionContext.isRender() || PortletActionContext.isResource()) { + executeMimeResult(finalLocation); } else if (PortletActionContext.isAction() || PortletActionContext.isEvent()) { executeActionResult(finalLocation, actionInvocation); } else { @@ -125,7 +126,8 @@ * @param invocation */ protected void executeActionResult(String finalLocation, ActionInvocation invocation) throws Exception { - LOG.debug("Executing result in Event phase"); + String phase = (PortletActionContext.isEvent()) ? "Event" : "Action"; + LOG.debug("Executing result in "+phase+" phase"); StateAwareResponse res = (StateAwareResponse)PortletActionContext.getResponse(); Map sessionMap = invocation.getInvocationContext().getSession(); LOG.debug("Setting event render parameter: " + finalLocation); @@ -168,38 +170,38 @@ } } - /** - * Executes the render result. - * - * @param finalLocation - * @throws PortletException - * @throws IOException - */ - protected void executeRenderResult(final String finalLocation) throws PortletException, IOException { - LOG.debug("Executing result in Render phase"); - PortletContext ctx = PortletActionContext.getPortletContext(); - RenderRequest req = PortletActionContext.getRenderRequest(); - RenderResponse res = PortletActionContext.getRenderResponse(); - res.setContentType(contentType); - if (TextUtils.stringSet(title)) { - res.setTitle(title); - } - LOG.debug("Location: " + finalLocation); - if (useDispatcherServlet) { - req.setAttribute(DISPATCH_TO, finalLocation); - PortletRequestDispatcher dispatcher = ctx.getNamedDispatcher(dispatcherServletName); - if(dispatcher == null) { - throw new PortletException("Could not locate dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml file"); - } - dispatcher.include(req, res); - } else { - PortletRequestDispatcher dispatcher = ctx.getRequestDispatcher(finalLocation); - if (dispatcher == null) { - throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'"); - } - dispatcher.include(req, res); - } - } + /** + * Executes the render result. + * + * @param finalLocation + * @throws PortletException + * @throws IOException + */ + protected void executeMimeResult(final String finalLocation) throws PortletException, IOException { + LOG.debug("Executing mime result"); + PortletContext ctx = PortletActionContext.getPortletContext(); + PortletRequest req = PortletActionContext.getRequest(); + MimeResponse res = (MimeResponse)PortletActionContext.getResponse(); + res.setContentType(contentType); + if (TextUtils.stringSet(title) && res instanceof RenderResponse) { + ((RenderResponse)res).setTitle(title); + } + LOG.debug("Location: " + finalLocation); + if (useDispatcherServlet) { + req.setAttribute(DISPATCH_TO, finalLocation); + PortletRequestDispatcher dispatcher = ctx.getNamedDispatcher(dispatcherServletName); + if(dispatcher == null) { + throw new PortletException("Could not locate dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml file"); + } + dispatcher.include(req, res); + } else { + PortletRequestDispatcher dispatcher = ctx.getRequestDispatcher(finalLocation); + if (dispatcher == null) { + throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'"); + } + dispatcher.include(req, res); + } + } /** * Sets the content type. Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java?rev=722163&r1=722162&r2=722163&view=diff ============================================================================== --- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java (original) +++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java Mon Dec 1 10:34:38 2008 @@ -33,8 +33,8 @@ import javax.portlet.PortletMode; import javax.portlet.PortletSecurityException; import javax.portlet.PortletURL; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; +import javax.portlet.PortletRequest; +import javax.portlet.MimeResponse; import javax.portlet.WindowState; import org.apache.struts2.StrutsException; @@ -47,8 +47,8 @@ * Helper class for creating Portlet URLs. Portlet URLs are fundamentally different from regular * servlet URLs since they never target the application itself; all requests go through the portlet * container and must therefore be programatically constructed using the - * {@link javax.portlet.RenderResponse#createActionURL()} and - * {@link javax.portlet.RenderResponse#createRenderURL()} APIs. + * {@link javax.portlet.MimeResponse#createActionURL()} and + * {@link javax.portlet.MimeResponse#createRenderURL()} APIs. * */ public class PortletUrlHelper { @@ -83,13 +83,13 @@ String scheme, String type, String portletMode, String windowState, boolean includeContext, boolean encodeResult) { StringBuffer resultingAction = new StringBuffer(); - RenderRequest request = PortletActionContext.getRenderRequest(); - RenderResponse response = PortletActionContext.getRenderResponse(); + PortletRequest request = PortletActionContext.getRequest(); + MimeResponse response = (MimeResponse)PortletActionContext.getResponse(); LOG.debug("Creating url. Action = " + action + ", Namespace = " + namespace + ", Type = " + type); namespace = prependNamespace(namespace, portletMode); if (!TextUtils.stringSet(portletMode)) { - portletMode = PortletActionContext.getRenderRequest().getPortletMode().toString(); + portletMode = PortletActionContext.getRequest().getPortletMode().toString(); } String result = null; int paramStartIndex = action.indexOf('?'); @@ -170,7 +170,7 @@ */ private static String prependNamespace(String namespace, String portletMode) { StringBuffer sb = new StringBuffer(); - PortletMode mode = PortletActionContext.getRenderRequest().getPortletMode(); + PortletMode mode = PortletActionContext.getRequest().getPortletMode(); if(TextUtils.stringSet(portletMode)) { mode = new PortletMode(portletMode); } @@ -228,8 +228,8 @@ throw new StrutsException("Encoding "+ENCODING+" not found"); } } - RenderResponse resp = PortletActionContext.getRenderResponse(); - RenderRequest req = PortletActionContext.getRenderRequest(); + MimeResponse resp = (MimeResponse)PortletActionContext.getResponse(); + PortletRequest req = PortletActionContext.getRequest(); return resp.encodeURL(req.getContextPath() + sb.toString()); } @@ -261,12 +261,12 @@ /** * Convert the given String to a WindowState object. * - * @param portletReq The RenderRequest. + * @param portletReq The PortletRequest. * @param windowState The WindowState as a String. * @return The WindowState that mathces the windowState String, or if * the Sring is blank, the current WindowState. */ - private static WindowState getWindowState(RenderRequest portletReq, + private static WindowState getWindowState(PortletRequest portletReq, String windowState) { WindowState state = portletReq.getWindowState(); if (TextUtils.stringSet(windowState)) { @@ -288,12 +288,12 @@ /** * Convert the given String to a PortletMode object. * - * @param portletReq The RenderRequest. + * @param portletReq The PortletRequest. * @param portletMode The PortletMode as a String. * @return The PortletMode that mathces the portletMode String, or if * the Sring is blank, the current PortletMode. */ - private static PortletMode getPortletMode(RenderRequest portletReq, + private static PortletMode getPortletMode(PortletRequest portletReq, String portletMode) { PortletMode mode = portletReq.getPortletMode();