Author: ggregory Date: Sat May 12 20:07:08 2012 New Revision: 1337627 URL: http://svn.apache.org/viewvc?rev=1337627&view=rev Log: [VFS-414][FTP] Add config API to set the file type. [VFS-182][FTP] Usage of FTP with heterogeneous FTP server (possibility of using Ascii file type).
Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java (with props) Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java commons/proper/vfs/trunk/src/changes/changes.xml Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java Sat May 12 20:07:08 2012 @@ -62,6 +62,13 @@ public abstract class FileSystemConfigBu return getString(opts, ROOTURI); } + /** + * @since 2.1 + */ + protected void setParam(FileSystemOptions opts, String name, boolean value) + { + setParam(opts, name, Boolean.valueOf(value)); + } protected void setParam(FileSystemOptions opts, String name, Object value) { Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties Sat May 12 20:07:08 2012 @@ -228,7 +228,7 @@ vfs.provider.ftp/invalid-directory-entry vfs.provider.ftp/login.error=Could not login to FTP server on "{0}" as user "{1}". vfs.provider.ftp/output-error.debug=Cant open output connection for file "{0}". Reason: "{1}". vfs.provider.ftp/rename-file.error=Could not rename FTP file "{0}" to "{1}". -vfs.provider.ftp/set-binary.error=Could not switch to binary transfer mode. +vfs.provider.ftp/set-file-type.error=Could not set the file type to "{0}". # SFTP Provider vfs.provider.sftp/change-work-directory-back.error=Could not change back to work directory "{0}". Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java Sat May 12 20:07:08 2012 @@ -97,10 +97,15 @@ public final class FtpClientFactory hostname, UserAuthenticatorUtils.toString(username)); } + FtpFileType fileType = FtpFileSystemConfigBuilder.getInstance().getFileType(fileSystemOptions); + if (fileType == null) + { + fileType = FtpFileType.BINARY; + } // Set binary mode - if (!client.setFileType(FTP.BINARY_FILE_TYPE)) + if (!client.setFileType(fileType.getValue())) { - throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname); + throw new FileSystemException("vfs.provider.ftp/set-file-type.error", fileType); } // Set dataTimeout value Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java Sat May 12 20:07:08 2012 @@ -22,36 +22,38 @@ import org.apache.commons.vfs2.FileSyste import org.apache.commons.vfs2.FileSystemOptions; /** - * The config BUILDER for various ftp configuration options. + * The config builder for various ftp configuration options. */ public final class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder { + private static final String _PREFIX = FtpFileSystemConfigBuilder.class.getName(); + private static final FtpFileSystemConfigBuilder BUILDER = new FtpFileSystemConfigBuilder(); private static final String FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY"; - private static final String PASSIVE_MODE = FtpFileSystemConfigBuilder.class.getName() + ".PASSIVE"; - private static final String USER_DIR_IS_ROOT = FtpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT"; - private static final String DATA_TIMEOUT = FtpFileSystemConfigBuilder.class.getName() + ".DATA_TIMEOUT"; - private static final String SO_TIMEOUT = FtpFileSystemConfigBuilder.class.getName() + ".SO_TIMEOUT"; - - private static final String SERVER_LANGUAGE_CODE = - FtpFileSystemConfigBuilder.class.getName() + ".SERVER_LANGUAGE_CODE"; - private static final String DEFAULT_DATE_FORMAT = - FtpFileSystemConfigBuilder.class.getName() + ".DEFAULT_DATE_FORMAT"; - private static final String RECENT_DATE_FORMAT = - FtpFileSystemConfigBuilder.class.getName() + ".RECENT_DATE_FORMAT"; - private static final String SERVER_TIME_ZONE_ID = - FtpFileSystemConfigBuilder.class.getName() + ".SERVER_TIME_ZONE_ID"; - private static final String SHORT_MONTH_NAMES = - FtpFileSystemConfigBuilder.class.getName() + ".SHORT_MONTH_NAMES"; - private static final String ENCODING = - FtpFileSystemConfigBuilder.class.getName() + ".ENCODING"; + private static final String FILE_TYPE = _PREFIX + ".FILE_TYPE"; + private static final String PASSIVE_MODE = _PREFIX + ".PASSIVE"; + private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT"; + private static final String DATA_TIMEOUT = _PREFIX + ".DATA_TIMEOUT"; + private static final String SO_TIMEOUT = _PREFIX + ".SO_TIMEOUT"; + + private static final String SERVER_LANGUAGE_CODE = _PREFIX + ".SERVER_LANGUAGE_CODE"; + private static final String DEFAULT_DATE_FORMAT = _PREFIX + ".DEFAULT_DATE_FORMAT"; + private static final String RECENT_DATE_FORMAT = _PREFIX + ".RECENT_DATE_FORMAT"; + private static final String SERVER_TIME_ZONE_ID = _PREFIX + ".SERVER_TIME_ZONE_ID"; + private static final String SHORT_MONTH_NAMES = _PREFIX + ".SHORT_MONTH_NAMES"; + private static final String ENCODING = _PREFIX + ".ENCODING"; private FtpFileSystemConfigBuilder() { super("ftp."); } + /** + * Gets the singleton instance. + * + * @return the singleton instance. + */ public static FtpFileSystemConfigBuilder getInstance() { return BUILDER; @@ -69,6 +71,18 @@ public final class FtpFileSystemConfigBu } /** + * Sets the file type parameter. + * + * @param opts The FileSystemOptions. + * @param ftpFileType A FtpFileType + * @since 2.1 + */ + public void setFileType(FileSystemOptions opts, FtpFileType ftpFileType) + { + setParam(opts, FILE_TYPE, ftpFileType); + } + + /** * @param opts The FlleSystemOptions. * @see #setEntryParserFactory * @return An FTPFileEntryParserFactory. @@ -79,6 +93,18 @@ public final class FtpFileSystemConfigBu } /** + * Gets the file type parameter. + * + * @param opts The FileSystemOptions. + * @return A FtpFileType + * @since 2.1 + */ + public FtpFileType getFileType(FileSystemOptions opts) + { + return (FtpFileType) getParam(opts, FILE_TYPE); + } + + /** * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br /> * <br /> * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by using @@ -328,6 +354,7 @@ public final class FtpFileSystemConfigBu * */ public String getControlEncoding(FileSystemOptions opts) { - return (String) getParam(opts, ENCODING); + return (String) getParam(opts, ENCODING); } + } Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java?rev=1337627&view=auto ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java (added) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java Sat May 12 20:07:08 2012 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.vfs2.provider.ftp; + +import org.apache.commons.net.ftp.FTP; + +/** + * The FTP file types. + * + * @since 2.1 + */ +public enum FtpFileType +{ + /** + * The ASCII file type. + */ + ASCII(FTP.ASCII_FILE_TYPE), + + /** + * The binary file type. + */ + BINARY(FTP.BINARY_FILE_TYPE), + + /** + * The local file type. + */ + LOCAL(FTP.LOCAL_FILE_TYPE), + + /** + * The EBCDIC file type. + */ + EBCDIC(FTP.EBCDIC_FILE_TYPE); + + /** + * The Apache Commons Net FTP file type. + */ + private final int value; + + /** + * Constructs a file type. + * + * @param fileType + * The Apache Commons Net FTP file type. + */ + private FtpFileType(int fileType) + { + this.value = fileType; + } + + /** + * Gets the Apache Commons Net FTP file type. + * + * @return + */ + int getValue() + { + return this.value; + } +} Propchange: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileType.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java Sat May 12 20:07:08 2012 @@ -27,6 +27,7 @@ import org.apache.commons.vfs2.FileSyste import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import org.apache.commons.vfs2.provider.ftp.FtpFileProvider; import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; +import org.apache.commons.vfs2.provider.ftp.FtpFileType; import org.apache.commons.vfs2.test.AbstractProviderTestConfig; import org.apache.commons.vfs2.test.ProviderTestConfig; import org.apache.commons.vfs2.test.ProviderTestSuite; @@ -168,6 +169,8 @@ public class FtpProviderTestCase extends } FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); + // FtpFileType.BINARY is the default + FtpFileSystemConfigBuilder.getInstance().setFileType(opts, FtpFileType.BINARY); return manager.resolveFile(uri, opts); } Modified: commons/proper/vfs/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1337627&r1=1337626&r2=1337627&view=diff ============================================================================== --- commons/proper/vfs/trunk/src/changes/changes.xml (original) +++ commons/proper/vfs/trunk/src/changes/changes.xml Sat May 12 20:07:08 2012 @@ -23,6 +23,12 @@ <body> <release version="2.1" date="TBD" description=""> + <action issue="VFS-414" dev="ggregory" type="update" due-to="ggregory"> + [FTP] Add config API to set the file type. + </action> + <action issue="VFS-182" dev="ggregory" type="update" due-to="ggregory"> + [FTP] Usage of FTP with heterogeneous FTP server (possibility of using Ascii file type). + </action> <action issue="VFS-395" dev="ggregory" type="update" due-to="ggregory"> [POM] Remove maven-scm-* dependencies. </action>