1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.webdav4;
18
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.Collections;
22
23 import org.apache.commons.vfs2.Capability;
24 import org.apache.commons.vfs2.FileName;
25 import org.apache.commons.vfs2.FileObject;
26 import org.apache.commons.vfs2.FileSystem;
27 import org.apache.commons.vfs2.FileSystemConfigBuilder;
28 import org.apache.commons.vfs2.FileSystemException;
29 import org.apache.commons.vfs2.FileSystemOptions;
30 import org.apache.commons.vfs2.UserAuthenticationData;
31 import org.apache.commons.vfs2.provider.GenericFileName;
32 import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
33 import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
34 import org.apache.http.client.HttpClient;
35 import org.apache.http.client.protocol.HttpClientContext;
36
37
38
39
40
41
42 public class Webdav4FileProvider extends Http4FileProvider {
43
44
45
46
47
48
49 @Deprecated
50 public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] {
51 UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD };
52
53
54 public static final Collection<Capability> DEFAULT_CAPABILITIES =
55 Collections.unmodifiableCollection(
56 Arrays.asList(
57 Capability.CREATE,
58 Capability.DELETE,
59 Capability.RENAME,
60 Capability.GET_TYPE,
61 Capability.LIST_CHILDREN,
62 Capability.READ_CONTENT,
63 Capability.URI,
64 Capability.WRITE_CONTENT,
65 Capability.GET_LAST_MODIFIED,
66 Capability.ATTRIBUTES,
67 Capability.RANDOM_ACCESS_READ,
68 Capability.DIRECTORY_READ_CONTENT
69 )
70 );
71
72
73 protected static final Collection<Capability> capabilities = DEFAULT_CAPABILITIES;
74
75 public Webdav4FileProvider() {
76 setFileNameParser(Webdav4FileNameParser.getInstance());
77 }
78
79
80
81
82
83
84
85
86
87
88
89 @Override
90 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
91 throws FileSystemException {
92
93 final GenericFileName/../../org/apache/commons/vfs2/provider/GenericFileName.html#GenericFileName">GenericFileName rootName = (GenericFileName) name;
94
95 final FileSystemOptioFileSystemOptionsileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;
96
97 UserAuthenticationData authData = null;
98 final HttpClient httpClient;
99 final HttpClientContext httpClientContext;
100
101 try {
102 final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
103 authData = UserAuthenticatorUtils.authenticate(fsOpts, AUTHENTICATOR_TYPES);
104 httpClientContext = createHttpClientContext(builder, rootName, fsOpts, authData);
105 httpClient = createHttpClient(builder, rootName, fsOpts);
106 } finally {
107 UserAuthenticatorUtils.cleanup(authData);
108 }
109
110 return new Webdav4FileSystem(rootName, fsOpts, httpClient, httpClientContext);
111 }
112
113 @Override
114 public FileSystemConfigBuilder getConfigBuilder() {
115 return Webdav4FileSystemConfigBuilder.getInstance();
116 }
117
118 @Override
119 public Collection<Capability> getCapabilities() {
120 return capabilities;
121 }
122 }