commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url UrlFileProvider.java
Date Wed, 12 Feb 2003 07:42:41 GMT
adammurdoch    2003/02/11 23:42:41

  Modified:    vfs/src/java/org/apache/commons/vfs FileName.java
               vfs/src/java/org/apache/commons/vfs/provider
                        BasicFileName.java DefaultFileName.java
                        GenericFileName.java UriParser.java
               vfs/src/java/org/apache/commons/vfs/provider/ftp
                        FtpFileName.java
               vfs/src/java/org/apache/commons/vfs/provider/smb
                        SmbFileName.java
               vfs/src/java/org/apache/commons/vfs/provider/url
                        UrlFileProvider.java
  Log:
  Minor FileName tidy-ups:
  - Added FileName.SEPARATOR and SEPARATOR_CHAR constants
  - FileName.getRootUri() always returns a URI with trailing /
  - Made GenericFileName.getPort() return an int, rather than String
  - Fixed checking for empty share name for URI like smb://hostname/
  
  Revision  Changes    Path
  1.10      +11 -1     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileName.java
  
  Index: FileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileName.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FileName.java	23 Jan 2003 12:27:23 -0000	1.9
  +++ FileName.java	12 Feb 2003 07:42:40 -0000	1.10
  @@ -67,6 +67,16 @@
   public interface FileName
   {
       /**
  +     * The separator character used in absolute file paths.
  +     */
  +    char SEPARATOR_CHAR = '/';
  +
  +    /**
  +     * The separator used in absolute file paths.
  +     */
  +    String SEPARATOR = "/";
  +
  +    /**
        * The absolute path of the root of a file system.
        */
       String ROOT_PATH = "/";
  @@ -113,7 +123,7 @@
        * Returns the URI scheme of this file.
        */
       String getScheme();
  -    
  +
       /**
        * Returns the absolute URI of this file.
        */
  
  
  
  1.2       +10 -2     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/BasicFileName.java
  
  Index: BasicFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/BasicFileName.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicFileName.java	12 Feb 2003 02:05:19 -0000	1.1
  +++ BasicFileName.java	12 Feb 2003 07:42:41 -0000	1.2
  @@ -79,7 +79,15 @@
                             final String path )
       {
           super( scheme, path );
  -        this.rootUri = rootUri;
  +        if ( rootUri.endsWith( SEPARATOR ) )
  +        {
  +            // Remove trailing separator
  +            this.rootUri = rootUri.substring( 0, rootUri.length() - 1 );
  +        }
  +        else
  +        {
  +            this.rootUri = rootUri;
  +        }
       }
   
       public BasicFileName( final FileName rootUri, final String path )
  
  
  
  1.10      +31 -29    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileName.java
  
  Index: DefaultFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileName.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultFileName.java	12 Feb 2003 02:05:19 -0000	1.9
  +++ DefaultFileName.java	12 Feb 2003 07:42:41 -0000	1.10
  @@ -68,9 +68,6 @@
   public abstract class DefaultFileName
       implements FileName
   {
  -    public static final char separatorChar = UriParser.separatorChar;
  -    public static final String separator = UriParser.separator;
  -
       private final String scheme;
       private final String absPath;
   
  @@ -84,7 +81,14 @@
                               final String absPath )
       {
           this.scheme = scheme;
  -        this.absPath = absPath;
  +        if ( absPath != null && absPath.length() > 0 )
  +        {
  +            this.absPath = absPath;
  +        }
  +        else
  +        {
  +            this.absPath = ROOT_PATH;
  +        }
       }
   
       /**
  @@ -118,7 +122,8 @@
       protected abstract FileName createName( String absPath );
   
       /**
  -     * Builds the root URI for this file name.
  +     * Builds the root URI for this file name.  Note that the root URI must not
  +     * end with a separator character.
        */
       protected abstract void appendRootUri( StringBuffer buffer );
   
  @@ -129,7 +134,7 @@
       {
           if ( baseName == null )
           {
  -            final int idx = absPath.lastIndexOf( separatorChar );
  +            final int idx = absPath.lastIndexOf( SEPARATOR_CHAR );
               if ( idx == -1 )
               {
                   baseName = absPath;
  @@ -165,10 +170,10 @@
           UriParser.fixSeparators( buffer );
   
           // Determine whether to prepend the base path
  -        if ( name.length() == 0 || name.charAt( 0 ) != separatorChar )
  +        if ( name.length() == 0 || name.charAt( 0 ) != SEPARATOR_CHAR )
           {
               // Supplied path is not absolute
  -            buffer.insert( 0, separatorChar );
  +            buffer.insert( 0, SEPARATOR_CHAR );
               buffer.insert( 0, absPath );
           }
   
  @@ -191,7 +196,7 @@
       public FileName getParent()
       {
           final String parentPath;
  -        final int idx = absPath.lastIndexOf( separatorChar );
  +        final int idx = absPath.lastIndexOf( SEPARATOR_CHAR );
           if ( idx == -1 || idx == absPath.length() - 1 )
           {
               // No parent
  @@ -200,7 +205,7 @@
           else if ( idx == 0 )
           {
               // Root is the parent
  -            parentPath = separator;
  +            parentPath = SEPARATOR;
           }
           else
           {
  @@ -235,7 +240,10 @@
       {
           if ( uri == null )
           {
  -            uri = getRootURI() + absPath;
  +            final StringBuffer buffer = new StringBuffer();
  +            appendRootUri( buffer );
  +            buffer.append( absPath );
  +            uri = buffer.toString();
           }
           return uri;
       }
  @@ -272,7 +280,7 @@
               // Same names
               return ".";
           }
  -        else if ( pos == basePathLen && pos < pathLen && path.charAt(
pos ) == separatorChar )
  +        else if ( pos == basePathLen && pos < pathLen && path.charAt(
pos ) == SEPARATOR_CHAR )
           {
               // A descendent of the base path
               return path.substring( pos + 1 );
  @@ -280,21 +288,21 @@
   
           // Strip the common prefix off the path
           final StringBuffer buffer = new StringBuffer();
  -        if ( pathLen > 1 && ( pos < pathLen || absPath.charAt( pos ) != separatorChar
) )
  +        if ( pathLen > 1 && ( pos < pathLen || absPath.charAt( pos ) != SEPARATOR_CHAR
) )
           {
               // Not a direct ancestor, need to back up
  -            pos = absPath.lastIndexOf( separatorChar, pos );
  +            pos = absPath.lastIndexOf( SEPARATOR_CHAR, pos );
               buffer.append( path.substring( pos ) );
           }
   
           // Prepend a '../' for each element in the base path past the common
           // prefix
           buffer.insert( 0, ".." );
  -        pos = absPath.indexOf( separatorChar, pos + 1 );
  +        pos = absPath.indexOf( SEPARATOR_CHAR, pos + 1 );
           while ( pos != -1 )
           {
               buffer.insert( 0, "../" );
  -            pos = absPath.indexOf( separatorChar, pos + 1 );
  +            pos = absPath.indexOf( SEPARATOR_CHAR, pos + 1 );
           }
   
           return buffer.toString();
  @@ -309,13 +317,7 @@
           {
               final StringBuffer buffer = new StringBuffer();
               appendRootUri( buffer );
  -
  -            // Remove trailing separator, if any
  -            if ( buffer.charAt( buffer.length() - 1 ) == separatorChar )
  -            {
  -                buffer.deleteCharAt( buffer.length() - 1 );
  -            }
  -
  +            buffer.append( SEPARATOR_CHAR );
               rootUri = buffer.toString();
           }
           return rootUri;
  @@ -327,14 +329,14 @@
       public int getDepth()
       {
           final int len = absPath.length();
  -        if ( len == 0 || ( len == 1 && absPath.charAt( 0 ) == separatorChar ) )
  +        if ( len == 0 || ( len == 1 && absPath.charAt( 0 ) == SEPARATOR_CHAR )
)
           {
               return 0;
           }
           int depth = 1;
           for ( int pos = 0; pos > -1 && pos < len; depth++ )
           {
  -            pos = absPath.indexOf( separatorChar, pos + 1 );
  +            pos = absPath.indexOf( SEPARATOR_CHAR, pos + 1 );
           }
           return depth;
       }
  @@ -419,8 +421,8 @@
           if ( scope == NameScope.CHILD )
           {
               if ( path.length() == baseLen
  -                || ( baseLen > 1 && path.charAt( baseLen ) != separatorChar
)
  -                || path.indexOf( separatorChar, baseLen + 1 ) != -1 )
  +                || ( baseLen > 1 && path.charAt( baseLen ) != SEPARATOR_CHAR
)
  +                || path.indexOf( SEPARATOR_CHAR, baseLen + 1 ) != -1 )
               {
                   return false;
               }
  @@ -428,7 +430,7 @@
           else if ( scope == NameScope.DESCENDENT )
           {
               if ( path.length() == baseLen
  -                || ( baseLen > 1 && path.charAt( baseLen ) != separatorChar
) )
  +                || ( baseLen > 1 && path.charAt( baseLen ) != SEPARATOR_CHAR
) )
               {
                   return false;
               }
  @@ -437,7 +439,7 @@
           {
               if ( baseLen > 1
                   && path.length() > baseLen
  -                && path.charAt( baseLen ) != separatorChar )
  +                && path.charAt( baseLen ) != SEPARATOR_CHAR )
               {
                   return false;
               }
  
  
  
  1.4       +25 -17    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GenericFileName.java	12 Feb 2003 02:05:19 -0000	1.3
  +++ GenericFileName.java	12 Feb 2003 07:42:41 -0000	1.4
  @@ -70,17 +70,24 @@
   {
       private final String userInfo;
       private final String hostName;
  -    private final String port;
  +    private final int port;
   
       protected GenericFileName( final String scheme,
                                  final String hostName,
  -                               final String port,
  +                               final int port,
                                  final String userInfo,
                                  final String path )
       {
           super( scheme, path );
           this.hostName = hostName;
  -        this.port = port;
  +        if ( port > 0 )
  +        {
  +            this.port = port;
  +        }
  +        else
  +        {
  +            this.port = getDefaultPort();
  +        }
           this.userInfo = userInfo;
       }
   
  @@ -97,13 +104,13 @@
       }
   
       /** Returns the port part of the URI. */
  -    public String getPort()
  +    public int getPort()
       {
           return port;
       }
   
       /** Returns the default port for this file name. */
  -    public abstract String getDefaultPort();
  +    public abstract int getDefaultPort();
   
       /**
        * Extracts the scheme, userinfo, hostname and port components of a
  @@ -143,12 +150,7 @@
           auth.hostName = hostName.toLowerCase();
   
           // Extract port
  -        final String port = extractPort( name );
  -        if ( port != null && port.length() == 0 )
  -        {
  -            throw new FileSystemException( "vfs.provider/missing-port.error", uri );
  -        }
  -        auth.port = port;
  +        auth.port = extractPort( name, uri );
   
           // Expecting '/' or empty name
           if ( name.length() > 0 && name.charAt( 0 ) != '/' )
  @@ -218,12 +220,13 @@
       /**
        * Extracts the port from a URI.  The <scheme>://<userinfo>@<hostname>
        * part has been removed.
  +     * @return The port, or -1 if the URI does not contain a port.
        */
  -    protected static String extractPort( final StringBuffer name )
  +    private static int extractPort( final StringBuffer name, final String uri ) throws
FileSystemException
       {
           if ( name.length() < 1 || name.charAt( 0 ) != ':' )
           {
  -            return null;
  +            return -1;
           }
   
           final int maxlen = name.length();
  @@ -239,7 +242,12 @@
   
           final String port = name.substring( 1, pos );
           name.delete( 0, pos );
  -        return port;
  +        if ( port.length() == 0 )
  +        {
  +            throw new FileSystemException( "vfs.provider/missing-port.error", uri );
  +        }
  +
  +        return Integer.parseInt( port );
       }
   
       /**
  @@ -255,7 +263,7 @@
               buffer.append( "@" );
           }
           buffer.append( hostName );
  -        if ( port != null && port.length() > 0 && !port.equals( getDefaultPort()
) )
  +        if ( port != getDefaultPort() )
           {
               buffer.append( ":" );
               buffer.append( port );
  @@ -268,6 +276,6 @@
           public String scheme;
           public String hostName;
           public String userInfo;
  -        public String port;
  +        public int port;
       }
   }
  
  
  
  1.13      +9 -11     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java
  
  Index: UriParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- UriParser.java	24 Jan 2003 00:20:03 -0000	1.12
  +++ UriParser.java	12 Feb 2003 07:42:41 -0000	1.13
  @@ -56,6 +56,7 @@
   package org.apache.commons.vfs.provider;
   
   import org.apache.commons.vfs.FileSystemException;
  +import org.apache.commons.vfs.FileName;
   
   /**
    * Utilities for dealing with URIs.  See RFC 2396 for details.
  @@ -66,10 +67,7 @@
   public final class UriParser
   {
       /** The normalised separator to use. */
  -    public static final char separatorChar = '/';
  -
  -    /** The normalised separator to use. */
  -    public static final String separator = "/";
  +    private static final char SEPARATOR_CHAR = FileName.SEPARATOR_CHAR;
   
       /**
        * The set of valid separators.  These are all converted to the normalised one.
  @@ -92,13 +90,13 @@
               return null;
           }
           int startPos = 0;
  -        if ( name.charAt( 0 ) == separatorChar )
  +        if ( name.charAt( 0 ) == SEPARATOR_CHAR )
           {
               startPos = 1;
           }
           for ( int pos = startPos; pos < len; pos++ )
           {
  -            if ( name.charAt( pos ) == separatorChar )
  +            if ( name.charAt( pos ) == SEPARATOR_CHAR )
               {
                   // Found a separator
                   final String elem = name.substring( startPos, pos );
  @@ -135,7 +133,7 @@
   
           // Determine the start of the first element
           int startFirstElem = 0;
  -        if ( path.charAt( 0 ) == separatorChar )
  +        if ( path.charAt( 0 ) == SEPARATOR_CHAR )
           {
               if ( path.length() == 1 )
               {
  @@ -151,7 +149,7 @@
           {
               // Find the end of the element
               int endElem = startElem;
  -            for ( ; endElem < maxlen && path.charAt( endElem ) != separatorChar;
endElem++ )
  +            for ( ; endElem < maxlen && path.charAt( endElem ) != SEPARATOR_CHAR;
endElem++ )
               {
               }
   
  @@ -183,7 +181,7 @@
   
                   // Find start of previous element
                   int pos = startElem - 2;
  -                for ( ; pos >= 0 && path.charAt( pos ) != separatorChar; pos--
)
  +                for ( ; pos >= 0 && path.charAt( pos ) != SEPARATOR_CHAR; pos--
)
                   {
                   }
                   startElem = pos + 1;
  @@ -198,7 +196,7 @@
           }
   
           // Remove trailing separator
  -        if ( maxlen > 0 && path.charAt( maxlen - 1 ) == separatorChar &&
maxlen > 1 )
  +        if ( maxlen > 0 && path.charAt( maxlen - 1 ) == SEPARATOR_CHAR &&
maxlen > 1 )
           {
               path.delete( maxlen - 1, maxlen );
           }
  @@ -225,7 +223,7 @@
                   char separator = separators[ j ];
                   if ( ch == separator )
                   {
  -                    name.setCharAt( i, separatorChar );
  +                    name.setCharAt( i, SEPARATOR_CHAR );
                       changed = true;
                       break;
                   }
  
  
  
  1.4       +5 -5      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileName.java
  
  Index: FtpFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileName.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FtpFileName.java	12 Feb 2003 02:05:19 -0000	1.3
  +++ FtpFileName.java	12 Feb 2003 07:42:41 -0000	1.4
  @@ -67,7 +67,7 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -class FtpFileName
  +public class FtpFileName
       extends GenericFileName
   {
       private final String userName;
  @@ -75,7 +75,7 @@
   
       private FtpFileName( final String scheme,
                            final String hostName,
  -                         final String port,
  +                         final int port,
                            final String userInfo,
                            final String userName,
                            final String password,
  @@ -154,9 +154,9 @@
       }
   
       /** Returns the default port for this file name. */
  -    public String getDefaultPort()
  +    public int getDefaultPort()
       {
  -        return "21";
  +        return 21;
       }
   
       /**
  
  
  
  1.4       +6 -6      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SmbFileName.java	12 Feb 2003 02:05:19 -0000	1.3
  +++ SmbFileName.java	12 Feb 2003 07:42:41 -0000	1.4
  @@ -66,14 +66,14 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -class SmbFileName
  +public class SmbFileName
       extends GenericFileName
   {
       private final String share;
   
       private SmbFileName( final String scheme,
                            final String hostName,
  -                         final String port,
  +                         final int port,
                            final String userInfo,
                            final String share,
                            final String path )
  @@ -99,7 +99,7 @@
   
           // Extract the share
           final String share = UriParser.extractFirstElement( name );
  -        if ( share == null )
  +        if ( share == null || share.length() == 0 )
           {
               throw new FileSystemException( "vfs.provider.smb/missing-share-name.error",
uri );
           }
  @@ -126,9 +126,9 @@
       }
   
       /** Returns the default port for this file name. */
  -    public String getDefaultPort()
  +    public int getDefaultPort()
       {
  -        return "139";
  +        return 139;
       }
   
       /**
  
  
  
  1.12      +1 -2      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- UrlFileProvider.java	12 Feb 2003 02:05:20 -0000	1.11
  +++ UrlFileProvider.java	12 Feb 2003 07:42:41 -0000	1.12
  @@ -62,7 +62,6 @@
   import org.apache.commons.vfs.FileSystem;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.AbstractFileSystemProvider;
  -import org.apache.commons.vfs.provider.DefaultFileName;
   import org.apache.commons.vfs.provider.BasicFileName;
   
   /**
  
  
  

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


Mime
View raw message