01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.context.support;
18:
19: import javax.servlet.ServletContext;
20:
21: import org.springframework.core.io.DefaultResourceLoader;
22: import org.springframework.core.io.Resource;
23:
24: /**
25: * ResourceLoader implementation that resolves paths as ServletContext
26: * resources, for use outside a WebApplicationContext (for example,
27: * in a HttpServletBean or GenericFilterBean subclass).
28: *
29: * <p>Within a WebApplicationContext, resource paths are automatically
30: * resolved as ServletContext resources by the context implementation.
31: *
32: * @author Juergen Hoeller
33: * @since 1.0.2
34: * @see #getResourceByPath
35: * @see ServletContextResource
36: * @see org.springframework.web.context.WebApplicationContext
37: * @see org.springframework.web.servlet.HttpServletBean
38: * @see org.springframework.web.filter.GenericFilterBean
39: */
40: public class ServletContextResourceLoader extends DefaultResourceLoader {
41:
42: private final ServletContext servletContext;
43:
44: /**
45: * Create a new ServletContextResourceLoader.
46: * @param servletContext the ServletContext to load resources with
47: */
48: public ServletContextResourceLoader(ServletContext servletContext) {
49: this .servletContext = servletContext;
50: }
51:
52: /**
53: * This implementation supports file paths beneath the root of the web application.
54: * @see ServletContextResource
55: */
56: protected Resource getResourceByPath(String path) {
57: return new ServletContextResource(this.servletContext, path);
58: }
59:
60: }
|