Polishing (along with the Tiles 2.2.2 upgrade in the Spring 4.0 line)

Issue: SPR-11285
This commit is contained in:
Juergen Hoeller 2014-01-06 00:43:41 +01:00
parent dbfe68a6dc
commit 0606c98277
6 changed files with 57 additions and 50 deletions

View File

@ -565,22 +565,22 @@ project("spring-webmvc") {
compile(project(":spring-context")) compile(project(":spring-context"))
optional(project(":spring-context-support")) // for Velocity support optional(project(":spring-context-support")) // for Velocity support
optional(project(":spring-oxm")) // for MarshallingView optional(project(":spring-oxm")) // for MarshallingView
optional("org.apache.tiles:tiles-api:2.1.2") optional("org.codehaus.jackson:jackson-mapper-asl:1.4.2")
optional("org.apache.tiles:tiles-core:2.1.2") optional("com.fasterxml.jackson.core:jackson-databind:2.0.1")
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.0.2-FINAL")
optional("com.lowagie:itext:2.1.7")
optional("jasperreports:jasperreports:2.0.5") { optional("jasperreports:jasperreports:2.0.5") {
exclude group: "xml-apis", module: "xml-apis" exclude group: "xml-apis", module: "xml-apis"
} }
optional("rome:rome:1.0") 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.0.2-FINAL")
optional("velocity:velocity:1.5") optional("velocity:velocity:1.5")
optional("velocity-tools:velocity-tools-view:1.4") optional("velocity-tools:velocity-tools-view:1.4")
optional("org.freemarker:freemarker:2.3.19") optional("org.freemarker:freemarker:2.3.19")
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.2") optional("org.apache.tiles:tiles-api:2.1.2")
optional("com.fasterxml.jackson.core:jackson-databind:2.0.1") 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")
provided("javax.servlet:jstl:1.2") provided("javax.servlet:jstl:1.2")
provided("javax.servlet:javax.servlet-api:3.0.1") provided("javax.servlet:javax.servlet-api:3.0.1")
provided("javax.servlet.jsp:jsp-api:2.1") provided("javax.servlet.jsp:jsp-api:2.1")
@ -634,12 +634,13 @@ project("spring-webmvc-tiles3") {
optional("org.apache.tiles:tiles-jsp:3.0.1") { optional("org.apache.tiles:tiles-jsp:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j" exclude group: "org.slf4j", module: "jcl-over-slf4j"
} }
optional("org.apache.tiles:tiles-extras:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j"
}
optional("org.apache.tiles:tiles-el:3.0.1") { optional("org.apache.tiles:tiles-el:3.0.1") {
exclude group: "org.slf4j", module: "jcl-over-slf4j" exclude group: "org.slf4j", module: "jcl-over-slf4j"
} }
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") provided("javax.servlet:javax.servlet-api:3.0.1")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.view.tiles3; package org.springframework.web.servlet.view.tiles3;
import java.io.IOException; import java.io.IOException;
@ -21,14 +22,15 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.apache.tiles.request.ApplicationResource; import org.apache.tiles.request.ApplicationResource;
import org.apache.tiles.request.locale.URLApplicationResource; import org.apache.tiles.request.locale.URLApplicationResource;
import org.apache.tiles.request.servlet.ServletApplicationContext; import org.apache.tiles.request.servlet.ServletApplicationContext;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.support.ServletContextResourcePatternResolver; import org.springframework.web.context.support.ServletContextResourcePatternResolver;
/** /**
@ -39,21 +41,15 @@ import org.springframework.web.context.support.ServletContextResourcePatternReso
*/ */
public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext { public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext {
/** private final ResourcePatternResolver resolver;
* The pattern resolver.
*/
protected ResourcePatternResolver resolver;
/**
* Constructor.
*
* @param servletContext The servlet context.
*/
public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) { public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) {
super(servletContext); super(servletContext);
resolver = new ServletContextResourcePatternResolver(servletContext); this.resolver = new ServletContextResourcePatternResolver(servletContext);
} }
@Override @Override
public ApplicationResource getResource(String localePath) { public ApplicationResource getResource(String localePath) {
ApplicationResource retValue = null; ApplicationResource retValue = null;
@ -78,20 +74,22 @@ public class SpringWildcardServletTilesApplicationContext extends ServletApplica
public Collection<ApplicationResource> getResources(String path) { public Collection<ApplicationResource> getResources(String path) {
Resource[] resources; Resource[] resources;
try { try {
resources = resolver.getResources(path); resources = this.resolver.getResources(path);
} catch (IOException e) { }
catch (IOException ex) {
return Collections.<ApplicationResource> emptyList(); return Collections.<ApplicationResource> emptyList();
} }
Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>(); Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>();
if (resources != null && resources.length > 0) { if (!ObjectUtils.isEmpty(resources)) {
for (int i = 0; i < resources.length; i++) { for (Resource resource : resources) {
URL url; URL url;
try { try {
url = resources[i].getURL(); url = resource.getURL();
resourceList.add(new URLApplicationResource(url.toExternalForm(), url)); resourceList.add(new URLApplicationResource(url.toExternalForm(), url));
} catch (IOException e) { }
catch (IOException ex) {
// shouldn't happen with the kind of resources we're using // 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);
} }
} }
} }

View File

@ -18,7 +18,6 @@ package org.springframework.web.servlet.view.tiles3;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import javax.el.ArrayELResolver; import javax.el.ArrayELResolver;
import javax.el.BeanELResolver; import javax.el.BeanELResolver;
import javax.el.CompositeELResolver; import javax.el.CompositeELResolver;
@ -54,9 +53,11 @@ import org.apache.tiles.impl.mgmt.CachingTilesContainer;
import org.apache.tiles.locale.LocaleResolver; import org.apache.tiles.locale.LocaleResolver;
import org.apache.tiles.preparer.factory.PreparerFactory; import org.apache.tiles.preparer.factory.PreparerFactory;
import org.apache.tiles.request.ApplicationContext; import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.ApplicationContextAware;
import org.apache.tiles.request.ApplicationResource; import org.apache.tiles.request.ApplicationResource;
import org.apache.tiles.startup.DefaultTilesInitializer; import org.apache.tiles.startup.DefaultTilesInitializer;
import org.apache.tiles.startup.TilesInitializer; import org.apache.tiles.startup.TilesInitializer;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapper;
import org.springframework.beans.PropertyAccessorFactory; import org.springframework.beans.PropertyAccessorFactory;
@ -83,7 +84,7 @@ import org.springframework.web.context.ServletContextAware;
* *
* <p>A typical TilesConfigurer bean definition looks as follows: * <p>A typical TilesConfigurer bean definition looks as follows:
* *
* <pre> * <pre class="code">
* &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> * &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
* &lt;property name="definitions"> * &lt;property name="definitions">
* &lt;list> * &lt;list>
@ -103,6 +104,8 @@ import org.springframework.web.context.ServletContextAware;
* @author mick semb wever * @author mick semb wever
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 3.2 * @since 3.2
* @see TilesView
* @see TilesViewResolver
*/ */
public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean { public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean {
@ -128,8 +131,6 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
private ServletContext servletContext; private ServletContext servletContext;
public TilesConfigurer() {
}
/** /**
* Configure Tiles using a custom TilesInitializer, typically specified as an inner bean. * Configure Tiles using a custom TilesInitializer, typically specified as an inner bean.
@ -158,10 +159,11 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
try { try {
this.tilesInitializer = new SpringCompleteAutoloadTilesInitializer(); this.tilesInitializer = new SpringCompleteAutoloadTilesInitializer();
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("tiles-extras 3.x not available", ex); throw new IllegalStateException("Tiles-Extras 3.0 not available", ex);
} }
} else { }
else {
this.tilesInitializer = null; this.tilesInitializer = null;
} }
} }
@ -170,7 +172,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
* Set the Tiles definitions, i.e. the list of files containing the definitions. * Set the Tiles definitions, i.e. the list of files containing the definitions.
* Default is "/WEB-INF/tiles.xml". * Default is "/WEB-INF/tiles.xml".
*/ */
public void setDefinitions(String[] definitions) { public void setDefinitions(String... definitions) {
this.definitions = definitions; this.definitions = definitions;
} }
@ -315,8 +317,8 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
if (definitionsFactoryClass != null) { if (definitionsFactoryClass != null) {
DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass); DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
if (factory instanceof org.apache.tiles.request.ApplicationContextAware) { if (factory instanceof ApplicationContextAware) {
((org.apache.tiles.request.ApplicationContextAware) factory).setApplicationContext(applicationContext); ((ApplicationContextAware) factory).setApplicationContext(applicationContext);
} }
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
if (bw.isWritableProperty("localeResolver")) { if (bw.isWritableProperty("localeResolver")) {
@ -363,6 +365,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
} }
} }
private class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer { private class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer {
@Override @Override
@ -371,6 +374,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
} }
} }
private class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory { private class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
@Override @Override
@ -407,6 +411,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
} }
} }
private static class CompositeELResolverImpl extends CompositeELResolver { private static class CompositeELResolverImpl extends CompositeELResolver {
public CompositeELResolverImpl() { public CompositeELResolverImpl() {
@ -420,4 +425,5 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
add(new BeanELResolver(false)); add(new BeanELResolver(false));
} }
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.web.servlet.view.tiles3; package org.springframework.web.servlet.view.tiles3;
import static org.junit.Assert.assertNotNull;
import org.apache.tiles.access.TilesAccess; import org.apache.tiles.access.TilesAccess;
import org.apache.tiles.impl.BasicTilesContainer; import org.apache.tiles.impl.BasicTilesContainer;
import org.apache.tiles.request.ApplicationContext; import org.apache.tiles.request.ApplicationContext;
@ -25,11 +23,14 @@ import org.apache.tiles.request.Request;
import org.apache.tiles.request.servlet.ServletRequest; import org.apache.tiles.request.servlet.ServletRequest;
import org.apache.tiles.request.servlet.ServletUtil; import org.apache.tiles.request.servlet.ServletUtil;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletContext; import org.springframework.mock.web.test.MockServletContext;
import static org.junit.Assert.*;
/** /**
* Test fixture for {@link TilesConfigurer}. * Test fixture for {@link TilesConfigurer}.
* *
@ -42,7 +43,7 @@ public class TilesConfigurerTests {
MockServletContext servletContext = new MockServletContext(); MockServletContext servletContext = new MockServletContext();
TilesConfigurer tc = new TilesConfigurer(); 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.setCheckRefresh(true);
tc.setServletContext(servletContext); tc.setServletContext(servletContext);
tc.afterPropertiesSet(); tc.afterPropertiesSet();
@ -57,6 +58,7 @@ public class TilesConfigurerTests {
tc.destroy(); tc.destroy();
} }
@Configuration @Configuration
public static class AppConfig { public static class AppConfig {
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -200,7 +200,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
"org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer"); "org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer");
this.tilesInitializer = (TilesInitializer) clazz.newInstance(); this.tilesInitializer = (TilesInitializer) clazz.newInstance();
} }
catch (Exception ex) { catch (Throwable ex) {
throw new IllegalStateException("Tiles-Extras 2.2 not available", ex); throw new IllegalStateException("Tiles-Extras 2.2 not available", ex);
} }
} }
@ -214,7 +214,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
* Set the Tiles definitions, i.e. the list of files containing the definitions. * Set the Tiles definitions, i.e. the list of files containing the definitions.
* Default is "/WEB-INF/tiles.xml". * Default is "/WEB-INF/tiles.xml".
*/ */
public void setDefinitions(String[] definitions) { public void setDefinitions(String... definitions) {
this.definitions = definitions; this.definitions = definitions;
if (definitions != null) { if (definitions != null) {
String defs = StringUtils.arrayToCommaDelimitedString(definitions); String defs = StringUtils.arrayToCommaDelimitedString(definitions);

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ public class TilesConfigurerTests {
public void simpleBootstrap() { public void simpleBootstrap() {
MockServletContext sc = new MockServletContext(); MockServletContext sc = new MockServletContext();
TilesConfigurer tc = new TilesConfigurer(); TilesConfigurer tc = new TilesConfigurer();
tc.setDefinitions(new String[] {"/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml"}); tc.setDefinitions("/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml");
tc.setCheckRefresh(true); tc.setCheckRefresh(true);
tc.setServletContext(sc); tc.setServletContext(sc);
tc.afterPropertiesSet(); tc.afterPropertiesSet();