Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0667B46DE for ; Thu, 23 Jun 2011 20:19:11 +0000 (UTC) Received: (qmail 97365 invoked by uid 500); 23 Jun 2011 20:19:10 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 97337 invoked by uid 500); 23 Jun 2011 20:19:10 -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 97330 invoked by uid 99); 23 Jun 2011 20:19:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2011 20:19:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Thu, 23 Jun 2011 20:19:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3985923888BD for ; Thu, 23 Jun 2011 20:18:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1139061 [1/5] - in /struts/archive/plugins: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/struts2/ src/main/java/org/apache/struts2/components/ src/main/java/org/apache/struts2/portl... Date: Thu, 23 Jun 2011 20:18:46 -0000 To: commits@struts.apache.org From: jogep@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110623201847.3985923888BD@eris.apache.org> Author: jogep Date: Thu Jun 23 20:18:43 2011 New Revision: 1139061 URL: http://svn.apache.org/viewvc?rev=1139061&view=rev Log: Move Portlet1 Plugin to archive Added: struts/archive/plugins/pom.xml struts/archive/plugins/src/ struts/archive/plugins/src/main/ struts/archive/plugins/src/main/java/ struts/archive/plugins/src/main/java/org/ struts/archive/plugins/src/main/java/org/apache/ struts/archive/plugins/src/main/java/org/apache/struts2/ struts/archive/plugins/src/main/java/org/apache/struts2/components/ struts/archive/plugins/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletApplicationMap.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletConfigAware.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletPreferencesAware.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletPrincipalProxy.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/interceptor/ServletPortletPreferences.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/result/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/result/PortletResult.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletHttpSession.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletConfig.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletContext.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletInputStream.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletOutputStream.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequest.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequestDispatcher.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/PortletServletResponse.java struts/archive/plugins/src/main/java/org/apache/struts2/portlet/servlet/package.html struts/archive/plugins/src/main/java/org/apache/struts2/portlet/util/ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java struts/archive/plugins/src/main/java/org/apache/struts2/views/ struts/archive/plugins/src/main/java/org/apache/struts2/views/freemarker/ struts/archive/plugins/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java struts/archive/plugins/src/main/resources/ struts/archive/plugins/src/main/resources/LICENSE.txt struts/archive/plugins/src/main/resources/NOTICE.txt struts/archive/plugins/src/main/resources/struts-plugin.xml struts/archive/plugins/src/test/ struts/archive/plugins/src/test/java/ struts/archive/plugins/src/test/java/org/ struts/archive/plugins/src/test/java/org/apache/ struts/archive/plugins/src/test/java/org/apache/struts2/ struts/archive/plugins/src/test/java/org/apache/struts2/components/ struts/archive/plugins/src/test/java/org/apache/struts2/components/PortletUrlRendererTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/context/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/result/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/PortletServletRequestTest.java struts/archive/plugins/src/test/java/org/apache/struts2/portlet/util/ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java struts/archive/plugins/src/test/java/org/apache/struts2/views/ struts/archive/plugins/src/test/java/org/apache/struts2/views/freemarker/ struts/archive/plugins/src/test/java/org/apache/struts2/views/freemarker/PortletFreemarkerResultTest.java struts/archive/plugins/src/test/java/org/apache/struts2/views/jsp/ struts/archive/plugins/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java Added: struts/archive/plugins/pom.xml URL: http://svn.apache.org/viewvc/struts/archive/plugins/pom.xml?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/pom.xml (added) +++ struts/archive/plugins/pom.xml Thu Jun 23 20:18:43 2011 @@ -0,0 +1,151 @@ + + + + 4.0.0 + + org.apache.struts + struts2-plugins + 2.3.1-SNAPSHOT + + org.apache.struts + struts2-portlet-plugin + jar + Struts 2 Portlet Plugin + + + scm:svn:http://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/portlet/ + scm:svn:https://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/portlet/ + http://svn.apache.org/viewcvs.cgi/struts/struts2/trunk/plugins/portlet/ + + + + + junit + junit + test + + + ${project.groupId} + struts2-junit-plugin + ${project.version} + test + + + + javax.servlet + jsp-api + provided + + + + commons-lang + commons-lang + + + + + org.apache.velocity + velocity + true + + + + org.apache.velocity + velocity-tools + true + + + + + portlet-api + portlet-api + provided + + + + mockobjects + mockobjects-jdk1.3-j2ee1.3 + test + + + + org.easymock + easymock + test + + + jmock + jmock + test + + + + jmock + jmock-cglib + test + + + + mockobjects + mockobjects-core + test + + + + log4j + log4j + test + + + + + org.springframework + spring-test + 2.5.6 + test + + + org.springframework + spring-webmvc-portlet + 2.5.6 + test + + + org.springframework + spring-core + 2.5.6 + test + + + commons-fileupload + commons-fileupload + test + + + cglib + cglib + test + + + Added: struts/archive/plugins/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,186 @@ +/* + * $Id: PortletUrlRenderer.java 1076544 2011-03-03 07:19:37Z lukaszlenart $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.components; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.inject.Inject; +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.StrutsException; +import org.apache.struts2.dispatcher.mapper.ActionMapper; +import org.apache.struts2.portlet.context.PortletActionContext; +import org.apache.struts2.portlet.util.PortletUrlHelper; + +import java.io.IOException; +import java.io.Writer; + +/** + * Implementation of the {@link UrlRenderer} interface that renders URLs for portlet environments. + * + * @see UrlRenderer + * + */ +public class PortletUrlRenderer implements UrlRenderer { + + /** + * The servlet renderer used when not executing in a portlet context. + */ + private UrlRenderer servletRenderer = null; + + public PortletUrlRenderer() { + this.servletRenderer = new ServletUrlRenderer(); + } + + @Inject + public void setActionMapper(ActionMapper actionMapper) { + servletRenderer.setActionMapper(actionMapper); + } + + /** + * {@inheritDoc} + */ + public void renderUrl(Writer writer, UrlProvider urlComponent) { + if(PortletActionContext.getPortletContext() == null || "none".equalsIgnoreCase(urlComponent.getPortletUrlType())) { + servletRenderer.renderUrl(writer, urlComponent); + } + else { + String action = null; + if(urlComponent.getAction() != null) { + action = urlComponent.findString(urlComponent.getAction()); + } + String scheme = urlComponent.getHttpServletRequest().getScheme(); + + if (urlComponent.getScheme() != null) { + scheme = urlComponent.getScheme(); + } + + String result; + urlComponent.setNamespace(urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest())); + if (onlyActionSpecified(urlComponent)) { + result = PortletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(), urlComponent.getPortletUrlType(), + urlComponent.getPortletMode(), urlComponent.getWindowState()); + } else if(onlyValueSpecified(urlComponent)){ + result = PortletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters()); + } + else { + result = createDefaultUrl(urlComponent); + } + String anchor = urlComponent.getAnchor(); + if (StringUtils.isNotEmpty(anchor)) { + result += '#' + urlComponent.findString(anchor); + } + + String var = urlComponent.getVar(); + + if (var != null) { + urlComponent.putInContext(result); + + // add to the request and page scopes as well + urlComponent.getHttpServletRequest().setAttribute(var, result); + } else { + try { + writer.write(result); + } catch (IOException e) { + throw new StrutsException("IOError: " + e.getMessage(), e); + } + } + } + } + + private String createDefaultUrl(UrlProvider urlComponent) { + String result; + ActionInvocation ai = (ActionInvocation)urlComponent.getStack().getContext().get( + ActionContext.ACTION_INVOCATION); + String action = ai.getProxy().getActionName(); + result = PortletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(), + urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState()); + return result; + } + + private boolean onlyValueSpecified(UrlProvider urlComponent) { + return urlComponent.getValue() != null && urlComponent.getAction() == null; + } + + private boolean onlyActionSpecified(UrlProvider urlComponent) { + return urlComponent.getValue() == null && urlComponent.getAction() != null; + } + + /** + * {@inheritDoc} + */ + public void renderFormUrl(Form formComponent) { + if(PortletActionContext.getPortletContext() == null) { + servletRenderer.renderFormUrl(formComponent); + } + else { + String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), + formComponent.request); + String action = null; + if (formComponent.action != null) { + action = formComponent.findString(formComponent.action); + } + else { + ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(ActionContext.ACTION_INVOCATION); + action = ai.getProxy().getActionName(); + } + String type = "action"; + if (StringUtils.isNotEmpty(formComponent.method)) { + if ("GET".equalsIgnoreCase(formComponent.method.trim())) { + type = "render"; + } + } + if (action != null) { + String result = PortletUrlHelper.buildUrl(action, namespace, null, + formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState); + formComponent.addParameter("action", result); + + + // name/id: cut out anything between / and . should be the id and + // name + String id = formComponent.getId(); + if (id == null) { + int slash = action.lastIndexOf('/'); + int dot = action.indexOf('.', slash); + if (dot != -1) { + id = action.substring(slash + 1, dot); + } else { + id = action.substring(slash + 1); + } + formComponent.addParameter("id", formComponent.escape(id)); + } + } + } + + } + + public void beforeRenderUrl(UrlProvider urlComponent) { + if(PortletActionContext.getPortletContext() == null) { + servletRenderer.beforeRenderUrl(urlComponent); + } + } + + public void setServletRenderer(UrlRenderer nonPortletRenderer) { + this.servletRenderer = nonPortletRenderer; + + } + +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,140 @@ +/* + * $Id: PortletActionConstants.java 671156 2008-06-24 12:33:59Z nilsga $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet; + +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.portlet.dispatcher.DispatcherServlet; + +/** + * Interface defining some constants used in the Struts portlet implementation + * + */ +public interface PortletActionConstants { + /** + * Default action name to use when no default action has been configured in the portlet + * init parameters. + */ + String DEFAULT_ACTION_NAME = "default"; + + /** + * Action name parameter name + */ + String ACTION_PARAM = "struts.portlet.action"; + + /** + * Key for parameter holding the last executed portlet mode. + */ + String MODE_PARAM = "struts.portlet.mode"; + + /** + * Key used for looking up and storing the portlet phase + */ + String PHASE = "struts.portlet.phase"; + + /** + * Constant used for the render phase ( + * {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)}) + */ + Integer RENDER_PHASE = new Integer(1); + + /** + * Constant used for the event phase ( + * {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)}) + */ + Integer EVENT_PHASE = new Integer(2); + + /** + * Key used for looking up and storing the + * {@link javax.portlet.PortletRequest} + */ + String REQUEST = "struts.portlet.request"; + + /** + * Key used for looking up and storing the + * {@link javax.portlet.PortletResponse} + */ + String RESPONSE = "struts.portlet.response"; + + /** + * Key used for looking up and storing the action that was invoked in the event phase. + */ + String EVENT_ACTION = "struts.portlet.eventAction"; + + /** + * Key used for looking up and storing the + * {@link javax.portlet.PortletConfig} + */ + String PORTLET_CONFIG = "struts.portlet.config"; + + /** + * Name of the action used as error handler + */ + String ERROR_ACTION = "errorHandler"; + + /** + * Key for the portlet namespace stored in the + * {@link org.apache.struts2.portlet.context.PortletActionContext}. + */ + String PORTLET_NAMESPACE = "struts.portlet.portletNamespace"; + + /** + * Key for the mode-to-namespace map stored in the + * {@link org.apache.struts2.portlet.context.PortletActionContext}. + */ + String MODE_NAMESPACE_MAP = "struts.portlet.modeNamespaceMap"; + + /** + * Key for the default action name for the portlet, stored in the + * {@link org.apache.struts2.portlet.context.PortletActionContext}. + */ + String DEFAULT_ACTION_FOR_MODE = "struts.portlet.defaultActionForMode"; + + /** + * Key for request attribute indicating if the action has been reset. + */ + String ACTION_RESET = "struts.portlet.actionReset"; + + /** + * Key for session attribute indicating the location of the render direct action. + */ + String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation"; + + /** + * Key for the dispatch instruction for the {@link DispatcherServlet} + */ + String DISPATCH_TO = "struts.portlet.dispatchTo"; + + /** + * Session key where the value stack from the event phase is stored. + */ + String STACK_FROM_EVENT_PHASE = "struts.portlet.valueStackFromEventPhase"; + + /** + * Default name of dispatcher servlet in web.xml + */ + String DEFAULT_DISPATCHER_SERVLET_NAME = "Struts2PortletDispatcherServlet"; + + /** + * Key for the action mapping in the context + */ + String ACTION_MAPPING = ServletActionContext.ACTION_MAPPING; +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletApplicationMap.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletApplicationMap.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletApplicationMap.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletApplicationMap.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,207 @@ +/* + * $Id: PortletApplicationMap.java 651946 2008-04-27 13:41:38Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet; + +import java.io.Serializable; +import java.util.AbstractMap; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.portlet.PortletContext; + +/** + * Portlet specific {@link java.util.Map} implementation representing the + * {@link javax.portlet.PortletContext} of a Portlet. + * + */ +public class PortletApplicationMap extends AbstractMap implements Serializable { + + private static final long serialVersionUID = 2296107511063504414L; + + private PortletContext context; + + private Set entries; + + /** + * Creates a new map object given the {@link PortletContext}. + * + * @param ctx The portlet context. + */ + public PortletApplicationMap(PortletContext ctx) { + this.context = ctx; + } + + /** + * Removes all entries from the Map and removes all attributes from the + * portlet context. + */ + public void clear() { + entries = null; + + Enumeration e = context.getAttributeNames(); + + while (e.hasMoreElements()) { + context.removeAttribute(e.nextElement().toString()); + } + } + + /** + * Creates a Set of all portlet context attributes as well as context init + * parameters. + * + * @return a Set of all portlet context attributes as well as context init + * parameters. + */ + public Set entrySet() { + if (entries == null) { + entries = new HashSet(); + + // Add portlet context attributes + Enumeration enumeration = context.getAttributeNames(); + + while (enumeration.hasMoreElements()) { + final String key = enumeration.nextElement().toString(); + final Object value = context.getAttribute(key); + entries.add(new Map.Entry() { + public boolean equals(Object obj) { + Map.Entry entry = (Map.Entry) obj; + + return ((key == null) ? (entry.getKey() == null) : key + .equals(entry.getKey())) + && ((value == null) ? (entry.getValue() == null) + : value.equals(entry.getValue())); + } + + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) + ^ ((value == null) ? 0 : value.hashCode()); + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object obj) { + context.setAttribute(key.toString(), obj); + + return value; + } + }); + } + + // Add portlet context init params + enumeration = context.getInitParameterNames(); + + while (enumeration.hasMoreElements()) { + final String key = enumeration.nextElement().toString(); + final Object value = context.getInitParameter(key); + entries.add(new Map.Entry() { + public boolean equals(Object obj) { + Map.Entry entry = (Map.Entry) obj; + + return ((key == null) ? (entry.getKey() == null) : key + .equals(entry.getKey())) + && ((value == null) ? (entry.getValue() == null) + : value.equals(entry.getValue())); + } + + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) + ^ ((value == null) ? 0 : value.hashCode()); + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object obj) { + context.setAttribute(key.toString(), obj); + + return value; + } + }); + } + } + + return entries; + } + + /** + * Returns the portlet context attribute or init parameter based on the + * given key. If the entry is not found, null is returned. + * + * @param key + * the entry key. + * @return the portlet context attribute or init parameter or null + * if the entry is not found. + */ + public Object get(Object key) { + // Try context attributes first, then init params + // This gives the proper shadowing effects + String keyString = key.toString(); + Object value = context.getAttribute(keyString); + + return (value == null) ? context.getInitParameter(keyString) : value; + } + + /** + * Sets a portlet context attribute given a attribute name and value. + * + * @param key + * the name of the attribute. + * @param value + * the value to set. + * @return the attribute that was just set. + */ + public Object put(Object key, Object value) { + entries = null; + context.setAttribute(key.toString(), value); + + return get(key); + } + + /** + * Removes the specified portlet context attribute. + * + * @param key + * the attribute to remove. + * @return the entry that was just removed. + */ + public Object remove(Object key) { + entries = null; + + Object value = get(key); + context.removeAttribute(key.toString()); + + return value; + } +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,158 @@ +/* + * $Id: PortletRequestMap.java 651946 2008-04-27 13:41:38Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet; + +import java.util.AbstractMap; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +import javax.portlet.PortletRequest; + +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; + +/** + * A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes. + * + */ +public class PortletRequestMap extends AbstractMap { + + private static final Logger LOG = LoggerFactory.getLogger(PortletRequestMap.class); + + private Set entries = null; + private PortletRequest request = null; + + /** + * Saves the request to use as the backing for getting and setting values + * + * @param request the portlet request. + */ + public PortletRequestMap(PortletRequest request) { + this.request = request; + } + + /** + * Removes all attributes from the request as well as clears entries in this + * map. + */ + public void clear() { + entries = null; + Enumeration keys = request.getAttributeNames(); + + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + request.removeAttribute(key); + } + } + + /** + * Returns a Set of attributes from the portlet request. + * + * @return a Set of attributes from the portlet request. + */ + public Set entrySet() { + if (entries == null) { + entries = new HashSet(); + + Enumeration enumeration = request.getAttributeNames(); + + while (enumeration.hasMoreElements()) { + final String key = enumeration.nextElement().toString(); + final Object value = request.getAttribute(key); + entries.add(new Entry() { + public boolean equals(Object obj) { + Entry entry = (Entry) obj; + + return ((key == null) ? (entry.getKey() == null) : key + .equals(entry.getKey())) + && ((value == null) ? (entry.getValue() == null) + : value.equals(entry.getValue())); + } + + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) + ^ ((value == null) ? 0 : value.hashCode()); + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object obj) { + request.setAttribute(key, obj); + + return value; + } + }); + } + } + + return entries; + } + + /** + * Returns the request attribute associated with the given key or + * null if it doesn't exist. + * + * @param key the name of the request attribute. + * @return the request attribute or null if it doesn't exist. + */ + public Object get(Object key) { + return request.getAttribute(key.toString()); + } + + /** + * Saves an attribute in the request. + * + * @param key the name of the request attribute. + * @param value the value to set. + * @return the object that was just set. + */ + public Object put(Object key, Object value) { + entries = null; + request.setAttribute(key.toString(), value); + + return get(key); + } + + /** + * Removes the specified request attribute. + * + * @param key the name of the attribute to remove. + * @return the value that was removed or null if the value was + * not found (and hence, not removed). + */ + public Object remove(Object key) { + entries = null; + + Object value = get(key); + request.removeAttribute(key.toString()); + + return value; + } + +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,163 @@ +/* + * $Id: PortletSessionMap.java 651946 2008-04-27 13:41:38Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet; + +import java.util.AbstractMap; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.portlet.PortletRequest; +import javax.portlet.PortletSession; + +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; + +/** + * A simple implementation of the {@link java.util.Map} interface to handle a collection of portlet session + * attributes. The {@link #entrySet()} method enumerates over all session attributes and creates a Set of entries. + * Note, this will occur lazily - only when the entry set is asked for. + * + */ +public class PortletSessionMap extends AbstractMap { + + private static final Logger LOG = LoggerFactory.getLogger(PortletSessionMap.class); + + private PortletSession session = null; + private Set entries = null; + + /** + * Creates a new session map given a portlet request. + * + * @param request the portlet request object. + */ + public PortletSessionMap(PortletRequest request) { + this.session = request.getPortletSession(); + } + + /** + * @see java.util.Map#entrySet() + */ + public Set entrySet() { + synchronized (session) { + if (entries == null) { + entries = new HashSet(); + + Enumeration enumeration = session.getAttributeNames(); + + while (enumeration.hasMoreElements()) { + final String key = enumeration.nextElement().toString(); + final Object value = session.getAttribute(key); + entries.add(new Map.Entry() { + public boolean equals(Object obj) { + Map.Entry entry = (Map.Entry) obj; + + return ((key == null) ? (entry.getKey() == null) + : key.equals(entry.getKey())) + && ((value == null) ? (entry.getValue() == null) + : value.equals(entry.getValue())); + } + + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) + ^ ((value == null) ? 0 : value.hashCode()); + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object obj) { + session.setAttribute(key, obj); + + return value; + } + }); + } + } + } + + return entries; + } + + /** + * Returns the session attribute associated with the given key or + * null if it doesn't exist. + * + * @param key the name of the session attribute. + * @return the session attribute or null if it doesn't exist. + */ + public Object get(Object key) { + synchronized (session) { + return session.getAttribute(key.toString()); + } + } + + /** + * Saves an attribute in the session. + * + * @param key the name of the session attribute. + * @param value the value to set. + * @return the object that was just set. + */ + public Object put(Object key, Object value) { + synchronized (session) { + entries = null; + session.setAttribute(key.toString(), value); + + return get(key); + } + } + + /** + * @see java.util.Map#clear() + */ + public void clear() { + synchronized (session) { + entries = null; + session.invalidate(); + } + } + + /** + * Removes the specified session attribute. + * + * @param key the name of the attribute to remove. + * @return the value that was removed or null if the value was + * not found (and hence, not removed). + */ + public Object remove(Object key) { + synchronized (session) { + entries = null; + + Object value = get(key); + session.removeAttribute(key.toString()); + + return value; + } + } +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,241 @@ +/* + * $Id: PortletActionContext.java 724030 2008-12-06 19:32:29Z nilsga $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet.context; + +import java.util.Map; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletContext; +import javax.portlet.PortletRequest; +import javax.portlet.PortletResponse; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.apache.struts2.StrutsStatics; +import org.apache.struts2.dispatcher.mapper.ActionMapping; +import org.apache.struts2.portlet.PortletActionConstants; + +import com.opensymphony.xwork2.ActionContext; + + +/** + * PortletActionContext. ActionContext thread local for the portlet environment. + * + * @version $Revision: 724030 $ $Date: 2008-12-06 20:32:29 +0100 (Sa, 06 Dez 2008) $ + */ +public class PortletActionContext implements PortletActionConstants { + + /** + * Get the PortletConfig of the portlet that is executing. + * + * @return The PortletConfig of the executing portlet. + */ + public static PortletConfig getPortletConfig() { + return (PortletConfig) getContext().get(PORTLET_CONFIG); + } + + /** + * Get the RenderRequest. Can only be invoked in the render phase. + * + * @return The current RenderRequest. + * @throws IllegalStateException If the method is invoked in the wrong phase. + */ + public static RenderRequest getRenderRequest() { + if (!isRender()) { + throw new IllegalStateException( + "RenderRequest cannot be obtained in event phase"); + } + return (RenderRequest) getContext().get(REQUEST); + } + + /** + * Get the RenderResponse. Can only be invoked in the render phase. + * + * @return The current RenderResponse. + * @throws IllegalStateException If the method is invoked in the wrong phase. + */ + public static RenderResponse getRenderResponse() { + if (!isRender()) { + throw new IllegalStateException( + "RenderResponse cannot be obtained in event phase"); + } + return (RenderResponse) getContext().get(RESPONSE); + } + + /** + * Get the ActionRequest. Can only be invoked in the event phase. + * + * @return The current ActionRequest. + * @throws IllegalStateException If the method is invoked in the wrong phase. + */ + public static ActionRequest getActionRequest() { + if (!isEvent()) { + throw new IllegalStateException( + "ActionRequest cannot be obtained in render phase"); + } + return (ActionRequest) getContext().get(REQUEST); + } + + /** + * Get the ActionRequest. Can only be invoked in the event phase. + * + * @return The current ActionRequest. + * @throws IllegalStateException If the method is invoked in the wrong phase. + */ + public static ActionResponse getActionResponse() { + if (!isEvent()) { + throw new IllegalStateException( + "ActionResponse cannot be obtained in render phase"); + } + return (ActionResponse) getContext().get(RESPONSE); + } + + /** + * Get the action namespace of the portlet. Used to organize actions for multiple portlets in + * the same portlet application. + * + * @return The portlet namespace as defined in portlet.xml and struts.xml + */ + public static String getPortletNamespace() { + return (String)getContext().get(PORTLET_NAMESPACE); + } + + /** + * Get the current PortletRequest. + * + * @return The current PortletRequest. + */ + public static PortletRequest getRequest() { + return (PortletRequest) getContext().get(REQUEST); + } + + /** + * Convenience setter for the portlet request. + * @param request + */ + public static void setRequest(PortletRequest request) { + getContext().put(REQUEST, request); + } + + /** + * Get the current PortletResponse + * + * @return The current PortletResponse. + */ + public static PortletResponse getResponse() { + return (PortletResponse) getContext().get(RESPONSE); + } + + /** + * Convenience setter for the portlet response. + * @param response + */ + public static void setResponse(PortletResponse response) { + getContext().put(RESPONSE, response); + } + + /** + * Get the phase that the portlet is executing in. + * + * @return {@link PortletActionConstants#RENDER_PHASE} in render phase, and + * {@link PortletActionConstants#EVENT_PHASE} in the event phase. + */ + public static Integer getPhase() { + return (Integer) getContext().get(PHASE); + } + + /** + * @return true if the Portlet is executing in render phase. + */ + public static boolean isRender() { + return PortletActionConstants.RENDER_PHASE.equals(getPhase()); + } + + /** + * @return true if the Portlet is executing in the event phase. + */ + public static boolean isEvent() { + return PortletActionConstants.EVENT_PHASE.equals(getPhase()); + } + + /** + * @return The current ActionContext. + */ + private static ActionContext getContext() { + return ActionContext.getContext(); + } + + /** + * Check to see if the current request is a portlet request. + * + * @return true if the current request is a portlet request. + */ + public static boolean isPortletRequest() { + return getRequest() != null; + } + + /** + * Get the default action mapping for the current mode. + * + * @return The default action mapping for the current portlet mode. + */ + public static ActionMapping getDefaultActionForMode() { + return (ActionMapping)getContext().get(DEFAULT_ACTION_FOR_MODE); + } + + /** + * Get the namespace to mode mappings. + * + * @return The map of the namespaces for each mode. + */ + public static Map getModeNamespaceMap() { + return (Map)getContext().get(MODE_NAMESPACE_MAP); + } + + /** + * Get the portlet context. + * @return The portlet context. + */ + public static PortletContext getPortletContext() { + return (PortletContext)getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT); + } + + /** + * Convenience setter for the portlet context. + * @param context + */ + public static void setPortletContext(PortletContext context) { + getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, context); + } + + /** + * Gets the action mapping for this context + * + * @return The action mapping + */ + public static ActionMapping getActionMapping() { + return (ActionMapping) getContext().get(ACTION_MAPPING); + } + +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,52 @@ +/* + * $Id: PreparatorServlet.java 1099157 2011-05-03 17:53:55Z jogep $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet.context; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + +import org.apache.struts2.StrutsStatics; + +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; + +/** + * @deprecated + * + * This servlet has been deprecated. Do not use it (WW-2101) + * + */ +public class PreparatorServlet extends HttpServlet implements StrutsStatics { + + private static final long serialVersionUID = 1853399729352984089L; + + private final static Logger LOG = LoggerFactory.getLogger(PreparatorServlet.class); + + @Override + public void init(ServletConfig config) throws ServletException { + if (LOG.isWarnEnabled()) { + LOG.warn("The preparator servlet has been deprecated. It can safely be removed from your web.xml file"); + } + } + +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,69 @@ +/* + * $Id: ServletContextHolderListener.java 1099157 2011-05-03 17:53:55Z jogep $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet.context; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; + +/** + * @deprecated + * + * This listener has been deprecated. Do not use it. (WW-2101) + * + */ +public class ServletContextHolderListener implements ServletContextListener { + + private static ServletContext context = null; + + private final static Logger LOG = LoggerFactory.getLogger(ServletContextHolderListener.class); + + /** + * @return The current servlet context + */ + public static ServletContext getServletContext() { + return context; + } + + /** + * Stores the reference to the {@link ServletContext}. + * + * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) + */ + public void contextInitialized(ServletContextEvent event) { + if (LOG.isWarnEnabled()) { + LOG.warn("The ServletContextHolderListener has been deprecated. It can safely be removed from your web.xml file"); + } + context = event.getServletContext(); + } + + /** + * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) + */ + public void contextDestroyed(ServletContextEvent event) { + context = null; + } + +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,73 @@ +/* + * $Id: DirectRenderFromEventAction.java 651946 2008-04-27 13:41:38Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet.dispatcher; + +import com.opensymphony.xwork2.Action; + +import java.io.Serializable; +import java.util.Map; + +import org.apache.struts2.interceptor.SessionAware; +import org.apache.struts2.portlet.PortletActionConstants; + +/** + * When a portlet is targetted for an event, the portlet will receive two + * portlet requests, one for the event phase, and then followed by a render + * operation. When in the event phase, the action that is executed can't render + * any output. This means that if an action in the XWork configuration is executed in the event + * phase, and the action is set up with a result that should render something, the result can't + * immediately be executed. The portlet needs to "wait" to the render phase to do the + * rendering. + *

