diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml
index 7173275e0..4e6044beb 100644
--- a/apps/showcase/pom.xml
+++ b/apps/showcase/pom.xml
@@ -171,11 +171,6 @@
hibernate-validator5.1.3.Final
-
- org.glassfish
- javax.el
- 3.0.0
-
diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
index ddc7669eb..3323302ad 100644
--- a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
+++ b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
@@ -350,6 +350,7 @@ public class FreemarkerManager {
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);
diff --git a/plugins/bean-validation/pom.xml b/plugins/bean-validation/pom.xml
index b7318efe8..f2500c52b 100644
--- a/plugins/bean-validation/pom.xml
+++ b/plugins/bean-validation/pom.xml
@@ -58,7 +58,6 @@
org.glassfishjavax.el
- 3.0.0test
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 2f1fe76ef..ba4418184 100644
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -59,7 +59,6 @@
springtestngtiles
- tiles3
diff --git a/plugins/portlet-tiles/pom.xml b/plugins/portlet-tiles/pom.xml
index bb8b6e134..8b710b206 100644
--- a/plugins/portlet-tiles/pom.xml
+++ b/plugins/portlet-tiles/pom.xml
@@ -42,6 +42,10 @@
org.apache.strutsstruts2-portlet-plugin
+
+ org.apache.tiles
+ tiles-request-portlet
+ javax.servletjsp-api
diff --git a/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java b/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java
index d10693ceb..f12274b39 100644
--- a/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java
+++ b/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java
@@ -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();
@@ -33,10 +55,7 @@ public class PortletTilesResult extends ServletDispatcherResult {
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 {
@@ -44,30 +63,24 @@ public class PortletTilesResult extends ServletDispatcherResult {
}
}
- /**
- * @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 sessionMap = invocation.getInvocationContext().getSession();
sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location);
@@ -75,4 +88,27 @@ public class PortletTilesResult extends ServletDispatcherResult {
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);
+ }
+
}
diff --git a/plugins/tiles/pom.xml b/plugins/tiles/pom.xml
index 3d2a01c5c..0b964af9d 100644
--- a/plugins/tiles/pom.xml
+++ b/plugins/tiles/pom.xml
@@ -34,21 +34,56 @@
Struts 2 Tiles Plugin
+
+ org.apache.tiles
+ tiles-api
+ org.apache.tilestiles-core
+
+ org.apache.tiles
+ tiles-servlet
+
+
+ org.apache.tiles
+ tiles-request-api
+
+
+ org.apache.tiles
+ tiles-request-jsp
+
+
+ org.apache.tiles
+ tiles-request-servlet
+ org.apache.tilestiles-jsp
- runtime
+
+
+ org.apache.tiles
+ tiles-freemarker
+
+
+ org.apache.tiles
+ tiles-ognl
+
+
+ org.apache.tiles
+ tiles-el
+
+
+ org.glassfish
+ javax.el
+ truejavax.servletjsp-apiprovided
-
UTF-8
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/ConfiguredServletContext.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/ConfiguredServletContext.java
deleted file mode 100644
index dfc1408de..000000000
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/ConfiguredServletContext.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * $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.tiles;
-
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.Servlet;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-
-/**
- * ServletContext implementation which allows Struts
- * to inject initialization parameters into the context
- * in order to reduce the amount of configuration required
- * within web.xml for using Tiles.
- *
- * The specified init parameters are only utilized if
- * they are not explicitaly defined in the web.xml
- *
- * @version $Rev$
- * @since Struts 2.0.1
- */
-@SuppressWarnings("deprecation")
-public class ConfiguredServletContext implements ServletContext {
-
- private ServletContext rootContext;
- private Map initParameters;
-
-
- public ConfiguredServletContext(ServletContext context, Map initParameters) {
- this.rootContext = context;
- this.initParameters = initParameters;
- }
-
- public ServletContext getContext(String string) {
- return rootContext.getContext(string);
- }
-
- public int getMajorVersion() {
- return rootContext.getMajorVersion();
- }
-
- public int getMinorVersion() {
- return rootContext.getMinorVersion();
- }
-
- public String getMimeType(String string) {
- return rootContext.getMimeType(string);
- }
-
- public Set getResourcePaths(String string) {
- return rootContext.getResourcePaths(string);
- }
-
- public URL getResource(String string) throws MalformedURLException {
- return rootContext.getResource(string);
- }
-
- public InputStream getResourceAsStream(String string) {
- return rootContext.getResourceAsStream(string);
- }
-
- public RequestDispatcher getRequestDispatcher(String string) {
- return rootContext.getRequestDispatcher(string);
- }
-
- public RequestDispatcher getNamedDispatcher(String string) {
- return rootContext.getNamedDispatcher(string);
- }
-
- @SuppressWarnings("deprecation")
- public Servlet getServlet(String string) throws ServletException {
- return rootContext.getServlet(string);
- }
-
- @SuppressWarnings("deprecation")
- public Enumeration getServlets() {
- return rootContext.getServlets(); //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @SuppressWarnings("deprecation")
- public Enumeration getServletNames() {
- return rootContext.getServletNames();
- }
-
- public void log(String string) {
- rootContext.log(string);
- }
-
- @SuppressWarnings("deprecation")
- public void log(Exception exception, String string) {
- rootContext.log(exception, string);
- }
-
- public void log(String string, Throwable throwable) {
- rootContext.log(string, throwable);
- }
-
- public String getRealPath(String string) {
- return rootContext.getRealPath(string);
- }
-
- public String getServerInfo() {
- return rootContext.getServerInfo();
- }
-
- public String getInitParameter(String string) {
- String parm = rootContext.getInitParameter(string);
- if (parm == null) {
- return initParameters.get(string);
- }
- return parm;
- }
-
- public Enumeration getInitParameterNames() {
- return new CompositeEnumeration(
- rootContext.getInitParameterNames(),
- initParameters.keySet().iterator());
- }
-
- public Object getAttribute(String string) {
- return rootContext.getAttribute(string);
- }
-
- public Enumeration getAttributeNames() {
- return rootContext.getAttributeNames();
- }
-
- public void setAttribute(String string, Object object) {
- rootContext.setAttribute(string, object);
- }
-
- public void removeAttribute(String string) {
- rootContext.removeAttribute(string);
- }
-
- public String getServletContextName() {
- return rootContext.getServletContextName();
- }
-
- class CompositeEnumeration implements Enumeration {
-
- private Enumeration first;
- private Iterator second;
-
-
- public CompositeEnumeration(Enumeration first, Iterator second) {
- this.first = first;
- this.second = second;
- }
-
- public boolean hasMoreElements() {
- return first.hasMoreElements() || second.hasNext();
- }
-
- public Object nextElement() {
- if (first.hasMoreElements()) {
- return first.nextElement();
- }
-
- return second.next();
- }
- }
-}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
new file mode 100644
index 000000000..6884e9a42
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.tiles;
+
+import org.apache.tiles.request.locale.PostfixedApplicationResource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class StrutsApplicationResource extends PostfixedApplicationResource {
+
+ private final URL url;
+
+ public StrutsApplicationResource(URL url) {
+ super(url.getPath());
+ this.url = url;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ if (new File(url.getPath()).exists()) {
+ return url.openStream();
+ }
+ return null;
+ }
+
+ @Override
+ public long getLastModified() throws IOException {
+ File file = new File(url.getPath());
+ if (file.exists()) {
+ return file.lastModified();
+ }
+ return 0;
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
new file mode 100644
index 000000000..5102eada4
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
@@ -0,0 +1,118 @@
+/*
+ * 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.tiles;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.inject.Container;
+import freemarker.ext.beans.BeanModel;
+import freemarker.template.Configuration;
+import freemarker.template.TemplateException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.views.JspSupportServlet;
+import org.apache.struts2.views.freemarker.FreemarkerManager;
+import org.apache.struts2.views.freemarker.FreemarkerResult;
+import org.apache.struts2.views.freemarker.StrutsBeanWrapper;
+import org.apache.tiles.freemarker.template.TilesFMModelRepository;
+import org.apache.tiles.impl.InvalidTemplateException;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.render.Renderer;
+import org.apache.tiles.request.servlet.ServletUtil;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+public class StrutsFreeMarkerAttributeRenderer implements Renderer {
+
+ private static Logger LOG = LogManager.getLogger(StrutsFreeMarkerAttributeRenderer.class);
+
+ @Override
+ public void render(String path, Request request) throws IOException {
+ if (path != null) {
+ LOG.trace("Rendering freemarker tile [{}]", path);
+
+ ActionContext ctx = readActionContext(request);
+
+ registerTilesBeanModel(ctx);
+
+ FreemarkerResult result = new FreemarkerResult(path);
+ result.setWriter(request.getWriter());
+
+ Container container = ctx.getContainer();
+ container.inject(result);
+
+ try {
+ ActionInvocation invocation = ctx.getActionInvocation();
+ result.doExecute(path, invocation);
+ } catch (TemplateException e) {
+ LOG.error("Exception was thrown during rendering value {}: {}", path, e.getMessage());
+ throw new InvalidTemplateException(e);
+ }
+ } else {
+ LOG.error("Path is null, cannot render template!");
+ throw new InvalidTemplateException("Cannot render a null template");
+ }
+ }
+
+ /**
+ * Depending how Tiles definition was defined, request can an instance of JspRequest (for JSPs)
+ * or a ServletRequest (FreeMarker)
+ */
+ protected ActionContext readActionContext(Request request) {
+ LOG.debug("Obtaining HttpServletRequest based on [{}]", request.getClass().getName());
+
+ HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
+ ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
+
+ if (ctx == null) {
+ LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
+ throw new ConfigurationException("There is no ActionContext for current request!");
+ }
+
+ return ctx;
+ }
+
+ @Override
+ public boolean isRenderable(String path, Request request) {
+ LOG.trace("Checking if path [{}] can be rendered", path);
+ return path != null && path.startsWith("/") && path.endsWith(".ftl");
+ }
+
+ /**
+ * This register dedicated BeanModel to support tiles tags.
+ * It requires {@link org.apache.struts2.views.JspSupportServlet} to be registered in web.xml
+ */
+ protected void registerTilesBeanModel(ActionContext ctx) {
+ ServletContext servletContext = ServletActionContext.getServletContext();
+ Configuration configuration = ctx.getInstance(FreemarkerManager.class).getConfiguration(servletContext);
+
+ StrutsBeanWrapper wrapper = (StrutsBeanWrapper) ctx.getInstance(FreemarkerManager.class).getWrapper();
+
+ LOG.trace("Adding support for Tiles tags, please remember to register {} in web.xml!", JspSupportServlet.class.getName());
+
+ BeanModel tilesBeanModel = new BeanModel(new TilesFMModelRepository(), wrapper);
+ configuration.setSharedVariable("tiles", tilesBeanModel);
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
index 491ee02ab..0cb14f30c 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
@@ -1,6 +1,4 @@
/*
- * $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
@@ -21,73 +19,213 @@
package org.apache.struts2.tiles;
-import org.apache.tiles.TilesApplicationContext;
-import org.apache.tiles.TilesException;
-import org.apache.tiles.context.TilesContextFactory;
-import org.apache.tiles.context.TilesRequestContext;
+import ognl.OgnlException;
+import ognl.OgnlRuntime;
+import ognl.PropertyAccessor;
+import org.apache.tiles.TilesContainer;
import org.apache.tiles.definition.DefinitionsFactory;
-import org.apache.tiles.factory.TilesContainerFactory;
-import org.apache.tiles.impl.BasicTilesContainer;
-import org.apache.tiles.preparer.PreparerFactory;
+import org.apache.tiles.definition.pattern.DefinitionPatternMatcherFactory;
+import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
+import org.apache.tiles.definition.pattern.PrefixedPatternDefinitionResolver;
+import org.apache.tiles.definition.pattern.regexp.RegexpDefinitionPatternMatcherFactory;
+import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
+import org.apache.tiles.el.ELAttributeEvaluator;
+import org.apache.tiles.el.JspExpressionFactoryFactory;
+import org.apache.tiles.el.ScopeELResolver;
+import org.apache.tiles.el.TilesContextBeanELResolver;
+import org.apache.tiles.el.TilesContextELResolver;
+import org.apache.tiles.evaluator.AttributeEvaluatorFactory;
+import org.apache.tiles.evaluator.BasicAttributeEvaluatorFactory;
+import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator;
+import org.apache.tiles.factory.BasicTilesContainerFactory;
+import org.apache.tiles.factory.TilesContainerFactoryException;
+import org.apache.tiles.impl.mgmt.CachingTilesContainer;
+import org.apache.tiles.locale.LocaleResolver;
+import org.apache.tiles.ognl.AnyScopePropertyAccessor;
+import org.apache.tiles.ognl.DelegatePropertyAccessor;
+import org.apache.tiles.ognl.NestedObjectDelegatePropertyAccessor;
+import org.apache.tiles.ognl.OGNLAttributeEvaluator;
+import org.apache.tiles.ognl.PropertyAccessorDelegateFactory;
+import org.apache.tiles.ognl.ScopePropertyAccessor;
+import org.apache.tiles.ognl.TilesApplicationContextNestedObjectExtractor;
+import org.apache.tiles.ognl.TilesContextPropertyAccessorDelegateFactory;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.ApplicationResource;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.render.BasicRendererFactory;
+import org.apache.tiles.request.render.ChainedDelegateRenderer;
+import org.apache.tiles.request.render.Renderer;
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELResolver;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
import java.util.Map;
-
-public class StrutsTilesContainerFactory extends TilesContainerFactory {
-
-
- @Override
- protected void storeContainerDependencies(Object context, Map initParameters, Map configuration, BasicTilesContainer container) throws TilesException {
- TilesContextFactory contextFactory =
- (TilesContextFactory) createFactory(configuration,
- CONTEXT_FACTORY_INIT_PARAM);
-
- contextFactory = new StrutsTilesContextFactory(contextFactory);
-
- DefinitionsFactory defsFactory =
- (DefinitionsFactory) createFactory(configuration,
- DEFINITIONS_FACTORY_INIT_PARAM);
-
- PreparerFactory prepFactory =
- (PreparerFactory) createFactory(configuration,
- PREPARER_FACTORY_INIT_PARAM);
-
- contextFactory.init(configuration);
- TilesApplicationContext tilesContext =
- contextFactory.createApplicationContext(context);
-
- container.setDefinitionsFactory(defsFactory);
- container.setContextFactory(contextFactory);
- container.setPreparerFactory(prepFactory);
- container.setApplicationContext(tilesContext);
- }
+/**
+ * Dedicated Struts factory to build Tiles container with support for:
+ * - Freemarker
+ * - OGNL (as default)
+ * - EL
+ * - Wildcards
+ *
+ * If you need additional features create your own listener and factory,
+ * you can base on code from Tiles' CompleteAutoloadTilesContainerFactory
+ */
+public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
/**
- * Wrapper factory, used to decorate the TilesRequestContext with a
- * FreemarkerResult aware version.
- *
+ * The freemarker renderer name.
*/
- class StrutsTilesContextFactory implements TilesContextFactory {
+ public static final String FREEMARKER_RENDERER_NAME = "freemarker";
- private TilesContextFactory factory;
+ /**
+ * Supported pattern types
+ */
+ public static final String PATTERN_WILDCARD = "WILDCARD";
+ public static final String PATTERN_REGEXP = "REGEXP";
- public StrutsTilesContextFactory(TilesContextFactory factory) {
- this.factory = factory;
+ /**
+ * Default pattern to be used to collect Tiles definitions if user didn't configure any
+ */
+ public static final String TILES_DEFAULT_PATTERN = "tiles*.xml";
+
+ /**
+ * Supported expression languages
+ */
+ public static final String OGNL = "OGNL";
+ public static final String EL = "EL";
+
+ @Override
+ public TilesContainer createDecoratedContainer(TilesContainer originalContainer, ApplicationContext applicationContext) {
+ return new CachingTilesContainer(originalContainer);
+ }
+
+ @Override
+ protected void registerAttributeRenderers(
+ final BasicRendererFactory rendererFactory,
+ final ApplicationContext applicationContext,
+ final TilesContainer container,
+ final AttributeEvaluatorFactory attributeEvaluatorFactory) {
+
+ super.registerAttributeRenderers(rendererFactory, applicationContext, container, attributeEvaluatorFactory);
+
+ StrutsFreeMarkerAttributeRenderer freemarkerRenderer = new StrutsFreeMarkerAttributeRenderer();
+
+ rendererFactory.registerRenderer(FREEMARKER_RENDERER_NAME, freemarkerRenderer);
+ }
+
+ @Override
+ protected Renderer createDefaultAttributeRenderer(
+ BasicRendererFactory rendererFactory,
+ ApplicationContext applicationContext,
+ TilesContainer container,
+ AttributeEvaluatorFactory attributeEvaluatorFactory) {
+
+ ChainedDelegateRenderer retValue = new ChainedDelegateRenderer();
+ retValue.addAttributeRenderer(rendererFactory.getRenderer(DEFINITION_RENDERER_NAME));
+ retValue.addAttributeRenderer(rendererFactory.getRenderer(FREEMARKER_RENDERER_NAME));
+ retValue.addAttributeRenderer(rendererFactory.getRenderer(TEMPLATE_RENDERER_NAME));
+ retValue.addAttributeRenderer(rendererFactory.getRenderer(STRING_RENDERER_NAME));
+ return retValue;
+ }
+
+ @Override
+ protected AttributeEvaluatorFactory createAttributeEvaluatorFactory(
+ ApplicationContext applicationContext,
+ LocaleResolver resolver) {
+
+ BasicAttributeEvaluatorFactory attributeEvaluatorFactory = new BasicAttributeEvaluatorFactory(new DirectAttributeEvaluator());
+ attributeEvaluatorFactory.registerAttributeEvaluator(OGNL, createOGNLEvaluator());
+ attributeEvaluatorFactory.registerAttributeEvaluator(EL, createELEvaluator(applicationContext));
+
+ return attributeEvaluatorFactory;
+ }
+
+ @Override
+ protected PatternDefinitionResolver createPatternDefinitionResolver(Class customizationKeyClass) {
+ DefinitionPatternMatcherFactory wildcardFactory = new WildcardDefinitionPatternMatcherFactory();
+ DefinitionPatternMatcherFactory regexpFactory = new RegexpDefinitionPatternMatcherFactory();
+ PrefixedPatternDefinitionResolver resolver = new PrefixedPatternDefinitionResolver<>();
+
+ resolver.registerDefinitionPatternMatcherFactory(PATTERN_WILDCARD, wildcardFactory);
+ resolver.registerDefinitionPatternMatcherFactory(PATTERN_REGEXP, regexpFactory);
+
+ return resolver;
+ }
+
+ protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
+ return new StrutsTilesLocaleResolver();
+ }
+
+ @Override
+ protected List getSources(ApplicationContext applicationContext) {
+ Collection resources = applicationContext.getResources(getTilesDefinitionPattern(applicationContext.getInitParams()));
+
+ List filteredResources = new ArrayList<>();
+ if (resources != null) {
+ for (ApplicationResource resource : resources) {
+ if (Locale.ROOT.equals(resource.getLocale())) {
+ filteredResources.add(resource);
+ }
+ }
}
- public void init(Map map) {
- factory.init(map);
- }
+ return filteredResources;
+ }
- public TilesApplicationContext createApplicationContext(Object context) {
- return factory.createApplicationContext(context);
+ protected String getTilesDefinitionPattern(Map params) {
+ if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) {
+ return params.get(DefinitionsFactory.DEFINITIONS_CONFIG);
}
+ return TILES_DEFAULT_PATTERN;
+ }
- public TilesRequestContext createRequestContext(
- TilesApplicationContext tilesApplicationContext,
- Object... requestItems) {
- TilesRequestContext context = factory.createRequestContext(tilesApplicationContext, requestItems);
- return new StrutsTilesRequestContext(context);
+ protected ELAttributeEvaluator createELEvaluator(ApplicationContext applicationContext) {
+ ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
+ JspExpressionFactoryFactory efFactory = new JspExpressionFactoryFactory();
+ efFactory.setApplicationContext(applicationContext);
+ evaluator.setExpressionFactory(efFactory.getExpressionFactory());
+ ELResolver elResolver = new CompositeELResolver() {
+ {
+ BeanELResolver beanElResolver = new BeanELResolver(false);
+ add(new ScopeELResolver());
+ add(new TilesContextELResolver(beanElResolver));
+ add(new TilesContextBeanELResolver());
+ add(new ArrayELResolver(false));
+ add(new ListELResolver(false));
+ add(new MapELResolver(false));
+ add(new ResourceBundleELResolver());
+ add(beanElResolver);
+ }
+ };
+ evaluator.setResolver(elResolver);
+ return evaluator;
+ }
+
+ protected OGNLAttributeEvaluator createOGNLEvaluator() {
+ try {
+ PropertyAccessor objectPropertyAccessor = OgnlRuntime.getPropertyAccessor(Object.class);
+ PropertyAccessor applicationContextPropertyAccessor = new NestedObjectDelegatePropertyAccessor<>(
+ new TilesApplicationContextNestedObjectExtractor(), objectPropertyAccessor);
+ PropertyAccessor anyScopePropertyAccessor = new AnyScopePropertyAccessor();
+ PropertyAccessor scopePropertyAccessor = new ScopePropertyAccessor();
+ PropertyAccessorDelegateFactory factory = new TilesContextPropertyAccessorDelegateFactory(
+ objectPropertyAccessor, applicationContextPropertyAccessor, anyScopePropertyAccessor,
+ scopePropertyAccessor);
+ PropertyAccessor tilesRequestAccessor = new DelegatePropertyAccessor<>(factory);
+ OgnlRuntime.setPropertyAccessor(Request.class, tilesRequestAccessor);
+ return new OGNLAttributeEvaluator();
+ } catch (OgnlException e) {
+ throw new TilesContainerFactoryException("Cannot initialize OGNL evaluator", e);
}
}
-}
+
+}
\ No newline at end of file
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesInitializer.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesInitializer.java
new file mode 100644
index 000000000..d0f32f0dd
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesInitializer.java
@@ -0,0 +1,46 @@
+/*
+ * 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.tiles;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.tiles.factory.AbstractTilesContainerFactory;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.startup.AbstractTilesInitializer;
+
+import javax.servlet.ServletContext;
+
+public class StrutsTilesInitializer extends AbstractTilesInitializer {
+
+ private static final Logger LOG = LogManager.getLogger(StrutsTilesInitializer.class);
+
+ @Override
+ protected ApplicationContext createTilesApplicationContext(ApplicationContext preliminaryContext) {
+ LOG.debug("Initializing Tiles wildcard support ...");
+ return new StrutsWildcardServletApplicationContext((ServletContext) preliminaryContext.getContext());
+ }
+
+ @Override
+ protected AbstractTilesContainerFactory createContainerFactory(ApplicationContext context) {
+ LOG.trace("Creating dedicated Struts factory to create Tiles container");
+ return new StrutsTilesContainerFactory();
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesListener.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesListener.java
index b04908af1..cf874b1d0 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesListener.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesListener.java
@@ -1,6 +1,4 @@
/*
- * $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
@@ -21,57 +19,23 @@
package org.apache.struts2.tiles;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import org.apache.tiles.TilesContainer;
-import org.apache.tiles.TilesException;
-import org.apache.tiles.factory.TilesContainerFactory;
-import org.apache.tiles.web.startup.TilesListener;
-
-import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.tiles.startup.TilesInitializer;
+import org.apache.tiles.web.startup.AbstractTilesListener;
/**
- * Listener used to automatically inject ServletContext
- * init parameters so that they don't need to be configured
- * explicitly for tiles integration. This is provided
- * mainly for backwards compatibility with Struts 2.0.1
- * configuration.
+ * Listener used to automatically tie Tiles support into Struts
*
* @since Struts 2.0.2
- * @version $Rev$
- *
*/
-public class StrutsTilesListener extends TilesListener {
+public class StrutsTilesListener extends AbstractTilesListener {
private static final Logger LOG = LogManager.getLogger(StrutsTilesListener.class);
- private static final Map INIT;
-
- static {
- INIT = new HashMap();
- INIT.put(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM,
- StrutsTilesContainerFactory.class.getName());
+ @Override
+ protected TilesInitializer createTilesInitializer() {
+ LOG.info("Starting Struts Tiles 2 integration ...");
+ return new StrutsTilesInitializer();
}
-
- protected TilesContainer createContainer(ServletContext context)
- throws TilesException {
- if(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM) == null) {
- context = decorate(context);
- }
- else {
- if (LOG.isWarnEnabled()) {
- LOG.warn("Tiles container factory is explicitly set. Not injecting struts configuration.");
- }
- }
- return super.createContainer(context);
- }
-
- protected ServletContext decorate(ServletContext context) {
- return new ConfiguredServletContext(context, INIT);
- }
-
-}
+}
\ No newline at end of file
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
new file mode 100644
index 000000000..2c0ef9d66
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
@@ -0,0 +1,54 @@
+/*
+ * 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.tiles;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.LocaleProvider;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.tiles.locale.LocaleResolver;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.servlet.ServletUtil;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Locale;
+
+public class StrutsTilesLocaleResolver implements LocaleResolver {
+
+ private static Logger LOG = LogManager.getLogger(StrutsTilesLocaleResolver.class);
+
+ @Override
+ public Locale resolveLocale(Request request) {
+ HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
+ ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
+
+ if (ctx == null) {
+ LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
+ throw new ConfigurationException("There is no ActionContext for current request!");
+ }
+
+ LocaleProvider provider = ctx.getInstance(LocaleProvider.class);
+
+ return provider.getLocale();
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java
deleted file mode 100644
index d9319a4f1..000000000
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesRequestContext.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * $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.tiles;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.inject.Container;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
-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.
- * This class contains default implementation of utilities. This implementation
- * is intended to be used without Struts.
- *
- *
- *
- * TilesUtilImpl implementation used to intercept .ftl requests and
- * ensure that they are setup properly to take advantage of the
- * {@link FreemarkerResult}.
- *
- */
-public class StrutsTilesRequestContext extends TilesRequestContextWrapper {
-
- private static final Logger LOG = LogManager.getLogger(StrutsTilesRequestContext.class);
-
- /**
- * The mask used to detect requests which should be intercepted.
- */
- private String mask;
-
- /**
- * Default constructor.
- * Sets the mask to '.ftl'
- *
- * @param context
- */
- public StrutsTilesRequestContext(TilesRequestContext context) {
- this(context, ".ftl");
- }
-
- /**
- * Optional constructor used to specify a specific mask.
- *
- * @param mask
- * @param context
- */
- public StrutsTilesRequestContext(TilesRequestContext context, String mask) {
- super(context);
- this.mask = mask;
- }
-
- public void dispatch(String include) throws IOException {
- if (include.endsWith(mask)) {
- // FIXME This way FreeMarker results still don't have a content-type!
- include(include);
- } else {
- super.dispatch(include);
- }
- }
-
- /**
- * Enhancement of the default include which allows for freemarker
- * templates to be intercepted so that the FreemarkerResult can
- * be used in order to setup the appropriate model.
- *
- * @throws IOException
- */
- public void include(String include) throws IOException {
- if (include.endsWith(mask)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Intercepting tiles include '" + include + "'. Processing as freemarker result.");
- }
- HttpServletRequest request = (HttpServletRequest) getRequest();
- HttpServletResponse response = (HttpServletResponse) getResponse();
-
- ActionContext ctx = ServletActionContext.getActionContext(request);
- ActionInvocation invocation = ctx.getActionInvocation();
-
- try {
- FreemarkerResult result = new FreemarkerResult();
- result.setWriter(response.getWriter());
-
- Container container = ctx.getContainer();
- container.inject(result);
-
- result.doExecute(include, invocation);
- } catch (Exception e) {
- LOG.error("Error invoking Freemarker template", e);
- throw new IOException("Error invoking Freemarker template." + e.getMessage());
- }
- } else {
- super.include(include);
- }
- }
-
-}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java
new file mode 100644
index 000000000..0fa1bc31e
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java
@@ -0,0 +1,129 @@
+/*
+ * 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.tiles;
+
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.util.WildcardUtil;
+import com.opensymphony.xwork2.util.finder.ResourceFinder;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.tiles.request.ApplicationResource;
+import org.apache.tiles.request.servlet.ServletApplicationContext;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+public class StrutsWildcardServletApplicationContext extends ServletApplicationContext {
+
+ private static final Logger LOG = LogManager.getLogger(StrutsWildcardServletApplicationContext.class);
+
+ private ResourceFinder finder;
+
+ public StrutsWildcardServletApplicationContext(ServletContext context) {
+ super(context);
+
+ Set urls = new HashSet<>();
+
+ for (Object path : context.getResourcePaths("/")) {
+ try {
+ URL url = new File(context.getRealPath(String.valueOf(path))).toURI().toURL();
+ urls.add(url);
+ } catch (MalformedURLException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ try {
+ Enumeration resources = getClass().getClassLoader().getResources("/");
+ while (resources.hasMoreElements()) {
+ URL resource = resources.nextElement();
+ urls.add(resource);
+ }
+ } catch (IOException e) {
+ throw new ConfigurationException(e);
+ }
+
+ finder = new ResourceFinder(urls.toArray(new URL[urls.size()]));
+ }
+
+ public Collection getResources(String path) {
+ Set resources = new HashSet<>();
+
+ if (path.startsWith("/")) {
+ LOG.trace("Using ServletContext to load resource {}", path);
+ ApplicationResource resource = getResource(path);
+ if (resource != null) {
+ resources.add(resource);
+ }
+ }
+
+ try {
+ resources.addAll(findResources(path));
+ } catch (IOException e) {
+ LOG.error("Cannot find resources for [{}]", path, e);
+ }
+
+ return resources;
+ }
+
+ public ApplicationResource getResource(ApplicationResource base, Locale locale) {
+ String localePath = base.getLocalePath(locale);
+ if (new File(localePath).exists()) {
+ try {
+ return new StrutsApplicationResource(URI.create("file://" + localePath).toURL());
+ } catch (MalformedURLException e) {
+ LOG.warn("Cannot access [{}]", localePath, e);
+ return null;
+ }
+ }
+ return null;
+ }
+
+ protected Set findResources(String path) throws IOException {
+ Set resources = new HashSet<>();
+
+ LOG.trace("Using ResourceFinder to find matches for {}", path);
+
+ Pattern pattern = WildcardUtil.compileWildcardPattern(path);
+ Map matches = finder.getResourcesMap("");
+
+ for (String resource : matches.keySet()) {
+ if (pattern.matcher(resource).matches()) {
+ URL url = matches.get(resource);
+ resources.add(new StrutsApplicationResource(url));
+ }
+ }
+
+ LOG.trace("Found resources {} for path {}", resources, path);
+ return resources;
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java
index 490de7966..a4028690a 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java
@@ -28,9 +28,13 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.result.ServletDispatcherResult;
import org.apache.tiles.TilesContainer;
-import org.apache.tiles.access.TilesAccess;
import com.opensymphony.xwork2.ActionInvocation;
+import org.apache.tiles.access.TilesAccess;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.servlet.ServletRequest;
+import org.apache.tiles.request.servlet.ServletUtil;
/**
*
@@ -84,6 +88,7 @@ public class TilesResult extends ServletDispatcherResult {
public TilesResult(String location) {
super(location);
}
+
/**
* Dispatches to the given location. Does its forward via a RequestDispatcher. If the
* dispatch fails a 404 error will be sent back in the http response.
@@ -97,11 +102,15 @@ public class TilesResult extends ServletDispatcherResult {
setLocation(location);
ServletContext servletContext = ServletActionContext.getServletContext();
- TilesContainer container = TilesAccess.getContainer(servletContext);
- HttpServletRequest request = ServletActionContext.getRequest();
- HttpServletResponse response = ServletActionContext.getResponse();
+ ApplicationContext applicationContext = ServletUtil.getApplicationContext(servletContext);
+ TilesContainer container = TilesAccess.getContainer(applicationContext);
- container.render(location, request, response);
+ HttpServletRequest httpRequest = ServletActionContext.getRequest();
+ HttpServletResponse httpResponse = ServletActionContext.getResponse();
+
+ Request request = new ServletRequest(applicationContext, httpRequest, httpResponse);
+
+ container.render(location, request);
}
}
diff --git a/plugins/tiles3/pom.xml b/plugins/tiles3/pom.xml
deleted file mode 100644
index a029dff8f..000000000
--- a/plugins/tiles3/pom.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
- 4.0.0
-
- org.apache.struts
- struts2-plugins
- 2.5-SNAPSHOT
-
-
- struts2-tiles3-plugin
- jar
- Struts 2 Tiles 3 Plugin
-
-
- 3.0.1
- UTF-8
-
-
-
-
- org.apache.tiles
- tiles-core
- ${tiles3.version}
-
-
- org.apache.tiles
- tiles-extras
- ${tiles3.version}
-
-
- org.apache.tiles
- tiles-jsp
- ${tiles3.version}
- runtime
-
-
-
-
diff --git a/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java b/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java
deleted file mode 100644
index 6bc15bb4e..000000000
--- a/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * $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 org.apache.struts2.ServletActionContext;
-import org.apache.struts2.result.ServletDispatcherResult;
-import org.apache.tiles.TilesContainer;
-import org.apache.tiles.access.TilesAccess;
-import org.apache.tiles.request.ApplicationContext;
-import org.apache.tiles.request.servlet.ServletRequest;
-import org.apache.tiles.request.servlet.ServletUtil;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * First implementation of Tiles 3 support
- *
- * Please follow the link to read more how to configure the result
- * http://stackoverflow.com/questions/13337938/how-to-integrate-struts-2-with-tiles-3
- *
- * or check the docs
- *
- * https://cwiki.apache.org/confluence/display/WW/Tiles+3+Plugin
- *
- *
- * @author Ken McWilliams
- */
-public class TilesResult extends ServletDispatcherResult {
-
- public TilesResult() {
- super();
- }
-
- public TilesResult(String location) {
- super(location);
- }
-
- @Override
- public void doExecute(String location, ActionInvocation invocation) throws Exception {
- ServletContext context = ServletActionContext.getServletContext();
- HttpServletRequest request = ServletActionContext.getRequest();
- HttpServletResponse response = ServletActionContext.getResponse();
-
- ApplicationContext applicationContext = ServletUtil.getApplicationContext(context);
- ServletRequest servletRequest = new ServletRequest(applicationContext, request, response);
-
- TilesContainer container = initTilesContainer(applicationContext, servletRequest);
-
- container.startContext(servletRequest);
- container.render(location, servletRequest);
- }
-
- protected TilesContainer initTilesContainer(ApplicationContext applicationContext, ServletRequest servletRequest) {
- TilesContainer container = TilesAccess.getContainer(applicationContext);
- TilesAccess.setCurrentContainer(servletRequest, container);
- return container;
- }
-
-}
diff --git a/plugins/tiles3/src/main/resources/LICENSE.txt b/plugins/tiles3/src/main/resources/LICENSE.txt
deleted file mode 100644
index dd5b3a58a..000000000
--- a/plugins/tiles3/src/main/resources/LICENSE.txt
+++ /dev/null
@@ -1,174 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
diff --git a/plugins/tiles3/src/main/resources/NOTICE.txt b/plugins/tiles3/src/main/resources/NOTICE.txt
deleted file mode 100644
index bfba90c29..000000000
--- a/plugins/tiles3/src/main/resources/NOTICE.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Apache Struts
-Copyright 2000-2011 The Apache Software Foundation
-
-This product includes software developed by
-The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
diff --git a/plugins/tiles3/src/main/resources/struts-plugin.xml b/plugins/tiles3/src/main/resources/struts-plugin.xml
deleted file mode 100644
index 0018a5f37..000000000
--- a/plugins/tiles3/src/main/resources/struts-plugin.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/plugins/tiles3/src/site/site.xml b/plugins/tiles3/src/site/site.xml
deleted file mode 100644
index 07a667ec7..000000000
--- a/plugins/tiles3/src/site/site.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
- org.apache.maven.skins
- maven-fluido-skin
- 1.3.1
-
-
- Apache Software Foundation
- http://www.apache.org/images/asf-logo.gif
- http://www.apache.org/
-
-
- Apache Struts
- http://struts.apache.org/img/struts-logo.svg
- http://struts.apache.org/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pom.xml b/pom.xml
index 07fb3b320..08c94b43a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,7 +88,8 @@
3.1.23.35.0.2
- 2.0.6
+ 3.0.5
+ 1.0.62.5
@@ -595,6 +596,12 @@
provided
+
+ org.glassfish
+ javax.el
+ 3.0.0
+
+
taglibsstandard
@@ -616,16 +623,60 @@
provided
+
+ org.apache.tiles
+ tiles-api
+ ${tiles.version}
+ org.apache.tilestiles-core${tiles.version}
+
+ org.apache.tiles
+ tiles-servlet
+ ${tiles.version}
+
+
+ org.apache.tiles
+ tiles-request-portlet
+ ${tiles-request.version}
+
+
+ org.apache.tiles
+ tiles-request-api
+ ${tiles-request.version}
+
+
+ org.apache.tiles
+ tiles-request-jsp
+ ${tiles-request.version}
+
+
+ org.apache.tiles
+ tiles-request-servlet
+ ${tiles-request.version}
+ org.apache.tilestiles-jsp${tiles.version}
- runtime
+
+
+ org.apache.tiles
+ tiles-freemarker
+ ${tiles.version}
+
+
+ org.apache.tiles
+ tiles-ognl
+ ${tiles.version}
+
+
+ org.apache.tiles
+ tiles-el
+ ${tiles.version}