1 16 package org.apache.commons.vfs.provider.res; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystem; 21 import org.apache.commons.vfs.FileSystemConfigBuilder; 22 import org.apache.commons.vfs.FileSystemException; 23 import org.apache.commons.vfs.FileSystemOptions; 24 import org.apache.commons.vfs.provider.AbstractFileProvider; 25 import org.apache.commons.vfs.provider.UriParser; 26 27 import java.net.URL ; 28 import java.util.Arrays ; 29 import java.util.Collection ; 30 import java.util.Collections ; 31 32 37 public class ResourceFileProvider extends AbstractFileProvider 38 { 39 protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[] 40 { 41 Capability.DISPATCHER 42 })); 43 44 public ResourceFileProvider() 45 { 46 super(); 47 } 48 49 52 public FileObject findFile(final FileObject baseFile, 53 final String uri, 54 final FileSystemOptions fileSystemOptions) 55 throws FileSystemException 56 { 57 StringBuffer buf = new StringBuffer (80); 58 UriParser.extractScheme(uri, buf); 59 String resourceName = buf.toString(); 60 61 ClassLoader cl = ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions); 62 if (cl == null) 63 { 64 cl = getClass().getClassLoader(); 65 } 66 final URL url = cl.getResource(resourceName); 67 68 if (url == null) 69 { 70 throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri); 71 } 72 73 FileObject fo = getContext().getFileSystemManager().resolveFile(url.toExternalForm()); 74 return fo; 75 } 76 77 public FileSystemConfigBuilder getConfigBuilder() 78 { 79 return org.apache.commons.vfs.provider.res.ResourceFileSystemConfigBuilder.getInstance(); 80 } 81 82 public void closeFileSystem(FileSystem filesystem) 83 { 84 } 86 87 public Collection getCapabilities() 88 { 89 return capabilities; 90 } 91 } 92 | Popular Tags |