01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.vfs.provider.ftp;
18:
19: import org.apache.commons.vfs.Capability;
20: import org.apache.commons.vfs.FileName;
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.UserAuthenticationData;
26: import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
27: import org.apache.commons.vfs.provider.GenericFileName;
28:
29: import java.util.Arrays;
30: import java.util.Collection;
31: import java.util.Collections;
32:
33: /**
34: * A provider for FTP file systems.
35: *
36: * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
37: * @version $Revision: 480428 $ $Date: 2006-11-28 22:15:24 -0800 (Tue, 28 Nov 2006) $
38: */
39: public class FtpFileProvider extends AbstractOriginatingFileProvider {
40: public final static String ATTR_FILE_ENTRY_PARSER = "FEP";
41:
42: final static Collection capabilities = Collections
43: .unmodifiableCollection(Arrays.asList(new Capability[] {
44: Capability.CREATE, Capability.DELETE,
45: Capability.RENAME, Capability.GET_TYPE,
46: Capability.LIST_CHILDREN, Capability.READ_CONTENT,
47: Capability.GET_LAST_MODIFIED, Capability.URI,
48: Capability.WRITE_CONTENT,
49: Capability.APPEND_CONTENT,
50: Capability.RANDOM_ACCESS_READ, }));
51:
52: public final static UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] {
53: UserAuthenticationData.USERNAME,
54: UserAuthenticationData.PASSWORD };
55:
56: public FtpFileProvider() {
57: super ();
58: setFileNameParser(FtpFileNameParser.getInstance());
59: }
60:
61: /**
62: * Creates the filesystem.
63: */
64: protected FileSystem doCreateFileSystem(final FileName name,
65: final FileSystemOptions fileSystemOptions)
66: throws FileSystemException {
67: // Create the file system
68: final GenericFileName rootName = (GenericFileName) name;
69:
70: FTPClientWrapper ftpClient = new FTPClientWrapper(rootName,
71: fileSystemOptions);
72: /*
73: FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(),
74: rootName.getPort(),
75: rootName.getUserName(),
76: rootName.getPassword(),
77: rootName.getPath(),
78: fileSystemOptions);
79: */
80:
81: return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
82: }
83:
84: public FileSystemConfigBuilder getConfigBuilder() {
85: return FtpFileSystemConfigBuilder.getInstance();
86: }
87:
88: public Collection getCapabilities() {
89: return capabilities;
90: }
91: }
|