001/* 002 * Copyright 2002-2015 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.resource; 018 019import java.util.List; 020import javax.servlet.http.HttpServletRequest; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024 025import org.springframework.core.io.Resource; 026 027/** 028 * Base class for {@link org.springframework.web.servlet.resource.ResourceResolver} 029 * implementations. Provides consistent logging. 030 * 031 * @author Rossen Stoyanchev 032 * @since 4.1 033 */ 034public abstract class AbstractResourceResolver implements ResourceResolver { 035 036 protected final Log logger = LogFactory.getLog(getClass()); 037 038 039 @Override 040 public Resource resolveResource(HttpServletRequest request, String requestPath, 041 List<? extends Resource> locations, ResourceResolverChain chain) { 042 043 if (logger.isTraceEnabled()) { 044 logger.trace("Resolving resource for request path \"" + requestPath + "\""); 045 } 046 return resolveResourceInternal(request, requestPath, locations, chain); 047 } 048 049 @Override 050 public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations, 051 ResourceResolverChain chain) { 052 053 if (logger.isTraceEnabled()) { 054 logger.trace("Resolving public URL for resource path \"" + resourceUrlPath + "\""); 055 } 056 057 return resolveUrlPathInternal(resourceUrlPath, locations, chain); 058 } 059 060 061 protected abstract Resource resolveResourceInternal(HttpServletRequest request, String requestPath, 062 List<? extends Resource> locations, ResourceResolverChain chain); 063 064 protected abstract String resolveUrlPathInternal(String resourceUrlPath, 065 List<? extends Resource> locations, ResourceResolverChain chain); 066 067}