+ * When the {@link org.apache.struts2.portlet.result.PortletResult} detects such a + * scenario, instead of executing the actual view, it prepares a couple of render parameters + * specifying this action and the location of the view, which then will be executed in the + * following render request. + */ +public class DirectRenderFromEventAction implements SessionAware, PortletActionConstants, Action, Serializable { + + private static final long serialVersionUID = -1814807772308405785L; + + private String location = null; + + /** + * Get the location of the view. + * + * @return Returns the location. + */ + public String getLocation() { + return location; + } + + /** + * Always return success. + * + * @return SUCCESS + */ + public String execute() throws Exception { + return SUCCESS; + } + + public void setSession(Map session) { + location = (String)session.get(RENDER_DIRECT_LOCATION); + } +} Added: struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java?rev=1139061&view=auto ============================================================================== --- struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java (added) +++ struts/archive/plugins/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java Thu Jun 23 20:18:43 2011 @@ -0,0 +1,56 @@ +/* + * $Id: DispatcherServlet.java 1076544 2011-03-03 07:19:37Z lukaszlenart $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.struts2.portlet.dispatcher; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.dispatcher.StrutsRequestWrapper; +import org.apache.struts2.portlet.PortletActionConstants; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class DispatcherServlet extends HttpServlet implements PortletActionConstants { + + private static final long serialVersionUID = -266147033645951967L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String dispatchTo = (String) request.getAttribute(DISPATCH_TO); + HttpServletRequest wrapper = wrapRequestIfNecessary(request); + if(StringUtils.isNotEmpty(dispatchTo)) { + request.getRequestDispatcher(dispatchTo).include(wrapper, response); + } + } + + private HttpServletRequest wrapRequestIfNecessary(HttpServletRequest request) { + if(!(request instanceof StrutsRequestWrapper)) { + return new StrutsRequestWrapper(request); + } + else { + return request; + } + } + +}