Author: lukaszlenart Date: Fri Sep 7 05:48:49 2012 New Revision: 1381887 URL: http://svn.apache.org/viewvc?rev=1381887&view=rev Log: WW-2749 adds support for Tiles in Porlets as a dedicated plugin with new PortletTilesResult
Added: struts/struts2/trunk/plugins/portlet-tiles/ struts/struts2/trunk/plugins/portlet-tiles/pom.xml struts/struts2/trunk/plugins/portlet-tiles/src/ struts/struts2/trunk/plugins/portlet-tiles/src/main/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/ struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/LICENSE.txt - copied unchanged from r1381604, struts/struts2/trunk/plugins/portlet/src/main/resources/LICENSE.txt struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/NOTICE.txt - copied unchanged from r1381604, struts/struts2/trunk/plugins/portlet/src/main/resources/NOTICE.txt struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/struts-plugin.xml Modified: struts/struts2/trunk/plugins/pom.xml struts/struts2/trunk/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java Modified: struts/struts2/trunk/plugins/pom.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/pom.xml?rev=1381887&r1=1381886&r2=1381887&view=diff ============================================================================== --- struts/struts2/trunk/plugins/pom.xml (original) +++ struts/struts2/trunk/plugins/pom.xml Fri Sep 7 05:48:49 2012 @@ -57,6 +57,7 @@ <module>dojo</module> <module>rest</module> <module>portlet</module> + <module>portlet-tiles</module> <module>junit</module> <module>testng</module> <module>dwr</module> Added: struts/struts2/trunk/plugins/portlet-tiles/pom.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet-tiles/pom.xml?rev=1381887&view=auto ============================================================================== --- struts/struts2/trunk/plugins/portlet-tiles/pom.xml (added) +++ struts/struts2/trunk/plugins/portlet-tiles/pom.xml Fri Sep 7 05:48:49 2012 @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/* + * $Id: pom.xml 1337583 2012-05-12 16:06:55Z 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. + */ +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-plugins</artifactId> + <version>2.3.5-SNAPSHOT</version> + </parent> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-portlet-tiles-plugin</artifactId> + <packaging>jar</packaging> + <name>Struts 2 Portlet Tiles Plugin</name> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/portlet-tiles/</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/struts/struts2/trunk/plugins/portlet-tiles/</developerConnection> + <url>http://svn.apache.org/viewcvs.cgi/struts/struts2/trunk/plugins/portlet-tiles/</url> + </scm> + + <dependencies> + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-tiles-plugin</artifactId> + </dependency> + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-portlet-plugin</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.portlet</groupId> + <artifactId>portlet-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.tiles</groupId> + <artifactId>tiles-jsp</artifactId> + <scope>runtime</scope> + </dependency> + </dependencies> +</project> Added: struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java?rev=1381887&view=auto ============================================================================== --- struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java (added) +++ struts/struts2/trunk/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java Fri Sep 7 05:48:49 2012 @@ -0,0 +1,78 @@ +package org.apache.struts2.views.tiles; + +import com.opensymphony.xwork2.ActionInvocation; +import freemarker.template.TemplateException; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.portlet.PortletConstants; +import org.apache.struts2.portlet.context.PortletActionContext; +import org.apache.tiles.TilesContainer; +import org.apache.tiles.TilesException; +import org.apache.tiles.access.TilesAccess; + +import javax.portlet.ActionResponse; +import javax.portlet.PortletException; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +/** + * JIRA WW-2749 (STRUTS). + */ +public class PortletTilesResult extends ServletDispatcherResult { + + private static final long serialVersionUID = -3806939435493086244L; + + public PortletTilesResult() { + super(); + } + + public PortletTilesResult(String location) { + super(location); + } + + // FIXME PATCH du JIRA WW-2749 (STRUTS) + public void doExecute(String location, ActionInvocation invocation) + throws IOException, TemplateException, PortletException, TilesException { + + if (PortletActionContext.getPhase().isAction() || PortletActionContext.getPhase().isEvent()) { + executeActionResult(location, invocation); + } else { + executeRenderResult(location); + } + } + + /** + * @param location + * @throws TilesException + */ + protected void executeRenderResult(String location) throws TilesException { + setLocation(location); + + ServletContext servletContext = ServletActionContext.getServletContext(); + TilesContainer container = TilesAccess.getContainer(servletContext); + + HttpServletRequest request = ServletActionContext.getRequest(); + HttpServletResponse response = ServletActionContext.getResponse(); + + container.render(location, request, response); + } + + /** + * @param location + * @param invocation + */ + protected void executeActionResult(String location, ActionInvocation invocation) { + ActionResponse res = PortletActionContext.getActionResponse(); + + res.setRenderParameter(PortletConstants.ACTION_PARAM, "tilesDirect"); + + Map<String, Object> sessionMap = invocation.getInvocationContext().getSession(); + sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location); + + res.setRenderParameter(PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode().toString()); + } + +} Added: struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/struts-plugin.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/struts-plugin.xml?rev=1381887&view=auto ============================================================================== --- struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/struts-plugin.xml (added) +++ struts/struts2/trunk/plugins/portlet-tiles/src/main/resources/struts-plugin.xml Fri Sep 7 05:48:49 2012 @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- +/* + * $Id: struts-plugin.xml 1221225 2011-12-20 12:22:28Z 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. + */ +--> +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" + "http://struts.apache.org/dtds/struts-2.3.dtd"> + +<struts> + + <package name="struts-portlet-tiles-default" extends="struts-portlet-default"> + + <result-types> + <result-type name="tiles" class="org.apache.struts2.views.tiles.PortletTilesResult"/> + </result-types> + + <action name="tilesDirect" class="org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction"> + <result type="tiles" name="success">${location}</result> + </action> + + </package> + +</struts> Modified: struts/struts2/trunk/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java?rev=1381887&r1=1381886&r2=1381887&view=diff ============================================================================== --- struts/struts2/trunk/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java (original) +++ struts/struts2/trunk/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java Fri Sep 7 05:48:49 2012 @@ -21,21 +21,19 @@ package org.apache.struts2.tiles; -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.views.freemarker.FreemarkerResult; -import org.apache.tiles.context.TilesRequestContext; -import org.apache.tiles.context.TilesRequestContextWrapper; - import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.views.freemarker.FreemarkerResult; +import org.apache.tiles.context.TilesRequestContext; +import org.apache.tiles.context.TilesRequestContextWrapper; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * Default implementation of TilesUtil. @@ -52,7 +50,6 @@ public class StrutsTilesRequestContext e private static final Logger LOG = LoggerFactory.getLogger(StrutsTilesRequestContext.class); - /** * The mask used to detect requests which should be intercepted. */ @@ -74,14 +71,13 @@ public class StrutsTilesRequestContext e * @param mask * @param context */ - public StrutsTilesRequestContext(TilesRequestContext context, - String mask) { + public StrutsTilesRequestContext(TilesRequestContext context, String mask) { super(context); this.mask = mask; } public void dispatch(String include) throws IOException { - if (include.endsWith(mask)) { + if (include.endsWith(mask) || include.endsWith(".jsp")) { // FIXME This way FreeMarker results still don't have a content-type! include(include); } else {