1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.webdav4s;
18
19 import java.util.Collection;
20
21 import org.apache.commons.vfs2.Capability;
22 import org.apache.commons.vfs2.FileName;
23 import org.apache.commons.vfs2.FileObject;
24 import org.apache.commons.vfs2.FileSystem;
25 import org.apache.commons.vfs2.FileSystemConfigBuilder;
26 import org.apache.commons.vfs2.FileSystemException;
27 import org.apache.commons.vfs2.FileSystemOptions;
28 import org.apache.commons.vfs2.UserAuthenticationData;
29 import org.apache.commons.vfs2.provider.GenericFileName;
30 import org.apache.commons.vfs2.provider.http4s.Http4sFileProvider;
31 import org.apache.commons.vfs2.provider.webdav4.Webdav4FileProvider;
32 import org.apache.commons.vfs2.provider.webdav4.Webdav4FileSystem;
33 import org.apache.commons.vfs2.provider.webdav4.Webdav4FileSystemConfigBuilder;
34 import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
35 import org.apache.http.client.HttpClient;
36 import org.apache.http.client.protocol.HttpClientContext;
37
38
39
40
41
42
43 public class Webdav4sFileProvider extends Http4sFileProvider {
44
45
46 protected static final Collection<Capability> capabilities = Webdav4FileProvider.DEFAULT_CAPABILITIES;
47
48 public Webdav4sFileProvider() {
49 setFileNameParser(Webdav4sFileNameParser.getInstance());
50 }
51
52
53
54
55
56
57
58
59
60
61
62 @Override
63 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
64 throws FileSystemException {
65
66 final GenericFileName/../../org/apache/commons/vfs2/provider/GenericFileName.html#GenericFileName">GenericFileName rootName = (GenericFileName) name;
67
68 final FileSystemOptioFileSystemOptionsileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;
69
70 UserAuthenticationData authData = null;
71 final HttpClient httpClient;
72 final HttpClientContext httpClientContext;
73
74 try {
75 final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
76 authData = UserAuthenticatorUtils.authenticate(fsOpts, Webdav4FileProvider.AUTHENTICATOR_TYPES);
77 httpClientContext = createHttpClientContext(builder, rootName, fsOpts, authData);
78 httpClient = createHttpClient(builder, rootName, fsOpts);
79 } finally {
80 UserAuthenticatorUtils.cleanup(authData);
81 }
82
83 return new Webdav4FileSystem(rootName, fsOpts, httpClient, httpClientContext) {
84 };
85 }
86
87 @Override
88 public FileSystemConfigBuilder getConfigBuilder() {
89 return Webdav4FileSystemConfigBuilder.getInstance();
90 }
91
92 @Override
93 public Collection<Capability> getCapabilities() {
94 return capabilities;
95 }
96
97 }