1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.url;
18
19 import java.net.URI;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Collections;
23
24 import org.apache.commons.vfs2.Capability;
25 import org.apache.commons.vfs2.FileName;
26 import org.apache.commons.vfs2.FileObject;
27 import org.apache.commons.vfs2.FileSystem;
28 import org.apache.commons.vfs2.FileSystemConfigBuilder;
29 import org.apache.commons.vfs2.FileSystemException;
30 import org.apache.commons.vfs2.FileSystemOptions;
31 import org.apache.commons.vfs2.provider.AbstractFileProvider;
32
33
34
35
36 public class UrlFileProvider extends AbstractFileProvider {
37
38
39 protected static final Collection<Capability> capabilities = Collections.unmodifiableCollection(
40 Arrays.asList(Capability.READ_CONTENT, Capability.URI, Capability.GET_LAST_MODIFIED));
41
42 public UrlFileProvider() {
43 setFileNameParser(new UrlFileNameParser());
44 }
45
46
47
48
49
50
51
52
53
54
55 @Override
56 public synchronized FileObjectObject.html#FileObject">FileObject findFile(final FileObject baseFile, final String fileUri,
57 final FileSystemOptions fileSystemOptions) throws FileSystemException {
58 try {
59 final URI uri = URI.create(fileUri);
60 final URI rootUri = uri.resolve("/");
61 final String key = this.getClass().getName() + rootUri.toString();
62 FileSystem fs = findFileSystem(key, fileSystemOptions);
63 if (fs == null) {
64 final String extForm = rootUri.toString();
65 final FileName rootName = getContext().parseURI(extForm);
66
67
68 fs = new UrlFileSystem(rootName, fileSystemOptions);
69 addFileSystem(key, fs);
70 }
71 return fs.resolveFile(uri.getPath());
72 } catch (final Exception e) {
73 throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", fileUri, e);
74 }
75 }
76
77 @Override
78 public FileSystemConfigBuilder getConfigBuilder() {
79 return org.apache.commons.vfs2.provider.res.ResourceFileSystemConfigBuilder.getInstance();
80 }
81
82 @Override
83 public Collection<Capability> getCapabilities() {
84 return capabilities;
85 }
86 }