KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > support > ServletContextResourceLoader


1 /*
2  * Copyright 2002-2005 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.context.support;
18
19 import javax.servlet.ServletContext JavaDoc;
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 JavaDoc servletContext;
43
44
45     /**
46      * Create a new ServletContextResourceLoader.
47      * @param servletContext the ServletContext to load resources with
48      */

49     public ServletContextResourceLoader(ServletContext JavaDoc servletContext) {
50         this.servletContext = servletContext;
51     }
52
53     /**
54      * This implementation supports file paths beneath the root of the web application.
55      * @see ServletContextResource
56      */

57     protected Resource getResourceByPath(String JavaDoc path) {
58         return new ServletContextResource(this.servletContext, path);
59     }
60
61 }
62
Popular Tags