commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r798001 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ test/java/org/apache/commons/configuration2/
Date Sun, 26 Jul 2009 23:21:24 GMT
Author: rgoers
Date: Sun Jul 26 23:21:22 2009
New Revision: 798001

URL: http://svn.apache.org/viewvc?rev=798001&view=rev
Log:
Allow file options to work for any provider. Fix test compile failure introduced by r788057

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/FileSystem.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/VFSFileSystem.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestFileConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/FileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/FileSystem.java?rev=798001&r1=798000&r2=798001&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/FileSystem.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/FileSystem.java
Sun Jul 26 23:21:22 2009
@@ -27,7 +27,7 @@
 
 /**
  * Abstract layer to allow various types of file systems.
- * 
+ *
  * @since 1.7
  * @author <a href="http://commons.apache.org/configuration/team-list.html">Commons
Configuration team</a>
  */
@@ -77,7 +77,7 @@
             log = Logger.getLogger(getClass().getName() + "." + hashCode());
             log.setLevel(Level.OFF);
         }
-        
+
         this.log = log;
     }
 
@@ -94,7 +94,10 @@
                 if (FileSystem.class.isAssignableFrom(clazz))
                 {
                     fileSystem = (FileSystem) clazz.newInstance();
-                    System.out.println("Using " + fsClassName);
+                    if (log.isLoggable(Level.FINE))
+                    {
+                        log.fine("Using " + fsClassName);
+                    }
                 }
             }
             catch (InstantiationException ex)

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/VFSFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/VFSFileSystem.java?rev=798001&r1=798000&r2=798001&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/VFSFileSystem.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/VFSFileSystem.java
Sun Jul 26 23:21:22 2009
@@ -24,11 +24,8 @@
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileType;
 import org.apache.commons.vfs.FileSystemOptions;
-import org.apache.commons.vfs.UserAuthenticator;
-import org.apache.commons.vfs.impl.DefaultFileSystemConfigBuilder;
+import org.apache.commons.vfs.FileSystemConfigBuilder;
 import org.apache.commons.vfs.provider.UriParser;
-import org.apache.commons.vfs.provider.http.HttpFileSystemConfigBuilder;
-import org.apache.commons.vfs.provider.webdav.WebdavFileSystemConfigBuilder;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -39,6 +36,7 @@
 import java.net.MalformedURLException;
 import java.net.URLConnection;
 import java.util.Map;
