View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      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-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
38   */
39  public class FtpFileProvider
40      extends AbstractOriginatingFileProvider
41  {
42      public final static String ATTR_FILE_ENTRY_PARSER = "FEP";
43  
44      final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
45      {
46          Capability.CREATE,
47          Capability.DELETE,
48          Capability.RENAME,
49          Capability.GET_TYPE,
50          Capability.LIST_CHILDREN,
51          Capability.READ_CONTENT,
52          Capability.GET_LAST_MODIFIED,
53          Capability.URI,
54          Capability.WRITE_CONTENT,
55          Capability.APPEND_CONTENT,
56          Capability.RANDOM_ACCESS_READ,
57      }));
58  
59  	public final static UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[]
60  		{
61  			UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD
62  		};
63  
64  	public FtpFileProvider()
65      {
66          super();
67          setFileNameParser(FtpFileNameParser.getInstance());
68      }
69  
70      /***
71       * Creates the filesystem.
72       */
73      protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
74          throws FileSystemException
75      {
76          // Create the file system
77          final GenericFileName rootName = (GenericFileName) name;
78  
79          FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions);
80          /*
81          FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(),
82              rootName.getPort(),
83              rootName.getUserName(),
84              rootName.getPassword(),
85              rootName.getPath(),
86              fileSystemOptions);
87          */
88  
89          return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
90      }
91  
92      public FileSystemConfigBuilder getConfigBuilder()
93      {
94          return FtpFileSystemConfigBuilder.getInstance();
95      }
96  
97      public Collection getCapabilities()
98      {
99          return capabilities;
100     }
101 }