commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1409642 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/ core/src/main/java/org/apache/commons/vfs2/impl/ core/src/test/java/org/apache/commons/vfs2/test/ src/changes/
Date Thu, 15 Nov 2012 03:10:22 GMT
Author: ggregory
Date: Thu Nov 15 03:10:21 2012
New Revision: 1409642

URL: http://svn.apache.org/viewvc?rev=1409642&view=rev
Log:
[VFS-445] Add FileSystemManager.resolveFile(URI) and resolveFile(URL).

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemManager.java?rev=1409642&r1=1409641&r2=1409642&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/FileSystemManager.java
Thu Nov 15 03:10:21 2012
@@ -18,6 +18,8 @@ package org.apache.commons.vfs2;
 
 import java.io.File;
 import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.net.URL;
 import java.net.URLStreamHandlerFactory;
 import java.util.Collection;
 
@@ -335,4 +337,27 @@ public interface FileSystemManager
      * @throws FileSystemException if an error occurs.
      */
     FileOperationProvider[] getOperationProviders(final String scheme) throws FileSystemException;
+    
+    /**
+     * Resolves a URI into a {@link FileObject}.
+     *
+     * @param uri The URI to convert.
+     * @return The {@link FileObject} that represents the URI.  Never
+     *         returns null.
+     * @throws FileSystemException On error converting the file.
+     * @since 2.1
+     */
+    FileObject resolveFile(URI uri) throws FileSystemException;
+
+    /**
+     * Resolves a URL into a {@link FileObject}.
+     *
+     * @param url The URL to convert.
+     * @return The {@link FileObject} that represents the URL.  Never
+     *         returns null.
+     * @throws FileSystemException On error converting the file.
+     * @since 2.1
+     */
+    FileObject resolveFile(URL url) throws FileSystemException;
+
 }

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java?rev=1409642&r1=1409641&r2=1409642&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
Thu Nov 15 03:10:21 2012
@@ -18,6 +18,9 @@ package org.apache.commons.vfs2.impl;
 
 import java.io.File;
 import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.net.URLStreamHandler;
 import java.net.URLStreamHandlerFactory;
 import java.util.ArrayList;
@@ -1186,4 +1189,42 @@ public class DefaultFileSystemManager im
         }
         return providers.toArray(new FileOperationProvider[] {});
     }
+
+    /**
+     * Converts a URI into a {@link FileObject}.
+     *
+     * @param uri The URI to convert.
+     * @return The {@link FileObject} that represents the URI.  Never
+     *         returns null.
+     * @throws FileSystemException On error converting the URI.
+     * @since 2.1
+     */
+    @Override
+    public FileObject resolveFile(URI uri) throws FileSystemException
+    {
+        // TODO Push the URI deeper into VFS
+        return resolveFile(baseFile, uri.toString(), null);
+    }
+
+    /**
+     * Converts a URL into a {@link FileObject}.
+     *
+     * @param url The URL to convert.
+     * @return The {@link FileObject} that represents the URL.  Never
+     *         returns null.
+     * @throws FileSystemException On error converting the URL.
+     * @since 2.1
+     */
+    @Override
+    public FileObject resolveFile(URL url) throws FileSystemException
+    {
+        try
+        {
+            return this.resolveFile(url.toURI());
+        }
+        catch (URISyntaxException e)
+        {
+            throw new FileSystemException(e);
+        }
+    }
 }

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java?rev=1409642&r1=1409641&r2=1409642&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/FileSystemManagerFactoryTestCase.java
Thu Nov 15 03:10:21 2012
@@ -20,6 +20,7 @@ import java.io.File;
 
 import org.apache.commons.AbstractVfsTestCase;
 import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.VFS;
@@ -40,7 +41,19 @@ public class FileSystemManagerFactoryTes
 
         // Lookup a test jar file
         final File jarFile = getTestResourceFile("test.jar");
+        // File
         FileObject file = manager.toFileObject(jarFile);
+        check(manager, file);
+        // URI
+        FileObject file2 = manager.resolveFile(jarFile.toURI());
+        check(manager, file2);
+        // URL
+        FileObject file3 = manager.resolveFile(jarFile.toURI().toURL());
+        check(manager, file3);
+    }
+
+    private void check(final FileSystemManager manager, FileObject file) throws FileSystemException
+    {
         assertNotNull(file);
         assertTrue(file.exists());
         assertSame(FileType.FILE, file.getType());

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1409642&r1=1409641&r2=1409642&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Nov 15 03:10:21 2012
@@ -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-445" dev="ggregory" type="add" due-to="ggregory">
+        Add FileSystemManager.resolveFile(URI) and resolveFile(URL).
+      </action>
       <action issue="VFS-440" dev="ggregory" type="add" due-to="bpiwowar">
         [SFTP] Stream (e.g. netcat) proxy for Sftp file system (aka ProxyCommand).
       </action>



Mime
View raw message