001/*
002 * Copyright 2002-2018 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 contract for invoking a chain of {@link ResourceResolver ResourceResolvers} where each resolver
028 * is given a reference to the chain allowing it to delegate when necessary.
029 *
030 * @author Jeremy Grelle
031 * @author Rossen Stoyanchev
032 * @author Sam Brannen
033 * @since 4.1
034 */
035public interface ResourceResolverChain {
036
037        /**
038         * Resolve the supplied request and request path to a {@link Resource} that
039         * exists under one of the given resource locations.
040         * @param request the current request
041         * @param requestPath the portion of the request path to use
042         * @param locations the locations to search in when looking up resources
043         * @return the resolved resource, or {@code null} if unresolved
044         */
045        @Nullable
046        Resource resolveResource(
047                        @Nullable HttpServletRequest request, String requestPath, List<? extends Resource> locations);
048
049        /**
050         * Resolve the externally facing <em>public</em> URL path for clients to use
051         * to access the resource that is located at the given <em>internal</em>
052         * resource path.
053         * <p>This is useful when rendering URL links to clients.
054         * @param resourcePath the internal resource path
055         * @param locations the locations to search in when looking up resources
056         * @return the resolved public URL path, or {@code null} if unresolved
057         */
058        @Nullable
059        String resolveUrlPath(String resourcePath, List<? extends Resource> locations);
060
061}