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
50              .asList(new Capability[] { Capability.CREATE, Capability.DELETE, Capability.RENAME, Capability.GET_TYPE,
51                      Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.GET_LAST_MODIFIED, Capability.URI,
52                      Capability.WRITE_CONTENT, Capability.APPEND_CONTENT, Capability.RANDOM_ACCESS_READ, }));
53  
54      /**
55       * Constructs a new provider.
56       */
57      public FtpFileProvider() {
58          super();
59          setFileNameParser(FtpFileNameParser.getInstance());
60      }
61  
62      /**
63       * Creates the file system.
64       */
65      @Override
66      protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
67              throws FileSystemException {
68          // Create the file system
69          final GenericFileName/../../org/apache/commons/vfs2/provider/GenericFileName.html#GenericFileName">GenericFileName rootName = (GenericFileName) name;
70  
71          final FTPClientWrapperp/FTPClientWrapper.html#FTPClientWrapper">FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions);
72          /*
73           * FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
74           * rootName.getUserName(), rootName.getPassword(), rootName.getPath(), fileSystemOptions);
75           */
76  
77          return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
78      }
79  
80      @Override
81      public FileSystemConfigBuilder getConfigBuilder() {
82          return FtpFileSystemConfigBuilder.getInstance();
83      }
84  
85      @Override
86      public Collection<Capability> getCapabilities() {
87          return capabilities;
88      }
89  }