Remove tiles-request-servlet-wildcard dependency

The tiles-request-servlet-wildcard contained only one class that is an
implementation of the tiles-request ServletApplicationContext using a
Spring ApplicationContext to look up resources. It makes sense for this
class to be part of the Spring Tiles 3 integration.

Issue: SPR-10054
This commit is contained in:
Rossen Stoyanchev 2012-12-03 14:30:18 -05:00
parent d3c977b54b
commit 42a928596f
3 changed files with 104 additions and 7 deletions

View File

@ -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)

View File

@ -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<ApplicationResource> 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<ApplicationResource> urlSet = getResources(base.getLocalePath(locale));
if (urlSet != null && !urlSet.isEmpty()) {
retValue = urlSet.iterator().next();
}
return retValue;
}
@Override
public Collection<ApplicationResource> getResources(String path) {
Resource[] resources;
try {
resources = resolver.getResources(path);
} catch (IOException e) {
return Collections.<ApplicationResource> emptyList();
}
Collection<ApplicationResource> resourceList = new ArrayList<ApplicationResource>();
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;
}
}

View File

@ -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();