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.springframework.core.io.Resource;
23  
24  /**
25   * A strategy for resolving a request to a server-side resource.
26   *
27   * <p>Provides mechanisms for resolving an incoming request to an actual
28   * {@link org.springframework.core.io.Resource} and for obtaining the public
29   * URL path that clients should use when requesting the resource.
30   *
31   * @author Jeremy Grelle
32   * @author Rossen Stoyanchev
33   * @author Sam Brannen
34   * @since 4.1
35   * @see org.springframework.web.servlet.resource.ResourceResolverChain
36   */
37  public interface ResourceResolver {
38  
39  	/**
40  	 * Resolve the supplied request and request path to a {@link Resource} that
41  	 * exists under one of the given resource locations.
42  	 *
43  	 * @param request the current request
44  	 * @param requestPath the portion of the request path to use
45  	 * @param locations the locations to search in when looking up resources
46  	 * @param chain the chain of remaining resolvers to delegate to
47  	 * @return the resolved resource or {@code null} if unresolved
48  	 */
49  	Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations,
50  			ResourceResolverChain chain);
51  
52  	/**
53  	 * Resolve the externally facing <em>public</em> URL path for clients to use
54  	 * to access the resource that is located at the given <em>internal</em>
55  	 * resource path.
56  	 *
57  	 * <p>This is useful when rendering URL links to clients.
58  	 *
59  	 * @param resourcePath the internal resource path
60  	 * @param locations the locations to search in when looking up resources
61  	 * @param chain the chain of resolvers to delegate to
62  	 * @return the resolved public URL path or {@code null} if unresolved
63  	 */
64  	String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain);
65  
66  }