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