+import java.lang.reflect.Method;
 
 /**
  * FileSystem that uses Commons VFS
@@ -48,44 +46,8 @@
  */
 public class VFSFileSystem extends DefaultFileSystem
 {
-    /** The builder for Webdav options */
-    private final WebdavFileSystemConfigBuilder webdavBuilder;
-
-    /** The builder for Http optiosn */
-    private final HttpFileSystemConfigBuilder httpBuilder;
-
     public VFSFileSystem()
     {
-        WebdavFileSystemConfigBuilder wb = null;
-        try
-        {
-            FileSystemManager manager = VFS.getManager();
-            if (manager.hasProvider("webdav"))
-            {
-                wb = (WebdavFileSystemConfigBuilder) manager.getFileSystemConfigBuilder("webdav");
-            }
-        }
-        catch (FileSystemException e)
-        {
-            // Just ignore the error. Webdav won't have options.
-            wb = null;
-        }
-        webdavBuilder = wb;
-        HttpFileSystemConfigBuilder hb = null;
-        try
-        {
-            FileSystemManager manager = VFS.getManager();
-            if (manager.hasProvider("http"))
-            {
-                hb = (HttpFileSystemConfigBuilder) manager.getFileSystemConfigBuilder("http");
-            }
-        }
-        catch (FileSystemException e)
-        {
-            // Just ignore the error http won't have options.
-            hb = null;
-        }
-        httpBuilder = hb;
     }
 
     public InputStream getInputStream(String basePath, String fileName)
@@ -339,98 +301,72 @@
     private FileSystemOptions getOptions(String scheme)
     {
         FileSystemOptions opts = new FileSystemOptions();
+        FileSystemConfigBuilder builder;
+        try
+        {
+            builder = VFS.getManager().getFileSystemConfigBuilder(scheme);
+        }
+        catch (Exception ex)
+        {
+            return null;
+        }
         FileOptionsProvider provider = getFileOptionsProvider();
         if (provider != null)
         {
             Map<String, Object> map = provider.getOptions();
-            if (scheme.equals("webdav"))
+            if (map == null)
             {
-                return setWebdavOptions(opts, map);
+                return null;
             }
-            else if (scheme.equals("http"))
+            int count = 0;
+            for (Map.Entry<String, Object> entry : map.entrySet())
             {
-                return setHttpOptions(opts, map);
+                try
+                {
+                    String key = entry.getKey();
+                    if (FileOptionsProvider.CURRENT_USER.equals(key))
+                    {
+                        key = "creatorName";
+                    }
+                    setProperty(builder, opts, key, entry.getValue());
+                    ++count;
+                }
+                catch (Exception ex)
+                {
+                    // Ignore an incorrect property.
+                    continue;
+                }
             }
-            else
+            if (count > 0)
             {
-                return setDefaultOptions(opts, map);
+                return opts;
             }
         }
-        return opts;
-    }
+        return null;
 
-    private FileSystemOptions setWebdavOptions(FileSystemOptions opts, Map<String, Object>
map)
-    {
-        setHttpOptions(opts, map);
-        if (webdavBuilder == null || map == null)
-        {
-            return opts;
-        }
-        if (map.containsKey(FileOptionsProvider.VERSIONING))
-        {
-            boolean versioning = (Boolean) map.get(FileOptionsProvider.VERSIONING);
-            webdavBuilder.setVersioning(opts, versioning);
-        }
-        if (map.containsKey(FileOptionsProvider.CURRENT_USER))
-        {
-            webdavBuilder.setCreatorName(opts, (String) map.get(FileOptionsProvider.CURRENT_USER));
-        }
-        return opts;
     }
 
-    private FileSystemOptions setHttpOptions(FileSystemOptions opts, Map<String, Object>
map)
+    private void setProperty(FileSystemConfigBuilder builder, FileSystemOptions options,
+                             String key, Object value)
     {
-        setDefaultOptions(opts, map);
+        String methodName = "set" + key.substring(0, 1).toUpperCase() + key.substring(1);
+        Class[] paramTypes = new Class[2];
+        paramTypes[0] = FileSystemOptions.class;
+        paramTypes[1] = value.getClass();
 
-        if (httpBuilder == null || map == null)
-        {
-            return opts;
-        }
-        if (map.containsKey(FileOptionsProvider.PROXY_PORT))
-        {
-            int port = (Integer) map.get(FileOptionsProvider.PROXY_PORT);
-            httpBuilder.setProxyPort(opts, port);
-        }
-        if (map.containsKey(FileOptionsProvider.PROXY_HOST))
-        {
-            httpBuilder.setProxyHost(opts, (String) map.get(FileOptionsProvider.PROXY_HOST));
-        }
-        if (map.containsKey(FileOptionsProvider.MAX_HOST_CONNECTIONS))
-        {
-            int max = (Integer) map.get(FileOptionsProvider.MAX_HOST_CONNECTIONS);
-            httpBuilder.setMaxConnectionsPerHost(opts, max);
-        }
-        if (map.containsKey(FileOptionsProvider.MAX_TOTAL_CONNECTIONS))
+        try
         {
-            int max = (Integer) map.get(FileOptionsProvider.MAX_TOTAL_CONNECTIONS);
-            httpBuilder.setMaxTotalConnections(opts, max);
+            Method method = builder.getClass().getMethod(methodName, paramTypes);
+            Object[] params = new Object[2];
+            params[0] = options;
+            params[1] = value;
+            method.invoke(builder, params);
         }
-        return opts;
-    }
-
-
-    private FileSystemOptions setDefaultOptions(FileSystemOptions opts, Map map)
-    {
-        DefaultFileSystemConfigBuilder builder = DefaultFileSystemConfigBuilder.getInstance();
-
-        if (builder == null || map == null)
+        catch (Exception ex)
         {
-            return opts;
+            return;
         }
 
-        if (map.containsKey("userAuthenticator"))
-        {
-            UserAuthenticator auth = (UserAuthenticator) map.get("userAuthenticator");
-            try
-            {
-                builder.setUserAuthenticator(opts, auth);
-            }
-            catch (FileSystemException e)
-            {
-                return opts;
-            }
-        }
-        return opts;
     }
 
     /**

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestFileConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestFileConfiguration.java?rev=798001&r1=798000&r2=798001&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestFileConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestFileConfiguration.java
Sun Jul 26 23:21:22 2009
@@ -579,7 +579,7 @@
         config.getString("test");
         config.setFileName("Not existing file");
         config.getString("test");
-        l.verify(AbstractFileConfiguration.EVENT_RELOAD, null, null);
+        l.verify(AbstractHierarchicalFileConfiguration.EVENT_RELOAD, null, null);
         assertNotNull("Exception is not set", l.getLastEvent().getCause());
     }
 



Mime
View raw message