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 2003/02/15 01:07:46 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb SmbFileName.java SmbFileSystemProvider.java

adammurdoch    2003/02/14 16:07:45

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        AbstractOriginatingFileProvider.java
                        GenericFileName.java
               vfs/src/java/org/apache/commons/vfs/provider/ftp
                        FtpFileSystem.java FtpFileSystemProvider.java
               vfs/src/java/org/apache/commons/vfs/provider/local
                        DefaultLocalFileSystemProvider.java
               vfs/src/java/org/apache/commons/vfs/provider/smb
                        SmbFileName.java SmbFileSystemProvider.java
  Removed:     vfs/src/java/org/apache/commons/vfs/provider/ftp
                        FtpFileName.java
  Log:
  - Moved parsing code from FtpFileName up to GenericFileName.
  - Axed FtpFileName.
  - The name of the root of the new file system is now passed to
    AbstractOriginatingFileProvider.doCreateFileSystem().
  
  Revision  Changes    Path
  1.11      +10 -10    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractOriginatingFileProvider.java
  
  Index: AbstractOriginatingFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractOriginatingFileProvider.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractOriginatingFileProvider.java	12 Feb 2003 07:56:13 -0000	1.10
  +++ AbstractOriginatingFileProvider.java	15 Feb 2003 00:07:45 -0000	1.11
  @@ -102,13 +102,13 @@
           throws FileSystemException
       {
           // Check in the cache for the file system
  -        final String rootUri = name.getRootURI();
  -        FileSystem fs = findFileSystem( rootUri );
  +        final FileName rootName = name.resolveName( FileName.ROOT_PATH );
  +        FileSystem fs = findFileSystem( rootName );
           if ( fs == null )
           {
               // Need to create the file system, and cache it
  -            fs = doCreateFileSystem( name );
  -            addFileSystem( rootUri, fs );
  +            fs = doCreateFileSystem( rootName );
  +            addFileSystem( rootName, fs );
           }
   
           // Locate the file
  @@ -116,7 +116,7 @@
       }
   
       /**
  -     * Parses a URI.
  +     * Parses an absolute URI.
        *
        * @return The name of the file.  This name is used to locate the file
        *         system in the cache, using the root URI.  This name is also
  @@ -126,11 +126,11 @@
           throws FileSystemException;
   
       /**
  -     * Creates a filesystem.  The file system may implement {@link VfsComponent}.
  +     * Creates a {@link FileSystem}.  If the returned FileSystem implements
  +     * {@link VfsComponent}, it will be initialised.
        *
  -     * @param name The name of the file to create the file system for.
  +     * @param rootName The name of the root file of the file system to create.
        */
  -    protected abstract FileSystem doCreateFileSystem( final FileName name )
  +    protected abstract FileSystem doCreateFileSystem( final FileName rootName )
           throws FileSystemException;
  -
   }
  
  
  
  1.6       +106 -18   jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/GenericFileName.java
  
  Index: GenericFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/GenericFileName.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GenericFileName.java	12 Feb 2003 07:56:13 -0000	1.5
  +++ GenericFileName.java	15 Feb 2003 00:07:45 -0000	1.6
  @@ -56,6 +56,7 @@
   package org.apache.commons.vfs.provider;
   
   import org.apache.commons.vfs.FileSystemException;
  +import org.apache.commons.vfs.FileName;
   
   /**
    * A file name that represents a 'generic' URI, as per RFC 2396.  Consists of
  @@ -65,21 +66,28 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -public abstract class GenericFileName
  +public class GenericFileName
       extends DefaultFileName
   {
  -    private final String userInfo;
  +    private final String userName;
       private final String hostName;
  +    private final int defaultPort;
  +    private final String password;
       private final int port;
   
       protected GenericFileName( final String scheme,
                                  final String hostName,
                                  final int port,
  -                               final String userInfo,
  +                               final int defaultPort,
  +                               final String userName,
  +                               final String password,
                                  final String path )
       {
           super( scheme, path );
           this.hostName = hostName;
  +        this.defaultPort = defaultPort;
  +        this.password = password;
  +        this.userName = userName;
           if ( port > 0 )
           {
               this.port = port;
  @@ -88,29 +96,78 @@
           {
               this.port = getDefaultPort();
           }
  -        this.userInfo = userInfo;
       }
   
  -    /** Returns the user info part of the URI. */
  -    public String getUserInfo()
  +    /** Returns the user name part of this name. */
  +    public String getUserName()
       {
  -        return userInfo;
  +        return userName;
       }
   
  -    /** Returns the host name part of the URI. */
  +    /** Returns the password part of this name. */
  +    public String getPassword()
  +    {
  +        return password;
  +    }
  +
  +    /** Returns the host name part of this name. */
       public String getHostName()
       {
           return hostName;
       }
   
  -    /** Returns the port part of the URI. */
  +    /** Returns the port part of this name. */
       public int getPort()
       {
           return port;
       }
   
       /** Returns the default port for this file name. */
  -    public abstract int getDefaultPort();
  +    public int getDefaultPort()
  +    {
  +        return defaultPort;
  +    }
  +
  +    /**
  +     * Factory method for creating name instances.
  +     */
  +    protected FileName createName( final String absPath )
  +    {
  +        return new GenericFileName( getScheme(),
  +                                    hostName,
  +                                    port,
  +                                    defaultPort,
  +                                    userName,
  +                                    password,
  +                                    absPath );
  +    }
  +
  +    /**
  +     * Parses a generic URI.
  +     */
  +    public static GenericFileName parseUri( final String uri,
  +                                            final int defaultPort )
  +        throws FileSystemException
  +    {
  +        // FTP URI are generic URI (as per RFC 2396)
  +        final StringBuffer name = new StringBuffer();
  +
  +        // Extract the scheme and authority parts
  +        final Authority auth = extractToPath( uri, name );
  +
  +        // Decode and normalise the file name
  +        UriParser.decode( name, 0, name.length() );
  +        UriParser.normalisePath( name );
  +        final String path = name.toString();
  +
  +        return new GenericFileName( auth.scheme,
  +                                    auth.hostName,
  +                                    auth.port,
  +                                    defaultPort, 
  +                                    auth.userName,
  +                                    auth.password,
  +                                    path );
  +    }
   
       /**
        * Extracts the scheme, userinfo, hostname and port components of a
  @@ -138,8 +195,32 @@
           }
           name.delete( 0, 2 );
   
  -        // Extract userinfo
  -        auth.userInfo = extractUserInfo( name );
  +        // Extract userinfo, and split into username and password
  +        // TODO - need to decode username and password
  +        final String userInfo = extractUserInfo( name );
  +        final String userName;
  +        final String password;
  +        if ( userInfo != null )
  +        {
  +            int idx = userInfo.indexOf( ':' );
  +            if ( idx == -1 )
  +            {
  +                userName = userInfo;
  +                password = null;
  +            }
  +            else
  +            {
  +                userName = userInfo.substring( 0, idx );
  +                password = userInfo.substring( idx + 1 );
  +            }
  +        }
  +        else
  +        {
  +            userName = null;
  +            password = null;
  +        }
  +        auth.userName = userName;
  +        auth.password = password;
   
           // Extract hostname, and normalise (lowercase)
           final String hostName = extractHostName( name );
  @@ -257,15 +338,21 @@
       {
           buffer.append( getScheme() );
           buffer.append( "://" );
  -        if ( userInfo != null && userInfo.length() != 0 )
  +        if ( userName != null && userName.length() != 0 )
           {
  -            buffer.append( userInfo );
  -            buffer.append( "@" );
  +            // TODO - need to encode username and password
  +            buffer.append( userName );
  +            if ( password != null && password.length() != 0 )
  +            {
  +                buffer.append( ':' );
  +                buffer.append( password );
  +            }
  +            buffer.append( '@' );
           }
           buffer.append( hostName );
           if ( port != getDefaultPort() )
           {
  -            buffer.append( ":" );
  +            buffer.append( ':' );
               buffer.append( port );
           }
       }
  @@ -275,7 +362,8 @@
       {
           public String scheme;
           public String hostName;
  -        public String userInfo;
  +        public String userName;
  +        public String password;
           public int port;
       }
   }
  
  
  
  1.18      +21 -7     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java
  
  Index: FtpFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- FtpFileSystem.java	12 Feb 2003 07:56:15 -0000	1.17
  +++ FtpFileSystem.java	15 Feb 2003 00:07:45 -0000	1.18
  @@ -65,6 +65,7 @@
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.AbstractFileSystem;
  +import org.apache.commons.vfs.provider.GenericFileName;
   
   /**
    * An FTP file system.
  @@ -82,16 +83,29 @@
       // An idle client
       private FTPClient idleClient;
   
  -    public FtpFileSystem( final FileName rootName,
  -                          final String hostname,
  -                          final String username,
  -                          final String password )
  +    public FtpFileSystem( final GenericFileName rootName )
           throws FileSystemException
       {
           super( rootName, null );
  -        this.hostname = hostname;
  -        this.username = username;
  -        this.password = password;
  +        hostname = rootName.getHostName();
  +
  +        // Determine the username and password to use
  +        if ( rootName.getUserName() == null )
  +        {
  +            username = "anonymous";
  +        }
  +        else
  +        {
  +            username = rootName.getUserName();
  +        }
  +        if ( rootName.getPassword() == null )
  +        {
  +            password = "anonymous";
  +        }
  +        else
  +        {
  +            password = rootName.getPassword();
  +        }
       }
   
       public void close()
  
  
  
  1.13      +6 -19     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystemProvider.java
  
  Index: FtpFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystemProvider.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FtpFileSystemProvider.java	12 Feb 2003 07:56:15 -0000	1.12
  +++ FtpFileSystemProvider.java	15 Feb 2003 00:07:45 -0000	1.13
  @@ -59,6 +59,7 @@
   import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
  +import org.apache.commons.vfs.provider.GenericFileName;
   
   /**
    * A provider for FTP file systems.
  @@ -69,13 +70,15 @@
   public final class FtpFileSystemProvider
       extends AbstractOriginatingFileProvider
   {
  +    private static final int DEFAULT_PORT = 21;
  +
       /**
        * Parses a URI.
        */
       protected FileName parseUri( final String uri )
           throws FileSystemException
       {
  -        return FtpFileName.parseUri( uri );
  +        return GenericFileName.parseUri( uri, DEFAULT_PORT );
       }
   
       /**
  @@ -84,24 +87,8 @@
       protected FileSystem doCreateFileSystem( final FileName name )
           throws FileSystemException
       {
  -        final FtpFileName ftpUri = (FtpFileName)name;
  -
  -        // Build the root name
  -        final FileName rootName = ftpUri.resolveName( FileName.ROOT_PATH );
  -
  -        // Determine the username and password to use
  -        String username = ftpUri.getUserName();
  -        if ( username == null )
  -        {
  -            username = "anonymous";
  -        }
  -        String password = ftpUri.getPassword();
  -        if ( password == null )
  -        {
  -            password = "anonymous";
  -        }
  -
           // Create the file system
  -        return new FtpFileSystem( rootName, ftpUri.getHostName(), username, password );
  +        final GenericFileName rootName = (GenericFileName)name;
  +        return new FtpFileSystem( rootName );
       }
   }
  
  
  
  1.16      +2 -6      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/DefaultLocalFileSystemProvider.java
  
  Index: DefaultLocalFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/DefaultLocalFileSystemProvider.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultLocalFileSystemProvider.java	12 Feb 2003 07:56:15 -0000	1.15
  +++ DefaultLocalFileSystemProvider.java	15 Feb 2003 00:07:45 -0000	1.16
  @@ -132,12 +132,8 @@
       protected FileSystem doCreateFileSystem( final FileName name )
           throws FileSystemException
       {
  -        // Build the name of the root file.
  -        final LocalFileName fileUri = (LocalFileName)name;
  -        final String rootFile = fileUri.getRootFile();
  -
           // Create the file system
  -        final FileName rootName = fileUri.resolveName( FileName.ROOT_PATH );
  -        return new LocalFileSystem( rootName, rootFile );
  +        final LocalFileName rootName = (LocalFileName)name;
  +        return new LocalFileSystem( rootName, rootName.getRootFile() );
       }
   }
  
  
  
  1.6       +10 -11    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileName.java
  
  Index: SmbFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileName.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SmbFileName.java	12 Feb 2003 07:56:16 -0000	1.5
  +++ SmbFileName.java	15 Feb 2003 00:07:45 -0000	1.6
  @@ -69,16 +69,19 @@
   public class SmbFileName
       extends GenericFileName
   {
  +    private static final int DEFAULT_PORT = 139;
  +
       private final String share;
   
       private SmbFileName( final String scheme,
                            final String hostName,
                            final int port,
  -                         final String userInfo,
  +                         final String userName,
  +                         final String password,
                            final String share,
                            final String path )
       {
  -        super( scheme, hostName, port, userInfo, path );
  +        super( scheme, hostName, port, DEFAULT_PORT, userName, password, path );
           this.share = share;
       }
   
  @@ -112,7 +115,8 @@
           return new SmbFileName( auth.scheme,
                                   auth.hostName,
                                   auth.port,
  -                                auth.userInfo,
  +                                auth.userName,
  +                                auth.password,
                                   share,
                                   path );
       }
  @@ -125,12 +129,6 @@
           return share;
       }
   
  -    /** Returns the default port for this file name. */
  -    public int getDefaultPort()
  -    {
  -        return 139;
  -    }
  -
       /**
        * Builds the root URI for this file name.
        */
  @@ -149,7 +147,8 @@
           return new SmbFileName( getScheme(),
                                   getHostName(),
                                   getPort(),
  -                                getUserInfo(),
  +                                getUserName(),
  +                                getPassword(),
                                   share,
                                   path );
       }
  
  
  
  1.13      +1 -3      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileSystemProvider.java
  
  Index: SmbFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileSystemProvider.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SmbFileSystemProvider.java	12 Feb 2003 07:56:16 -0000	1.12
  +++ SmbFileSystemProvider.java	15 Feb 2003 00:07:45 -0000	1.13
  @@ -86,8 +86,6 @@
       protected FileSystem doCreateFileSystem( final FileName name )
           throws FileSystemException
       {
  -        final SmbFileName smbUri = (SmbFileName)name;
  -        final FileName rootName = smbUri.resolveName( FileName.ROOT_PATH );
  -        return new SmbFileSystem( rootName );
  +        return new SmbFileSystem( name );
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org