Skip to content

Commit 5d3484c

Browse files
committed
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
1 parent 24030a3 commit 5d3484c

File tree

9 files changed

+221
-390
lines changed

9 files changed

+221
-390
lines changed

build.gradle

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,22 +655,35 @@ project("spring-webmvc") {
655655
compile(project(":spring-context"))
656656
optional(project(":spring-context-support")) // for Velocity support
657657
optional(project(":spring-oxm")) // for MarshallingView
658-
optional("org.apache.tiles:tiles-api:2.1.2")
659-
optional("org.apache.tiles:tiles-core:2.1.2")
660-
optional("org.apache.tiles:tiles-jsp:2.1.2")
661-
optional("org.apache.tiles:tiles-servlet:2.1.2")
662-
optional("net.sourceforge.jexcelapi:jxl:2.6.3")
663-
optional("org.apache.poi:poi:3.9")
664-
optional("com.lowagie:itext:2.1.7")
658+
optional("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
659+
optional("com.fasterxml.jackson.core:jackson-databind:2.3.0")
665660
optional("net.sf.jasperreports:jasperreports:5.1.0") {
666661
exclude group: "xml-apis", module: "xml-apis"
667662
}
668663
optional("rome:rome:1.0")
664+
optional("com.lowagie:itext:2.1.7")
665+
optional("net.sourceforge.jexcelapi:jxl:2.6.3")
666+
optional("org.apache.poi:poi:3.9")
669667
optional("org.apache.velocity:velocity:1.7")
670668
optional("velocity-tools:velocity-tools-view:1.4")
671669
optional("org.freemarker:freemarker:2.3.19")
672-
optional("org.codehaus.jackson:jackson-mapper-asl:1.9.12")
673-
optional("com.fasterxml.jackson.core:jackson-databind:2.3.0")
670+
optional("org.apache.tiles:tiles-api:2.2.2")
671+
optional("org.apache.tiles:tiles-core:2.2.2") {
672+
exclude group: "org.slf4j", module: "jcl-over-slf4j"
673+
}
674+
optional("org.apache.tiles:tiles-servlet:2.2.2") {
675+
exclude group: "org.slf4j", module: "jcl-over-slf4j"
676+
}
677+
optional("org.apache.tiles:tiles-jsp:2.2.2") {
678+
exclude group: "org.slf4j", module: "jcl-over-slf4j"
679+
}
680+
optional("org.apache.tiles:tiles-el:2.2.2") {
681+
exclude group: "org.slf4j", module: "jcl-over-slf4j"
682+
}
683+
optional("org.apache.tiles:tiles-extras:2.2.2") {
684+
exclude group: "org.slf4j", module: "jcl-over-slf4j"
685+
exclude group: "org.springframework", module: "spring-web"
686+
}
674687
provided("javax.servlet:jstl:1.2")
675688
provided("javax.servlet:javax.servlet-api:3.0.1")
676689
provided("javax.servlet.jsp:jsp-api:2.1")
@@ -725,12 +738,12 @@ project("spring-webmvc-tiles3") {
725738
optional("org.apache.tiles:tiles-jsp:3.0.1") {
726739
exclude group: "org.slf4j", module: "jcl-over-slf4j"
727740
}
728-
optional("org.apache.tiles:tiles-extras:3.0.1") {
741+
optional("org.apache.tiles:tiles-el:3.0.1") {
729742
exclude group: "org.slf4j", module: "jcl-over-slf4j"
730-
exclude group: "org.springframework", module: "spring-web"
731743
}
732-
optional("org.apache.tiles:tiles-el:3.0.1") {
744+
optional("org.apache.tiles:tiles-extras:3.0.1") {
733745
exclude group: "org.slf4j", module: "jcl-over-slf4j"
746+
exclude group: "org.springframework", module: "spring-web"
734747
}
735748
provided("javax.servlet:javax.servlet-api:3.0.1")
736749
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")

spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.servlet.view.tiles3;
1718

1819
import java.io.IOException;
@@ -21,14 +22,15 @@
2122
import java.util.Collection;
2223
import java.util.Collections;
2324
import java.util.Locale;
24-
2525
import javax.servlet.ServletContext;
2626

2727
import org.apache.tiles.request.ApplicationResource;
2828
import org.apache.tiles.request.locale.URLApplicationResource;
2929
import org.apache.tiles.request.servlet.ServletApplicationContext;
30+
3031
import org.springframework.core.io.Resource;
3132
import org.springframework.core.io.support.ResourcePatternResolver;
33+
import org.springframework.util.ObjectUtils;
3234
import org.springframework.web.context.support.ServletContextResourcePatternResolver;
3335

3436
/**
@@ -39,21 +41,15 @@
3941
*/
4042
public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext {
4143

42-
/**
43-
* The pattern resolver.
44-
*/
45-
protected ResourcePatternResolver resolver;
44+
private final ResourcePatternResolver resolver;
45+
4646

47-
/**
48-
* Constructor.
49-
*
50-
* @param servletContext The servlet context.
51-
*/
5247
public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) {
5348
super(servletContext);
54-
resolver = new ServletContextResourcePatternResolver(servletContext);
49+
this.resolver = new ServletContextResourcePatternResolver(servletContext);
5550
}
5651

52+
5753
@Override
5854
public ApplicationResource getResource(String localePath) {
5955
ApplicationResource retValue = null;
@@ -78,20 +74,22 @@ public ApplicationResource getResource(ApplicationResource base, Locale locale)
7874
public Collection<ApplicationResource> getResources(String path) {
7975
Resource[] resources;
8076
try {
81-
resources = resolver.getResources(path);
82-
} catch (IOException e) {
77+
resources = this.resolver.getResources(path);
78+
}
79+
catch (IOException ex) {
8380
return Collections.<ApplicationResource> emptyList();
8481
}
8582
Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>();
86-
if (resources != null && resources.length > 0) {
87-
for (int i = 0; i < resources.length; i++) {
83+
if (!ObjectUtils.isEmpty(resources)) {
84+
for (Resource resource : resources) {
8885
URL url;
8986
try {
90-
url = resources[i].getURL();
87+
url = resource.getURL();
9188
resourceList.add(new URLApplicationResource(url.toExternalForm(), url));
92-
} catch (IOException e) {
89+
}
90+
catch (IOException ex) {
9391
// shouldn't happen with the kind of resources we're using
94-
throw new IllegalArgumentException("no URL for " + resources[i].toString(), e);
92+
throw new IllegalArgumentException("No URL for " + resource.toString(), ex);
9593
}
9694
}
9795
}

spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.LinkedList;
2020
import java.util.List;
21-
2221
import javax.el.ArrayELResolver;
2322
import javax.el.BeanELResolver;
2423
import javax.el.CompositeELResolver;
@@ -49,14 +48,15 @@
4948
import org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer;
5049
import org.apache.tiles.factory.AbstractTilesContainerFactory;
5150
import org.apache.tiles.factory.BasicTilesContainerFactory;
52-
import org.apache.tiles.impl.BasicTilesContainer;
5351
import org.apache.tiles.impl.mgmt.CachingTilesContainer;
5452
import org.apache.tiles.locale.LocaleResolver;
5553
import org.apache.tiles.preparer.factory.PreparerFactory;
5654
import org.apache.tiles.request.ApplicationContext;
55+
import org.apache.tiles.request.ApplicationContextAware;
5756
import org.apache.tiles.request.ApplicationResource;
5857
import org.apache.tiles.startup.DefaultTilesInitializer;
5958
import org.apache.tiles.startup.TilesInitializer;
59+
6060
import org.springframework.beans.BeanUtils;
6161
import org.springframework.beans.BeanWrapper;
6262
import org.springframework.beans.PropertyAccessorFactory;
@@ -103,13 +103,15 @@
103103
* @author mick semb wever
104104
* @author Rossen Stoyanchev
105105
* @since 3.2
106+
* @see TilesView
107+
* @see TilesViewResolver
106108
*/
107109
public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean {
108110

109-
private static final boolean tilesElPresent = // requires JSP 2.1 as well as Tiles EL module
110-
ClassUtils.isPresent("javax.servlet.jsp.JspApplicationContext", TilesConfigurer.class.getClassLoader()) &&
111+
private static final boolean tilesElPresent =
111112
ClassUtils.isPresent("org.apache.tiles.el.ELAttributeEvaluator", TilesConfigurer.class.getClassLoader());
112113

114+
113115
protected final Log logger = LogFactory.getLog(getClass());
114116

115117
private TilesInitializer tilesInitializer;
@@ -128,8 +130,6 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
128130

129131
private ServletContext servletContext;
130132

131-
public TilesConfigurer() {
132-
}
133133

134134
/**
135135
* Configure Tiles using a custom TilesInitializer, typically specified as an inner bean.
@@ -158,10 +158,11 @@ public void setCompleteAutoload(boolean completeAutoload) {
158158
try {
159159
this.tilesInitializer = new SpringCompleteAutoloadTilesInitializer();
160160
}
161-
catch (Exception ex) {
162-
throw new IllegalStateException("tiles-extras 3.x not available", ex);
161+
catch (Throwable ex) {
162+
throw new IllegalStateException("Tiles-Extras 3.0 not available", ex);
163163
}
164-
} else {
164+
}
165+
else {
165166
this.tilesInitializer = null;
166167
}
167168
}
@@ -170,7 +171,7 @@ public void setCompleteAutoload(boolean completeAutoload) {
170171
* Set the Tiles definitions, i.e. the list of files containing the definitions.
171172
* Default is "/WEB-INF/tiles.xml".
172173
*/
173-
public void setDefinitions(String[] definitions) {
174+
public void setDefinitions(String... definitions) {
174175
this.definitions = definitions;
175176
}
176177

@@ -318,8 +319,8 @@ protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applica
318319

319320
if (definitionsFactoryClass != null) {
320321
DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
321-
if (factory instanceof org.apache.tiles.request.ApplicationContextAware) {
322-
((org.apache.tiles.request.ApplicationContextAware) factory).setApplicationContext(applicationContext);
322+
if (factory instanceof ApplicationContextAware) {
323+
((ApplicationContextAware) factory).setApplicationContext(applicationContext);
323324
}
324325
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
325326
if (bw.isWritableProperty("localeResolver")) {
@@ -352,64 +353,49 @@ protected LocaleResolver createLocaleResolver(ApplicationContext context) {
352353
@Override
353354
protected AttributeEvaluatorFactory createAttributeEvaluatorFactory(ApplicationContext context,
354355
LocaleResolver resolver) {
355-
return new BasicAttributeEvaluatorFactory(createELEvaluator(context));
356-
}
357-
358-
private AttributeEvaluator createELEvaluator(ApplicationContext context) {
359-
if (tilesElPresent) {
360-
AttributeEvaluator evaluator = new TilesElActivator().createEvaluator();
361-
if (evaluator != null) {
362-
return evaluator;
363-
}
356+
AttributeEvaluator evaluator;
357+
if (tilesElPresent && JspFactory.getDefaultFactory() != null) {
358+
evaluator = new TilesElActivator().createEvaluator();
364359
}
365-
return new DirectAttributeEvaluator();
360+
else {
361+
evaluator = new DirectAttributeEvaluator();
362+
}
363+
return new BasicAttributeEvaluatorFactory(evaluator);
366364
}
367365
}
368366

369-
private class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer {
367+
368+
private static class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer {
370369

371370
@Override
372371
protected AbstractTilesContainerFactory createContainerFactory(ApplicationContext context) {
373372
return new SpringCompleteAutoloadTilesContainerFactory();
374373
}
375374
}
376375

377-
private class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
376+
377+
private static class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
378378

379379
@Override
380-
public TilesContainer createContainer(ApplicationContext applicationContext) {
381-
CachingTilesContainer cachingContainer = (CachingTilesContainer) super.createContainer(applicationContext);
382-
BasicTilesContainer tilesContainer = (BasicTilesContainer) cachingContainer.getWrappedContainer();
383-
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(tilesContainer.getDefinitionsFactory());
384-
if (bw.isWritableProperty("localeResolver")) {
385-
bw.setPropertyValue("localeResolver", new SpringLocaleResolver());
386-
}
387-
return tilesContainer;
380+
protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
381+
return new SpringLocaleResolver();
388382
}
383+
389384
}
390385

391386

392387
private class TilesElActivator {
393388

394389
public AttributeEvaluator createEvaluator() {
395-
try {
396-
// jsp-api-2.1 doesn't default instantiate a factory for us
397-
JspFactory factory = JspFactory.getDefaultFactory();
398-
if ((factory != null) && (factory.getJspApplicationContext(servletContext).getExpressionFactory() != null)) {
399-
logger.info("Found JSP 2.1 ExpressionFactory");
400-
ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
401-
evaluator.setExpressionFactory(factory.getJspApplicationContext(servletContext).getExpressionFactory());
402-
evaluator.setResolver(new CompositeELResolverImpl());
403-
return evaluator;
404-
}
405-
}
406-
catch (Throwable ex) {
407-
logger.warn("Could not obtain JSP 2.1 ExpressionFactory", ex);
408-
}
409-
return null;
390+
ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
391+
evaluator.setExpressionFactory(
392+
JspFactory.getDefaultFactory().getJspApplicationContext(servletContext).getExpressionFactory());
393+
evaluator.setResolver(new CompositeELResolverImpl());
394+
return evaluator;
410395
}
411396
}
412397

398+
413399
private static class CompositeELResolverImpl extends CompositeELResolver {
414400

415401
public CompositeELResolverImpl() {
@@ -423,4 +409,5 @@ public CompositeELResolverImpl() {
423409
add(new BeanELResolver(false));
424410
}
425411
}
412+
426413
}

spring-webmvc-tiles3/src/test/java/org/springframework/web/servlet/view/tiles3/TilesConfigurerTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,20 +16,21 @@
1616

1717
package org.springframework.web.servlet.view.tiles3;
1818

19-
import static org.junit.Assert.assertNotNull;
20-
2119
import org.apache.tiles.access.TilesAccess;
2220
import org.apache.tiles.impl.BasicTilesContainer;
2321
import org.apache.tiles.request.ApplicationContext;
2422
import org.apache.tiles.request.Request;
2523
import org.apache.tiles.request.servlet.ServletRequest;
2624
import org.apache.tiles.request.servlet.ServletUtil;
2725
import org.junit.Test;
26+
2827
import org.springframework.context.annotation.Configuration;
2928
import org.springframework.mock.web.test.MockHttpServletRequest;
3029
import org.springframework.mock.web.test.MockHttpServletResponse;
3130
import org.springframework.mock.web.test.MockServletContext;
3231

32+
import static org.junit.Assert.*;
33+
3334
/**
3435
* Test fixture for {@link TilesConfigurer}.
3536
*
@@ -42,7 +43,7 @@ public void simpleBootstrap() {
4243
MockServletContext servletContext = new MockServletContext();
4344

4445
TilesConfigurer tc = new TilesConfigurer();
45-
tc.setDefinitions(new String[] { "/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml" });
46+
tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
4647
tc.setCheckRefresh(true);
4748
tc.setServletContext(servletContext);
4849
tc.afterPropertiesSet();
@@ -57,6 +58,7 @@ public void simpleBootstrap() {
5758
tc.destroy();
5859
}
5960

61+
6062
@Configuration
6163
public static class AppConfig {
6264
}

0 commit comments

Comments
 (0)