View Javadoc
1   /*
2    * Copyright 2002-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.web.servlet.resource;
18  
19  import java.util.List;
20  import javax.servlet.http.HttpServletRequest;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  import org.springframework.core.io.Resource;
26  
27  /**
28   * Base class for {@link org.springframework.web.servlet.resource.ResourceResolver}
29   * implementations. Provides consistent logging.
30   *
31   * @author Rossen Stoyanchev
32   * @since 4.1
33   */
34  public abstract class AbstractResourceResolver implements ResourceResolver {
35  
36  	protected final Log logger = LogFactory.getLog(getClass());
37  
38  
39  	@Override
40  	public Resource resolveResource(HttpServletRequest request, String requestPath,
41  			List<? extends Resource> locations, ResourceResolverChain chain) {
42  
43  		if (logger.isTraceEnabled()) {
44  			logger.trace("Resolving resource: requestPath=\"" + requestPath + "\"");
45  		}
46  		return resolveResourceInternal(request, requestPath, locations, chain);
47  	}
48  
49  	protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
50  			List<? extends Resource> locations, ResourceResolverChain chain);
51  
52  	@Override
53  	public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations,
54  			ResourceResolverChain chain) {
55  
56  		if (logger.isTraceEnabled()) {
57  			logger.trace("Resolving public URL for path=\"" + resourceUrlPath + "\"");
58  		}
59  
60  		return resolveUrlPathInternal(resourceUrlPath, locations, chain);
61  	}
62  
63  	protected abstract String resolveUrlPathInternal(String resourceUrlPath,
64  			List<? extends Resource> locations, ResourceResolverChain chain);
65  
66  }