1 16 package org.apache.commons.vfs.provider.url; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileName; 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 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.util.Arrays ; 30 import java.util.Collection ; 31 import java.util.Collections ; 32 33 38 public class UrlFileProvider 39 extends AbstractFileProvider 40 { 41 protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[] 42 { 43 Capability.READ_CONTENT, 44 Capability.URI, 45 Capability.GET_LAST_MODIFIED 46 })); 47 48 public UrlFileProvider() 49 { 50 super(); 51 setFileNameParser(new UrlFileNameParser()); 52 } 53 54 57 public synchronized FileObject findFile(final FileObject baseFile, 58 final String uri, 59 final FileSystemOptions fileSystemOptions) 60 throws FileSystemException 61 { 62 try 63 { 64 final URL url = new URL (uri); 65 66 URL rootUrl = new URL (url, "/"); 67 final String key = this.getClass().getName() + rootUrl.toString(); 68 FileSystem fs = findFileSystem(key, fileSystemOptions); 69 if (fs == null) 70 { 71 String extForm = rootUrl.toExternalForm(); 72 final FileName rootName = 73 getContext().parseURI(extForm); 74 fs = new UrlFileSystem(rootName, fileSystemOptions); 77 addFileSystem(key, fs); 78 } 79 return fs.resolveFile(url.getPath()); 80 } 81 catch (final MalformedURLException e) 82 { 83 throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri, e); 84 } 85 } 86 87 public FileSystemConfigBuilder getConfigBuilder() 88 { 89 return org.apache.commons.vfs.provider.res.ResourceFileSystemConfigBuilder.getInstance(); 90 } 91 92 public Collection getCapabilities() 93 { 94 return capabilities; 95 } 96 } 97 | Popular Tags |