commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r1448689 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/ core/src/main/java/org/apache/commons/vfs2/provider/ftp/ core/src/main/java/org/apache/commons/vfs2/provider/ftps/ core/src/main/java/org/apache/commons/vf...
Date Thu, 21 Feb 2013 15:50:18 GMT
Author: joehni
Date: Thu Feb 21 15:50:18 2013
New Revision: 1448689

URL: http://svn.apache.org/r1448689
Log:
FileSytemConfigBuilder supports system properties for the value of enum-based configuration
entries (VFS-463).

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/provider/ftp/FtpFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.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=1448689&r1=1448688&r2=1448689&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
Thu Feb 21 15:50:18 2013
@@ -220,6 +220,29 @@ public abstract class FileSystemConfigBu
         return value;
     }
 
+    /** @since 2.1 */
+    protected <E extends Enum<E>> E getEnum(final Class<E> enumClass, final
FileSystemOptions opts, final String name)
+    {
+        return this.<E>getEnum(enumClass, opts, name, null);
+    }
+
+    /** @since 2.1 */
+    protected <E extends Enum<E>> E getEnum(final Class<E> enumClass, final
FileSystemOptions opts, final String name, final E defaultValue)
+    {
+        @SuppressWarnings("unchecked")
+		E value = (E) getParam(opts, name);
+        if (value == null)
+        {
+            final String str = getProperty(name);
+            if (str == null)
+            {
+                return defaultValue;
+            }
+            value = Enum.valueOf(enumClass, str);
+        }
+        return value;
+    }
+
     /** @since 2.0 */
     protected Float getFloat(final FileSystemOptions opts, final String name)
     {

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=1448689&r1=1448688&r2=1448689&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
Thu Feb 21 15:50:18 2013
@@ -143,7 +143,7 @@ public class FtpFileSystemConfigBuilder 
      */
     public FtpFileType getFileType(final FileSystemOptions opts)
     {
-        return (FtpFileType) getParam(opts, FILE_TYPE);
+        return getEnum(FtpFileType.class, opts, FILE_TYPE);
     }
 
     /**

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java?rev=1448689&r1=1448688&r2=1448689&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
Thu Feb 21 15:50:18 2013
@@ -74,8 +74,7 @@ public final class FtpsFileSystemConfigB
      */
     public FtpsMode getFtpsMode(final FileSystemOptions opts)
     {
-        final FtpsMode mode = (FtpsMode)getParam(opts, FTPS_MODE);
-		return mode == null ? FtpsMode.EXPLICIT : mode;
+        return getEnum(FtpsMode.class, opts, FTPS_MODE, FtpsMode.EXPLICIT);
     }
 
 	/**
@@ -134,7 +133,7 @@ public final class FtpsFileSystemConfigB
 	 */
 	public FtpsDataChannelProtectionLevel getDataChannelProtectionLevel(final FileSystemOptions
opts)
 	{
-		return (FtpsDataChannelProtectionLevel)getParam(opts, PROT);
+		return getEnum(FtpsDataChannelProtectionLevel.class, opts, PROT);
 	}
 
 	/**

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java?rev=1448689&r1=1448688&r2=1448689&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
Thu Feb 21 15:50:18 2013
@@ -217,7 +217,7 @@ public final class SftpFileSystemConfigB
      */
     public String getPreferredAuthentications(final FileSystemOptions opts)
     {
-        return (String) this.getParam(opts, PREFERRED_AUTHENTICATIONS);
+        return getString(opts, PREFERRED_AUTHENTICATIONS);
     }
 
 

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1448689&r1=1448688&r2=1448689&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Feb 21 15:50:18 2013
@@ -26,6 +26,9 @@
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen">
-->
 <!--     	[Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
+      <action issue="VFS-463" dev="joehni" type="update">
+        FileSytemConfigBuilder supports system properties for the value of enum-based configuration
entries.
+      </action>
       <action issue="VFS-462" dev="joehni" type="update">
         [FTPS] Deprecate FtpsFileSystemConfigBuilder.setFtpsType and FtpsFileSystemConfigBuilder.getFtpsType
         in favor of FtpsFileSystemConfigBuilder.setFtpsMode and FtpsFileSystemConfigBuilder.getFtpsMode
which



Mime
View raw message