1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.resource;
20
21 import java.io.IOException;
22 import java.net.URL;
23
24 import javax.servlet.ServletContext;
25
26 /**
27 * A resource loader implementation which loads resources
28 * using the servlet context.
29 *
30 */
31 public class ServletContextResourceLoader extends ResourceLoader
32 {
33 /**
34 * Constructs a new ServletContextResourceLoader.
35 *
36 * @param context the servlet context
37 */
38 public ServletContextResourceLoader(
39 ServletContext context)
40 {
41 _context = context;
42 }
43
44 /**
45 * Constructs a new ServletContextResourceLoader with specified parent
46 * resource loader.
47 *
48 * @param context the servlet context
49 * @param parent the parent resource loader
50 */
51 public ServletContextResourceLoader(
52 ServletContext context,
53 ResourceLoader parent)
54 {
55 super(parent);
56 _context = context;
57 }
58
59 @Override
60 protected URL findResource(
61 String path) throws IOException
62 {
63 return _context.getResource(path);
64 }
65
66 /*
67 protected Enumeration findResources(
68 String path) throws IOException
69 {
70 return new IteratorEnumeration(_context.getResourcePaths(path).iterator());
71 }
72 */
73
74 private final ServletContext _context;
75 }