1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.webdav;
18
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.Collections;
22
23 import org.apache.commons.httpclient.HttpClient;
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.UserAuthenticationData;
32 import org.apache.commons.vfs2.provider.GenericFileName;
33 import org.apache.commons.vfs2.provider.http.HttpClientFactory;
34 import org.apache.commons.vfs2.provider.http.HttpFileProvider;
35 import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
36
37
38
39
40
41
42 public class WebdavFileProvider extends HttpFileProvider {
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 protected static final Collection<Capability> capabilities = Collections
55 .unmodifiableCollection(Arrays.asList(Capability.CREATE, Capability.DELETE, Capability.RENAME, Capability.GET_TYPE,
56 Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.URI, Capability.WRITE_CONTENT,
57 Capability.GET_LAST_MODIFIED, Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ,
58 Capability.DIRECTORY_READ_CONTENT));
59
60 public WebdavFileProvider() {
61 setFileNameParser(WebdavFileNameParser.getInstance());
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 @Override
76 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
77 throws FileSystemException {
78
79 final GenericFileName/../../org/apache/commons/vfs2/provider/GenericFileName.html#GenericFileName">GenericFileName rootName = (GenericFileName) name;
80 final FileSystemOptioFileSystemOptionsileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;
81
82 UserAuthenticationData authData = null;
83 HttpClient httpClient;
84 try {
85 authData = UserAuthenticatorUtils.authenticate(fsOpts, AUTHENTICATOR_TYPES);
86
87 httpClient = HttpClientFactory.createConnection(WebdavFileSystemConfigBuilder.getInstance(), "http",
88 rootName.getHostName(), rootName.getPort(),
89 UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
90 UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))),
91 UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
92 UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))),
93 fsOpts);
94 } finally {
95 UserAuthenticatorUtils.cleanup(authData);
96 }
97
98 return new WebdavFileSystem(rootName, httpClient, fsOpts);
99 }
100
101 @Override
102 public FileSystemConfigBuilder getConfigBuilder() {
103 return WebdavFileSystemConfigBuilder.getInstance();
104 }
105
106 @Override
107 public Collection<Capability> getCapabilities() {
108 return capabilities;
109 }
110 }