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.springframework.core.io.Resource; 023 024/** 025 * A strategy for resolving a request to a server-side resource. 026 * 027 * <p>Provides mechanisms for resolving an incoming request to an actual 028 * {@link org.springframework.core.io.Resource} and for obtaining the 029 * public URL path that clients should use when requesting the resource. 030 * 031 * @author Jeremy Grelle 032 * @author Rossen Stoyanchev 033 * @author Sam Brannen 034 * @since 4.1 035 * @see org.springframework.web.servlet.resource.ResourceResolverChain 036 */ 037public interface ResourceResolver { 038 039 /** 040 * Resolve the supplied request and request path to a {@link Resource} that 041 * exists under one of the given resource locations. 042 * @param request the current request 043 * @param requestPath the portion of the request path to use 044 * @param locations the locations to search in when looking up resources 045 * @param chain the chain of remaining resolvers to delegate to 046 * @return the resolved resource or {@code null} if unresolved 047 */ 048 Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations, 049 ResourceResolverChain chain); 050 051 /** 052 * Resolve the externally facing <em>public</em> URL path for clients to use 053 * to access the resource that is located at the given <em>internal</em> 054 * resource path. 055 * <p>This is useful when rendering URL links to clients. 056 * @param resourcePath the internal resource path 057 * @param locations the locations to search in when looking up resources 058 * @param chain the chain of resolvers to delegate to 059 * @return the resolved public URL path or {@code null} if unresolved 060 */ 061 String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain); 062 063}