Permalink
Browse files

Upgraded Tiles2 TilesContainer to Tiles 2.2.2 (following the Spring 4…

….0 baseline)

In sync with our Tiles3 TilesContainer implementation now, as far as possible.

Issue: SPR-11285
  • Loading branch information...
1 parent 24030a3 commit 5d3484c74a252fa714e67cbf74790ea592293c33 @jhoeller jhoeller committed Jan 5, 2014
View
@@ -655,22 +655,35 @@ project("spring-webmvc") {
compile(project(":spring-context"))
optional(project(":spring-context-support")) // for Velocity support
optional(project(":spring-oxm")) // for MarshallingView
- optional("org.apache.tiles:tiles-api:2.1.2")
- optional("org.apache.tiles:tiles-core:2.1.2")
- optional("org.apache.tiles:tiles-jsp:2.1.2")
- optional("org.apache.tiles:tiles-servlet:2.1.2")
- optional("net.sourceforge.jexcelapi:jxl:2.6.3")
- optional("org.apache.poi:poi:3.9")
- optional("com.lowagie:itext:2.1.7")
+ optional("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
+ optional("com.fasterxml.jackson.core:jackson-databind:2.3.0")
optional("net.sf.jasperreports:jasperreports:5.1.0") {
exclude group: "xml-apis", module: "xml-apis"
}
optional("rome:rome:1.0")
+ optional("com.lowagie:itext:2.1.7")
+ optional("net.sourceforge.jexcelapi:jxl:2.6.3")
+ optional("org.apache.poi:poi:3.9")
optional("org.apache.velocity:velocity:1.7")
optional("velocity-tools:velocity-tools-view:1.4")
optional("org.freemarker:freemarker:2.3.19")
- optional("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
- optional("com.fasterxml.jackson.core:jackson-databind:2.3.0")
+ optional("org.apache.tiles:tiles-api:2.2.2")
+ optional("org.apache.tiles:tiles-core:2.2.2") {
+ exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ }
+ optional("org.apache.tiles:tiles-servlet:2.2.2") {
+ exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ }
+ optional("org.apache.tiles:tiles-jsp:2.2.2") {
+ exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ }
+ optional("org.apache.tiles:tiles-el:2.2.2") {
+ exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ }
+ optional("org.apache.tiles:tiles-extras:2.2.2") {
+ exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ exclude group: "org.springframework", module: "spring-web"
+ }
provided("javax.servlet:jstl:1.2")
provided("javax.servlet:javax.servlet-api:3.0.1")
provided("javax.servlet.jsp:jsp-api:2.1")
@@ -725,12 +738,12 @@ project("spring-webmvc-tiles3") {
optional("org.apache.tiles:tiles-jsp:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j"
}
- optional("org.apache.tiles:tiles-extras:3.0.1") {
+ optional("org.apache.tiles:tiles-el:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j"
- exclude group: "org.springframework", module: "spring-web"
}
- optional("org.apache.tiles:tiles-el:3.0.1") {
+ optional("org.apache.tiles:tiles-extras:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j"
+ exclude group: "org.springframework", module: "spring-web"
}
provided("javax.servlet:javax.servlet-api:3.0.1")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.web.servlet.view.tiles3;
import java.io.IOException;
@@ -21,14 +22,15 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
-
import javax.servlet.ServletContext;
import org.apache.tiles.request.ApplicationResource;
import org.apache.tiles.request.locale.URLApplicationResource;
import org.apache.tiles.request.servlet.ServletApplicationContext;
+
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.util.ObjectUtils;
import org.springframework.web.context.support.ServletContextResourcePatternResolver;
/**
@@ -39,21 +41,15 @@
*/
public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext {
- /**
- * The pattern resolver.
- */
- protected ResourcePatternResolver resolver;
+ private final ResourcePatternResolver resolver;
+
- /**
- * Constructor.
- *
- * @param servletContext The servlet context.
- */
public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) {
super(servletContext);
- resolver = new ServletContextResourcePatternResolver(servletContext);
+ this.resolver = new ServletContextResourcePatternResolver(servletContext);
}
+
@Override
public ApplicationResource getResource(String localePath) {
ApplicationResource retValue = null;
@@ -78,20 +74,22 @@ public ApplicationResource getResource(ApplicationResource base, Locale locale)
public Collection<ApplicationResource> getResources(String path) {
Resource[] resources;
try {
- resources = resolver.getResources(path);
- } catch (IOException e) {
+ resources = this.resolver.getResources(path);
+ }
+ catch (IOException ex) {
return Collections.<ApplicationResource> emptyList();
}
Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>();
- if (resources != null && resources.length > 0) {
- for (int i = 0; i < resources.length; i++) {
+ if (!ObjectUtils.isEmpty(resources)) {
+ for (Resource resource : resources) {
URL url;
try {
- url = resources[i].getURL();
+ url = resource.getURL();
resourceList.add(new URLApplicationResource(url.toExternalForm(), url));
- } catch (IOException e) {
+ }
+ catch (IOException ex) {
// shouldn't happen with the kind of resources we're using
- throw new IllegalArgumentException("no URL for " + resources[i].toString(), e);
+ throw new IllegalArgumentException("No URL for " + resource.toString(), ex);
}
}
}
@@ -18,7 +18,6 @@
import java.util.LinkedList;
import java.util.List;
-
import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
@@ -49,14 +48,15 @@
import org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer;
import org.apache.tiles.factory.AbstractTilesContainerFactory;
import org.apache.tiles.factory.BasicTilesContainerFactory;
-import org.apache.tiles.impl.BasicTilesContainer;
import org.apache.tiles.impl.mgmt.CachingTilesContainer;
import org.apache.tiles.locale.LocaleResolver;
import org.apache.tiles.preparer.factory.PreparerFactory;
import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.ApplicationContextAware;
import org.apache.tiles.request.ApplicationResource;
import org.apache.tiles.startup.DefaultTilesInitializer;
import org.apache.tiles.startup.TilesInitializer;
+
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.PropertyAccessorFactory;
@@ -103,13 +103,15 @@
* @author mick semb wever
* @author Rossen Stoyanchev
* @since 3.2
+ * @see TilesView
+ * @see TilesViewResolver
*/
public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean {
- private static final boolean tilesElPresent = // requires JSP 2.1 as well as Tiles EL module
- ClassUtils.isPresent("javax.servlet.jsp.JspApplicationContext", TilesConfigurer.class.getClassLoader()) &&
+ private static final boolean tilesElPresent =
ClassUtils.isPresent("org.apache.tiles.el.ELAttributeEvaluator", TilesConfigurer.class.getClassLoader());
+
protected final Log logger = LogFactory.getLog(getClass());
private TilesInitializer tilesInitializer;
@@ -128,8 +130,6 @@
private ServletContext servletContext;
- public TilesConfigurer() {
- }
/**
* Configure Tiles using a custom TilesInitializer, typically specified as an inner bean.
@@ -158,10 +158,11 @@ public void setCompleteAutoload(boolean completeAutoload) {
try {
this.tilesInitializer = new SpringCompleteAutoloadTilesInitializer();
}
- catch (Exception ex) {
- throw new IllegalStateException("tiles-extras 3.x not available", ex);
+ catch (Throwable ex) {
+ throw new IllegalStateException("Tiles-Extras 3.0 not available", ex);
}
- } else {
+ }
+ else {
this.tilesInitializer = null;
}
}
@@ -170,7 +171,7 @@ public void setCompleteAutoload(boolean completeAutoload) {
* Set the Tiles definitions, i.e. the list of files containing the definitions.
* Default is "/WEB-INF/tiles.xml".
*/
- public void setDefinitions(String[] definitions) {
+ public void setDefinitions(String... definitions) {
this.definitions = definitions;
}
@@ -318,8 +319,8 @@ protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applica
if (definitionsFactoryClass != null) {
DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
- if (factory instanceof org.apache.tiles.request.ApplicationContextAware) {
- ((org.apache.tiles.request.ApplicationContextAware) factory).setApplicationContext(applicationContext);
+ if (factory instanceof ApplicationContextAware) {
+ ((ApplicationContextAware) factory).setApplicationContext(applicationContext);
}
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
if (bw.isWritableProperty("localeResolver")) {
@@ -352,64 +353,49 @@ protected LocaleResolver createLocaleResolver(ApplicationContext context) {
@Override
protected AttributeEvaluatorFactory createAttributeEvaluatorFactory(ApplicationContext context,
LocaleResolver resolver) {
- return new BasicAttributeEvaluatorFactory(createELEvaluator(context));
- }
-
- private AttributeEvaluator createELEvaluator(ApplicationContext context) {
- if (tilesElPresent) {
- AttributeEvaluator evaluator = new TilesElActivator().createEvaluator();
- if (evaluator != null) {
- return evaluator;
- }
+ AttributeEvaluator evaluator;
+ if (tilesElPresent && JspFactory.getDefaultFactory() != null) {
+ evaluator = new TilesElActivator().createEvaluator();
}
- return new DirectAttributeEvaluator();
+ else {
+ evaluator = new DirectAttributeEvaluator();
+ }
+ return new BasicAttributeEvaluatorFactory(evaluator);
}
}
- private class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer {
+
+ private static class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer {
@Override
protected AbstractTilesContainerFactory createContainerFactory(ApplicationContext context) {
return new SpringCompleteAutoloadTilesContainerFactory();
}
}
- private class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
+
+ private static class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
@Override
- public TilesContainer createContainer(ApplicationContext applicationContext) {
- CachingTilesContainer cachingContainer = (CachingTilesContainer) super.createContainer(applicationContext);
- BasicTilesContainer tilesContainer = (BasicTilesContainer) cachingContainer.getWrappedContainer();
- BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(tilesContainer.getDefinitionsFactory());
- if (bw.isWritableProperty("localeResolver")) {
- bw.setPropertyValue("localeResolver", new SpringLocaleResolver());
- }
- return tilesContainer;
+ protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
+ return new SpringLocaleResolver();
}
+
}
private class TilesElActivator {
public AttributeEvaluator createEvaluator() {
- try {
- // jsp-api-2.1 doesn't default instantiate a factory for us
- JspFactory factory = JspFactory.getDefaultFactory();
- if ((factory != null) && (factory.getJspApplicationContext(servletContext).getExpressionFactory() != null)) {
- logger.info("Found JSP 2.1 ExpressionFactory");
- ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
- evaluator.setExpressionFactory(factory.getJspApplicationContext(servletContext).getExpressionFactory());
- evaluator.setResolver(new CompositeELResolverImpl());
- return evaluator;
- }
- }
- catch (Throwable ex) {
- logger.warn("Could not obtain JSP 2.1 ExpressionFactory", ex);
- }
- return null;
+ ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
+ evaluator.setExpressionFactory(
+ JspFactory.getDefaultFactory().getJspApplicationContext(servletContext).getExpressionFactory());
+ evaluator.setResolver(new CompositeELResolverImpl());
+ return evaluator;
}
}
+
private static class CompositeELResolverImpl extends CompositeELResolver {
public CompositeELResolverImpl() {
@@ -423,4 +409,5 @@ public CompositeELResolverImpl() {
add(new BeanELResolver(false));
}
}
+
}
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,21 @@
package org.springframework.web.servlet.view.tiles3;
-import static org.junit.Assert.assertNotNull;
-
import org.apache.tiles.access.TilesAccess;
import org.apache.tiles.impl.BasicTilesContainer;
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;
import org.junit.Test;
+
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletContext;
+import static org.junit.Assert.*;
+
/**
* Test fixture for {@link TilesConfigurer}.
*
@@ -42,7 +43,7 @@ public void simpleBootstrap() {
MockServletContext servletContext = new MockServletContext();
TilesConfigurer tc = new TilesConfigurer();
- tc.setDefinitions(new String[] { "/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml" });
+ tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
tc.setCheckRefresh(true);
tc.setServletContext(servletContext);
tc.afterPropertiesSet();
@@ -57,6 +58,7 @@ public void simpleBootstrap() {
tc.destroy();
}
+
@Configuration
public static class AppConfig {
}
Oops, something went wrong.

0 comments on commit 5d3484c

Please sign in to comment.