diff --git a/build.gradle b/build.gradle index 032d3683674..7a0a14dcfd2 100644 --- a/build.gradle +++ b/build.gradle @@ -521,10 +521,6 @@ project('spring-webmvc-tiles3') { compile("javax.servlet:jstl:1.1.2", provided) compile("javax.servlet.jsp:jsp-api:2.1", provided) compile("org.apache.tiles:tiles-request-api:1.0.1", optional) - compile("org.apache.tiles:tiles-request-servlet-wildcard:1.0.1") { dep-> - optional dep - exclude group: 'org.springframework', module: 'spring-web' - } compile("org.apache.tiles:tiles-api:3.0.1", optional) compile("org.apache.tiles:tiles-core:3.0.1", optional) compile("org.apache.tiles:tiles-servlet:3.0.1", optional) 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 new file mode 100644 index 00000000000..25d396b87e4 --- /dev/null +++ b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java @@ -0,0 +1,102 @@ +/* + * Copyright 2002-2012 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. + * 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.springframework.web.servlet.view.tiles3; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +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.web.context.support.ServletContextResourcePatternResolver; + +/** + * Spring-specific subclass of the Tiles ServletApplicationContext. + * + * @author Rossen Stoyanchev + * @since 3.2 + */ +public class SpringWildcardServletTilesApplicationContext extends ServletApplicationContext { + + /** + * The pattern resolver. + */ + protected ResourcePatternResolver resolver; + + /** + * Constructor. + * + * @param servletContext The servlet context. + */ + public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) { + super(servletContext); + resolver = new ServletContextResourcePatternResolver(servletContext); + } + + @Override + public ApplicationResource getResource(String localePath) { + ApplicationResource retValue = null; + Collection urlSet = getResources(localePath); + if (urlSet != null && !urlSet.isEmpty()) { + retValue = urlSet.iterator().next(); + } + return retValue; + } + + @Override + public ApplicationResource getResource(ApplicationResource base, Locale locale) { + ApplicationResource retValue = null; + Collection urlSet = getResources(base.getLocalePath(locale)); + if (urlSet != null && !urlSet.isEmpty()) { + retValue = urlSet.iterator().next(); + } + return retValue; + } + + @Override + public Collection getResources(String path) { + Resource[] resources; + try { + resources = resolver.getResources(path); + } catch (IOException e) { + return Collections. emptyList(); + } + Collection resourceList = new ArrayList(); + if (resources != null && resources.length > 0) { + for (int i = 0; i < resources.length; i++) { + URL url; + try { + url = resources[i].getURL(); + resourceList.add(new URLApplicationResource(url.toExternalForm(), url)); + } catch (IOException e) { + // shouldn't happen with the kind of resources we're using + throw new IllegalArgumentException("no URL for " + resources[i].toString(), e); + } + } + } + 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 7b23a60cdc2..06db96d38df 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 @@ -51,7 +51,6 @@ import org.apache.tiles.locale.LocaleResolver; import org.apache.tiles.preparer.factory.PreparerFactory; import org.apache.tiles.request.ApplicationContext; import org.apache.tiles.request.ApplicationResource; -import org.apache.tiles.request.servlet.wildcard.WildcardServletApplicationContext; import org.apache.tiles.startup.DefaultTilesInitializer; import org.apache.tiles.startup.TilesInitializer; import org.slf4j.Logger; @@ -249,8 +248,8 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D */ public void afterPropertiesSet() throws TilesException { - WildcardServletApplicationContext preliminaryContext = - new WildcardServletApplicationContext(this.servletContext); + SpringWildcardServletTilesApplicationContext preliminaryContext = + new SpringWildcardServletTilesApplicationContext(this.servletContext); if (this.tilesInitializer == null) { this.tilesInitializer = new SpringTilesInitializer();