1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.provider.res;
18
19 import org.apache.commons.vfs.Capability;
20 import org.apache.commons.vfs.FileObject;
21 import org.apache.commons.vfs.FileSystem;
22 import org.apache.commons.vfs.FileSystemConfigBuilder;
23 import org.apache.commons.vfs.FileSystemException;
24 import org.apache.commons.vfs.FileSystemOptions;
25 import org.apache.commons.vfs.provider.AbstractFileProvider;
26 import org.apache.commons.vfs.provider.UriParser;
27
28 import java.net.URL;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.Collections;
32
33 /***
34 * Description
35 *
36 * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
37 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
38 */
39 public class ResourceFileProvider extends AbstractFileProvider
40 {
41 protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
42 {
43 Capability.DISPATCHER
44 }));
45
46 public ResourceFileProvider()
47 {
48 super();
49 }
50
51 /***
52 * Locates a file object, by absolute URI.
53 */
54 public FileObject findFile(final FileObject baseFile,
55 final String uri,
56 final FileSystemOptions fileSystemOptions)
57 throws FileSystemException
58 {
59 StringBuffer buf = new StringBuffer(80);
60 UriParser.extractScheme(uri, buf);
61 String resourceName = buf.toString();
62
63 ClassLoader cl = ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions);
64 if (cl == null)
65 {
66 cl = getClass().getClassLoader();
67 }
68 final URL url = cl.getResource(resourceName);
69
70 if (url == null)
71 {
72 throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri);
73 }
74
75 FileObject fo = getContext().getFileSystemManager().resolveFile(url.toExternalForm());
76 return fo;
77 }
78
79 public FileSystemConfigBuilder getConfigBuilder()
80 {
81 return org.apache.commons.vfs.provider.res.ResourceFileSystemConfigBuilder.getInstance();
82 }
83
84 public void closeFileSystem(FileSystem filesystem)
85 {
86
87 }
88
89 public Collection getCapabilities()
90 {
91 return capabilities;
92 }
93 }