diff --git a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java index ad4699657a..e79fe8d5dd 100644 --- a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java +++ b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -37,6 +37,7 @@ import org.springframework.web.context.support.ServletContextResourcePatternReso * Spring-specific subclass of the Tiles ServletApplicationContext. * * @author Rossen Stoyanchev + * @author Juergen Hoeller * @since 3.2 */ public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext { @@ -77,24 +78,26 @@ public class SpringWildcardServletTilesApplicationContext extends ServletApplica resources = this.resolver.getResources(path); } catch (IOException ex) { - return Collections. emptyList(); + ((ServletContext) getContext()).log("Resource retrieval failed for path: " + path, ex); + return Collections.emptyList(); } - Collection resourceList = new ArrayList(); - if (!ObjectUtils.isEmpty(resources)) { - for (Resource resource : resources) { - URL url; - try { - url = resource.getURL(); - resourceList.add(new URLApplicationResource(url.toExternalForm(), url)); - } - catch (IOException ex) { - // shouldn't happen with the kind of resources we're using - throw new IllegalArgumentException("No URL for " + resource.toString(), ex); - } + if (ObjectUtils.isEmpty(resources)) { + ((ServletContext) getContext()).log("No resources found for path pattern: " + path); + return Collections.emptyList(); + } + + Collection resourceList = new ArrayList(resources.length); + for (Resource resource : resources) { + try { + URL url = resource.getURL(); + resourceList.add(new URLApplicationResource(url.toExternalForm(), url)); + } + catch (IOException ex) { + // Shouldn't happen with the kind of resources we're using + throw new IllegalArgumentException("No URL for " + resource, ex); } } return resourceList; } } - diff --git a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java index 28d9f767c0..3fe4adcc0d 100644 --- a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java +++ b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.view.tiles3; +import java.util.Collection; import java.util.LinkedList; import java.util.List; import javax.el.ArrayELResolver; @@ -285,7 +286,10 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D if (definitions != null) { List result = new LinkedList(); for (String definition : definitions) { - result.addAll(applicationContext.getResources(definition)); + Collection resources = applicationContext.getResources(definition); + if (resources != null) { + result.addAll(resources); + } } return result; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java index da6383a734..59a2e633da 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -19,8 +19,8 @@ package org.springframework.web.servlet.view.tiles2; import java.io.IOException; import java.net.URL; import java.util.Enumeration; -import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import javax.servlet.ServletContext; @@ -32,6 +32,8 @@ import org.apache.tiles.servlet.context.ServletTilesApplicationContext; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import org.springframework.web.context.support.ServletContextResourcePatternResolver; /** @@ -89,7 +91,7 @@ public class SpringTilesApplicationContextFactory extends AbstractTilesApplicati public URL getResource(String path) throws IOException { URL retValue = null; Set urlSet = getResources(path); - if (urlSet != null && !urlSet.isEmpty()) { + if (!CollectionUtils.isEmpty(urlSet)) { retValue = urlSet.iterator().next(); } return retValue; @@ -99,8 +101,8 @@ public class SpringTilesApplicationContextFactory extends AbstractTilesApplicati public Set getResources(String path) throws IOException { Set urlSet = null; Resource[] resources = this.resolver.getResources(path); - if (resources != null && resources.length > 0) { - urlSet = new HashSet(); + if (!ObjectUtils.isEmpty(resources)) { + urlSet = new LinkedHashSet(resources.length); for (Resource resource : resources) { urlSet.add(resource.getURL()); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java index e8babd933e..a4f4f57b67 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java @@ -25,6 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import javax.servlet.ServletContext; import javax.servlet.jsp.JspFactory; @@ -420,7 +421,10 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D try { List result = new LinkedList(); for (String definition : definitions) { - result.addAll(applicationContext.getResources(definition)); + Set resources = applicationContext.getResources(definition); + if (resources != null) { + result.addAll(resources); + } } return result; }