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.vfs2.provider.ftp;
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.FileSystem;
26  import org.apache.commons.vfs2.FileSystemConfigBuilder;
27  import org.apache.commons.vfs2.FileSystemException;
28  import org.apache.commons.vfs2.FileSystemOptions;
29  import org.apache.commons.vfs2.UserAuthenticationData;
30  import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
31  import org.apache.commons.vfs2.provider.GenericFileName;
32  
33  /**
34   * A provider for FTP file systems.
35   */
36  public class FtpFileProvider extends AbstractOriginatingFileProvider {
37  
38      /**
39       * File Entry Parser.
40       */
41      public static final String ATTR_FILE_ENTRY_PARSER = "FEP";
42  
43      /**
44       * Authenticator types.
45       */
46      public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] {
47              UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD };
48  
49      static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays.asList(Capability.CREATE, Capability.DELETE, Capability.RENAME, Capability.GET_TYPE,
50              Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.GET_LAST_MODIFIED, Capability.URI,
51              Capability.WRITE_CONTENT, Capability.APPEND_CONTENT, Capability.RANDOM_ACCESS_READ));
52  
53      /**
54       * Constructs a new provider.
55       */
56      public FtpFileProvider() {
57          super();
58          setFileNameParser(FtpFileNameParser.getInstance());
59      }
60  
61      /**
62       * Creates the file system.
63       */
64      @Override
65      protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
66              throws FileSystemException {
67          // Create the file system
68          final GenericFileName/../../org/apache/commons/vfs2/provider/GenericFileName.html#GenericFileName">GenericFileName rootName = (GenericFileName) name;
69  
70          final FTPClientWrapperp/FTPClientWrapper.html#FTPClientWrapper">FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions);
71          /*
72           * FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
73           * rootName.getUserName(), rootName.getPassword(), rootName.getPath(), fileSystemOptions);
74           */
75  
76          return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
77      }
78  
79      @Override
80      public FileSystemConfigBuilder getConfigBuilder() {
81          return FtpFileSystemConfigBuilder.getInstance();
82      }
83  
84      @Override
85      public Collection<Capability> getCapabilities() {
86          return capabilities;
87      }
88  }