You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/11/25 06:38:45 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url UrlFileProvider.java

adammurdoch    2002/11/24 21:38:45

  Modified:    vfs/src/java/org/apache/commons/vfs/provider/url
                        UrlFileProvider.java
  Log:
  Fixed the generic provider to handle URI schemes with no hostname part.
  
  Revision  Changes    Path
  1.9       +26 -16    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
  
  Index: UrlFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- UrlFileProvider.java	23 Nov 2002 00:33:54 -0000	1.8
  +++ UrlFileProvider.java	25 Nov 2002 05:38:45 -0000	1.9
  @@ -58,10 +58,13 @@
   import org.apache.commons.vfs.FileName;
   import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileSystemException;
  -import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
  +import org.apache.commons.vfs.FileObject;
  +import org.apache.commons.vfs.provider.AbstractFileSystemProvider;
   import org.apache.commons.vfs.provider.DefaultFileName;
   import org.apache.commons.vfs.provider.Uri;
   import org.apache.commons.vfs.provider.UriParser;
  +import java.net.URL;
  +import java.net.MalformedURLException;
   
   /**
    * A file provider backed by Java's URL API.
  @@ -70,26 +73,33 @@
    * @version $Revision$ $Date$
    */
   public class UrlFileProvider
  -    extends AbstractOriginatingFileProvider
  +    extends AbstractFileSystemProvider
   {
       private final UriParser parser = new UriParser();
   
       /**
  -     * Parses a URI into its components.
  +     * Locates a file object, by absolute URI.
        */
  -    protected Uri parseUri( final String uri )
  +    public FileObject findFile( final FileObject baseFile,
  +                                final String uri )
           throws FileSystemException
       {
  -        return parser.parseUri( uri );
  -    }
  -
  -    /**
  -     * Creates the filesystem.
  -     */
  -    protected FileSystem doCreateFileSystem( final Uri uri )
  -        throws FileSystemException
  -    {
  -        final DefaultFileName rootName = new DefaultFileName( parser, uri.getContainerUri(), FileName.ROOT_PATH );
  -        return new UrlFileSystem( rootName );
  +        try
  +        {
  +            final URL url = new URL( uri );
  +            final URL rootUrl = new URL( url, "/" );
  +            FileSystem fs = findFileSystem( rootUrl );
  +            if ( fs == null )
  +            {
  +                final FileName rootName = new DefaultFileName( parser, rootUrl.toExternalForm(), FileName.ROOT_PATH );
  +                fs = new UrlFileSystem( rootName );
  +                addFileSystem( rootUrl, fs );
  +            }
  +            return fs.resolveFile( url.getPath() );
  +        }
  +        catch ( final MalformedURLException e )
  +        {
  +            throw new FileSystemException( "vfs.provider.url/badly-formed-uri.error", uri, e );
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>