001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.view.tiles2; 018 019import java.io.IOException; 020import java.net.URL; 021import java.util.LinkedHashSet; 022import java.util.Set; 023import javax.servlet.ServletContext; 024 025import org.apache.tiles.servlet.context.ServletTilesApplicationContext; 026 027import org.springframework.core.io.Resource; 028import org.springframework.core.io.support.ResourcePatternResolver; 029import org.springframework.util.CollectionUtils; 030import org.springframework.util.ObjectUtils; 031import org.springframework.web.context.support.ServletContextResourcePatternResolver; 032 033/** 034 * Spring-specific subclass of the Tiles ServletTilesApplicationContext. 035 * 036 * <p><b>NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed 037 * as of Spring Framework 5.0.</b>. 038 * 039 * @author Juergen Hoeller 040 * @since 4.0.1 041 * @deprecated as of Spring 4.2, in favor of Tiles 3 042 */ 043@Deprecated 044public class SpringWildcardServletTilesApplicationContext extends ServletTilesApplicationContext { 045 046 private final ResourcePatternResolver resolver; 047 048 049 public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) { 050 super(servletContext); 051 this.resolver = new ServletContextResourcePatternResolver(servletContext); 052 } 053 054 055 @Override 056 public URL getResource(String path) throws IOException { 057 Set<URL> urlSet = getResources(path); 058 if (!CollectionUtils.isEmpty(urlSet)) { 059 return urlSet.iterator().next(); 060 } 061 return null; 062 } 063 064 @Override 065 public Set<URL> getResources(String path) throws IOException { 066 Set<URL> urlSet = null; 067 Resource[] resources = this.resolver.getResources(path); 068 if (!ObjectUtils.isEmpty(resources)) { 069 urlSet = new LinkedHashSet<URL>(resources.length); 070 for (Resource resource : resources) { 071 urlSet.add(resource.getURL()); 072 } 073 } 074 return urlSet; 075 } 076 077}