01: /*
02: * $Id$ $Revision$ $Date$
03: *
04: * ==============================================================================
05: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
06: * use this file except in compliance with the License. You may obtain a copy of
07: * the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17: package wicket.util.file;
18:
19: import java.net.URL;
20:
21: /**
22: * Path for working with OSGi bundles.
23: *
24: * @author Timur Mehrvarz
25: */
26: public final class OsgiPath implements IResourceFinder {
27: /** ClassLoader to be used for locating resources. */
28: final ClassLoader classLoader;
29:
30: /**
31: * Constructor.
32: *
33: * @param classLoader
34: * class loader to be used for locating resources
35: */
36: public OsgiPath(ClassLoader classLoader) {
37: this .classLoader = classLoader;
38: }
39:
40: /**
41: * Looks for a given pathname along this path in the OSGi (jar) bundle.
42: *
43: * @param pathname
44: * The filename with possible path
45: * @return The url located on the path
46: */
47: public URL find(final String pathname) {
48: String resourcePathName = "/" + pathname;
49: return classLoader.getResource(resourcePathName);
50: }
51: }
|