Skip to content

Commit

Permalink
WW-4584 Upgrades Tiles plugin to Tiles 3
Browse files Browse the repository at this point in the history
Also drops existing Tiles 3 plugin
  • Loading branch information
lukaszlenart committed Jan 18, 2016
2 parents 294394b + 9337512 commit d923c7c
Show file tree
Hide file tree
Showing 24 changed files with 772 additions and 862 deletions.
5 changes: 0 additions & 5 deletions apps/showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>

<!-- The Servlet API mocks in Spring Framework 4.x only supports Servlet 3.0 and higher.
This is only necessary in tests-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ protected ScopesHashModel buildScopesHashModel(ServletContext servletContext, Ht
servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel);
}
TaglibFactory taglibs = new TaglibFactory(servletContext);
taglibs.setObjectWrapper(wrapper);
servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs);
}
model.put(KEY_APPLICATION, servletContextModel);
Expand Down
1 change: 0 additions & 1 deletion plugins/bean-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>

Expand Down
1 change: 0 additions & 1 deletion plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<module>spring</module>
<module>testng</module>
<module>tiles</module>
<module>tiles3</module>
</modules>

<dependencies>
Expand Down
4 changes: 4 additions & 0 deletions plugins/portlet-tiles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-portlet</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
/*
* $Id$
*
* 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.views.tiles;

import com.opensymphony.xwork2.ActionInvocation;
import freemarker.template.TemplateException;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.result.ServletDispatcherResult;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.result.ServletDispatcherResult;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.TilesException;
import org.apache.tiles.access.TilesAccess;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
import org.apache.tiles.request.portlet.RenderPortletRequest;

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 javax.portlet.PortletContext;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.util.Map;

/**
* JIRA WW-2749 (STRUTS).
* Dedicated Tile result to be used in Portlet environment
*
* WW-2749
*/
public class PortletTilesResult extends ServletDispatcherResult {

private static final long serialVersionUID = -3806939435493086244L;
public static final String TILES_ACTION_NAME = "tilesDirect";

public PortletTilesResult() {
super();
Expand All @@ -33,46 +55,60 @@ 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 {

public void doExecute(String location, ActionInvocation invocation) throws Exception {
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);
PortletContext portletContext = PortletActionContext.getPortletContext();
RenderRequest request = PortletActionContext.getRenderRequest();
RenderResponse response = PortletActionContext.getRenderResponse();

HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
TilesContainer container = getCurrentContainer(request, portletContext);
ApplicationContext applicationContext = container.getApplicationContext();
Request currentRequest = new RenderPortletRequest(applicationContext, portletContext, request, response);

container.render(location, request, response);
container.render(location, currentRequest);
}

/**
* @param location
* @param invocation
*/
protected void executeActionResult(String location, ActionInvocation invocation) {
ActionResponse res = PortletActionContext.getActionResponse();

res.setRenderParameter(PortletConstants.ACTION_PARAM, "tilesDirect");
res.setRenderParameter(PortletConstants.ACTION_PARAM, TILES_ACTION_NAME);

Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location);

res.setRenderParameter(PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode().toString());
}

protected TilesContainer getCurrentContainer(javax.portlet.PortletRequest request, PortletContext context) {

TilesContainer container = (TilesContainer) request.getAttribute(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME);

if (container == null) {
container = getContainer(context);
request.setAttribute(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
}

return container;
}

protected TilesContainer getContainer(PortletContext context) {
return getContainer(context, TilesAccess.CONTAINER_ATTRIBUTE);
}

protected TilesContainer getContainer(PortletContext context, String key) {
if (key == null) {
key = TilesAccess.CONTAINER_ATTRIBUTE;
}
return (TilesContainer) context.getAttribute(key);
}

}
39 changes: 37 additions & 2 deletions plugins/tiles/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,56 @@
<name>Struts 2 Tiles Plugin</name>

<dependencies>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-jsp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-ognl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-el</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Loading

0 comments on commit d923c7c

Please sign in to comment.