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/01/24 01:20:05 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip ZipFileName.java ZipFileSystemProvider.java

adammurdoch    2003/01/23 16:20:05

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        DefaultFileName.java GenericFileName.java
                        LayeredFileName.java UriParser.java
               vfs/src/java/org/apache/commons/vfs/provider/ftp
                        FtpFileName.java FtpFileSystemProvider.java
               vfs/src/java/org/apache/commons/vfs/provider/local
                        DefaultLocalFileSystemProvider.java
                        LocalFileName.java LocalFileNameParser.java
               vfs/src/java/org/apache/commons/vfs/provider/smb
                        SmbFileName.java SmbFileSystemProvider.java
               vfs/src/java/org/apache/commons/vfs/provider/temp
                        TemporaryFileProvider.java
               vfs/src/java/org/apache/commons/vfs/provider/zip
                        ZipFileName.java ZipFileSystemProvider.java
  Log:
  More FileName tidy-ups:
  - Moved UriParser.resolveName() down to DefaultFileName.  Made the remaining UriParser's methods static.
  - DefaultFileName no longer extends UriParser.
  - Made all DefaultFileName subclasses immutable.
  
  Revision  Changes    Path
  1.8       +36 -49    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultFileName.java	23 Jan 2003 12:27:23 -0000	1.7
  +++ DefaultFileName.java	24 Jan 2003 00:20:03 -0000	1.8
  @@ -66,74 +66,43 @@
    * @version $Revision$ $Date$
    */
   public class DefaultFileName
  -    extends UriParser
       implements FileName
   {
  -    private static final char separatorChar = '/';
  -    private static final String separator = "/";
  +    public static final char separatorChar = UriParser.separatorChar;
  +    public static final String separator = UriParser.separator;
   
  -    private String scheme;
  -    private String rootUri;
  -    private String absPath;
  +    private final String scheme;
  +    private final String rootUri;
  +    private final String absPath;
   
       // Cached stuff
       private String uri;
       private String baseName;
   
       public DefaultFileName( final String scheme,
  -                            final String rootPrefix,
  +                            final String rootUri,
                               final String absPath )
       {
  -        setScheme( scheme );
  -        setRootURI( rootPrefix );
  -        setPath( absPath );
  -    }
  -
  -    public DefaultFileName( final String rootUri,
  -                            final String absPath )
  -    {
  -        this( extractScheme( rootUri ), rootUri, absPath );
  -    }
  -
  -    /**
  -     * @todo Get rid of this and make fields final again.
  -     */
  -    protected DefaultFileName()
  -    {
  -    }
  -
  -    /**
  -     * Sets the scheme for this filename.
  -     */
  -    protected void setScheme( final String scheme )
  -    {
           this.scheme = scheme;
  -    }
  -
  -    /**
  -     * Sets the path for this filename.
  -     */
  -    protected void setPath( final String absPath )
  -    {
           this.absPath = absPath;
  -    }
   
  -    /**
  -     * Sets the root URI for this filename.
  -     */
  -    protected void setRootURI( final String uri )
  -    {
           // Remove trailing separator, if any
  -        if ( uri.endsWith( separator ) )
  +        if ( rootUri.endsWith( separator ) )
           {
  -            this.rootUri = uri.substring( 0, uri.length() - 1 );
  +            this.rootUri = rootUri.substring( 0, rootUri.length() - 1 );
           }
           else
           {
  -            this.rootUri = uri;
  +            this.rootUri = rootUri;
           }
       }
   
  +    public DefaultFileName( final String rootUri,
  +                            final String absPath )
  +    {
  +        this( UriParser.extractScheme( rootUri ), rootUri, absPath );
  +    }
  +
       /**
        * Returns the hashcode for this name.
        */
  @@ -161,7 +130,8 @@
   
       /**
        * Factory method for creating name instances.  Can be overridden.
  -     * @param absPath
  +     *
  +     * @todo Implement this for all subclasses
        */
       protected FileName createName( final String absPath )
       {
  @@ -199,13 +169,30 @@
       }
   
       /**
  -     * Returns the name of a child of the file.
  +     * Resolves a name, relative to this file name.
        */
       public FileName resolveName( final String name,
                                    final NameScope scope )
           throws FileSystemException
       {
  -        final String resolvedPath = resolvePath( absPath, name );
  +        final StringBuffer buffer = new StringBuffer( name );
  +
  +        // Adjust separators
  +        UriParser.fixSeparators( buffer );
  +
  +        // Determine whether to prepend the base path
  +        if ( name.length() == 0 || name.charAt( 0 ) != separatorChar )
  +        {
  +            // Supplied path is not absolute
  +            buffer.insert( 0, separatorChar );
  +            buffer.insert( 0, absPath );
  +        }
  +
  +        // Normalise the path
  +        UriParser.normalisePath( buffer );
  +
  +        // Check the name is ok
  +        final String resolvedPath = buffer.toString();
           if ( !checkName( absPath, resolvedPath, scope ) )
           {
               throw new FileSystemException( "vfs.provider/invalid-descendent-name.error", name );
  
  
  
  1.2       +45 -66    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GenericFileName.java	23 Jan 2003 12:33:02 -0000	1.1
  +++ GenericFileName.java	24 Jan 2003 00:20:03 -0000	1.2
  @@ -68,9 +68,22 @@
   public class GenericFileName
       extends DefaultFileName
   {
  -    private String userInfo;
  -    private String hostName;
  -    private String port;
  +    private final String userInfo;
  +    private final String hostName;
  +    private final String port;
  +
  +    protected GenericFileName( final String scheme,
  +                               final String rootUri,
  +                               final String hostName,
  +                               final String port,
  +                               final String userInfo,
  +                               final String path )
  +    {
  +        super( scheme, rootUri, path );
  +        this.hostName = hostName;
  +        this.port = port;
  +        this.userInfo = userInfo;
  +    }
   
       /** Returns the user info part of the URI. */
       public String getUserInfo()
  @@ -78,63 +91,18 @@
           return userInfo;
       }
   
  -    /** Sets the user info part of the URI. */
  -    public void setUserInfo( final String userInfo )
  -    {
  -        this.userInfo = userInfo;
  -    }
  -
       /** Returns the host name part of the URI. */
       public String getHostName()
       {
           return hostName;
       }
   
  -    /** Sets the host name part of the URI. */
  -    public void setHostName( final String hostName )
  -    {
  -        this.hostName = hostName;
  -    }
  -
       /** Returns the port part of the URI. */
       public String getPort()
       {
           return port;
       }
   
  -    /** Sets the port part of the URI. */
  -    public void setPort( final String port )
  -    {
  -        this.port = port;
  -    }
  -
  -    /**
  -     * Parses a generic URI.  Briefly, a generic URI looks like:
  -     *
  -     * <pre>
  -     * &lt;scheme> '://' [ &lt;userinfo> '@' ] &lt;hostname> [ ':' &lt;port> ] '/' &lt;path>
  -     * </pre>
  -     *
  -     * <p>This method differs from the RFC, in that either / or \ is allowed
  -     * as a path separator.
  -     *
  -     * @param uri
  -     *          The URI to parse.
  -     */
  -    protected void parseGenericUri( final String uri )
  -        throws FileSystemException
  -    {
  -        final StringBuffer name = new StringBuffer();
  -
  -        // Extract the scheme and authority parts
  -        extractToPath( uri, name );
  -
  -        // Decode and normalise the file name
  -        decode( name, 0, name.length() );
  -        normalisePath( name );
  -        setPath( name.toString() );
  -    }
  -
       /**
        * Extracts the scheme, userinfo, hostname and port components of a
        * generic URI.
  @@ -145,13 +113,14 @@
        * @param name
        *          Used to return the remainder of the URI.
        */
  -    protected void extractToPath( final String uri,
  -                                  final StringBuffer name )
  +    protected static Authority extractToPath( final String uri,
  +                                              final StringBuffer name )
           throws FileSystemException
       {
  +        final Authority auth = new Authority();
  +
           // Extract the scheme
  -        final String scheme = extractScheme( uri, name );
  -        setScheme( scheme );
  +        auth.scheme = UriParser.extractScheme( uri, name );
   
           // Expecting "//"
           if ( name.length() < 2 || name.charAt( 0 ) != '/' || name.charAt( 1 ) != '/' )
  @@ -161,16 +130,15 @@
           name.delete( 0, 2 );
   
           // Extract userinfo
  -        final String userInfo = extractUserInfo( name );
  -        setUserInfo( userInfo );
  +        auth.userInfo = extractUserInfo( name );
   
  -        // Extract hostname, and normalise
  +        // Extract hostname, and normalise (lowercase)
           final String hostName = extractHostName( name );
           if ( hostName == null )
           {
               throw new FileSystemException( "vfs.provider/missing-hostname.error", uri );
           }
  -        setHostName( hostName.toLowerCase() );
  +        auth.hostName = hostName.toLowerCase();
   
           // Extract port
           final String port = extractPort( name );
  @@ -178,20 +146,22 @@
           {
               throw new FileSystemException( "vfs.provider/missing-port.error", uri );
           }
  -        setPort( port );
  +        auth.port = port;
   
           // Expecting '/' or empty name
           if ( name.length() > 0 && name.charAt( 0 ) != '/' )
           {
               throw new FileSystemException( "vfs.provider/missing-hostname-path-sep.error", uri );
           }
  +
  +        return auth;
       }
   
       /**
        * Extracts the user info from a URI.  The <scheme>:// part has been removed
        * already.
        */
  -    protected String extractUserInfo( final StringBuffer name )
  +    protected static String extractUserInfo( final StringBuffer name )
       {
           final int maxlen = name.length();
           for ( int pos = 0; pos < maxlen; pos++ )
  @@ -219,7 +189,7 @@
        * Extracts the hostname from a URI.  The <scheme>://<userinfo>@ part has
        * been removed.
        */
  -    protected String extractHostName( final StringBuffer name )
  +    protected static String extractHostName( final StringBuffer name )
       {
           final int maxlen = name.length();
           int pos = 0;
  @@ -247,7 +217,7 @@
        * Extracts the port from a URI.  The <scheme>://<userinfo>@<hostname>
        * part has been removed.
        */
  -    protected String extractPort( final StringBuffer name )
  +    protected static String extractPort( final StringBuffer name )
       {
           if ( name.length() < 1 || name.charAt( 0 ) != ':' )
           {
  @@ -273,18 +243,19 @@
       /**
        * Assembles a generic URI, appending to the supplied StringBuffer.
        */
  -    protected void appendRootUri( final StringBuffer rootUri )
  +    protected static void appendRootUri( final Authority auth,
  +                                         final StringBuffer rootUri )
       {
  -        rootUri.append( getScheme() );
  +        rootUri.append( auth.scheme );
           rootUri.append( "://" );
  -        final String userInfo = getUserInfo();
  +        final String userInfo = auth.userInfo;
           if ( userInfo != null && userInfo.length() != 0 )
           {
               rootUri.append( userInfo );
               rootUri.append( "@" );
           }
  -        rootUri.append( getHostName() );
  -        final String port = getPort();
  +        rootUri.append( auth.hostName );
  +        final String port = auth.port;
           if ( port != null && port.length() > 0 )
           {
               rootUri.append( ":" );
  @@ -292,4 +263,12 @@
           }
       }
   
  +    /** Parsed authority info (scheme, hostname, userinfo, port) */
  +    protected static class Authority
  +    {
  +        public String scheme;
  +        public String hostName;
  +        public String userInfo;
  +        public String port;
  +    }
   }
  
  
  
  1.2       +11 -7     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/LayeredFileName.java
  
  Index: LayeredFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/LayeredFileName.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LayeredFileName.java	23 Jan 2003 12:27:23 -0000	1.1
  +++ LayeredFileName.java	24 Jan 2003 00:20:03 -0000	1.2
  @@ -64,7 +64,16 @@
   public class LayeredFileName
       extends DefaultFileName
   {
  -    private String outerUri;
  +    private final String outerUri;
  +
  +    protected LayeredFileName( final String scheme,
  +                               final String rootUri,
  +                               final String outerUri,
  +                               final String path )
  +    {
  +        super( scheme, rootUri, path );
  +        this.outerUri = outerUri;
  +    }
   
       /**
        * Returns the URI of the outer file.
  @@ -72,10 +81,5 @@
       public String getOuterUri()
       {
           return outerUri;
  -    }
  -
  -    public void setOuterUri( final String outerUri )
  -    {
  -        this.outerUri = outerUri;
       }
   }
  
  
  
  1.12      +12 -87    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- UriParser.java	23 Jan 2003 12:27:23 -0000	1.11
  +++ UriParser.java	24 Jan 2003 00:20:03 -0000	1.12
  @@ -55,75 +55,36 @@
    */
   package org.apache.commons.vfs.provider;
   
  -import java.util.HashSet;
  -import java.util.Iterator;
   import org.apache.commons.vfs.FileSystemException;
   
   /**
  - * A name parser which parses absolute URIs.  See RFC 2396 for details.
  + * Utilities for dealing with URIs.  See RFC 2396 for details.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -public class UriParser
  +public final class UriParser
   {
       /** The normalised separator to use. */
  -    private final char separatorChar;
  +    public static final char separatorChar = '/';
  +
  +    /** The normalised separator to use. */
  +    public static final String separator = "/";
   
       /**
        * The set of valid separators.  These are all converted to the normalised one.
        * Does <i>not</i> contain the normalised separator
        */
  -    private final char[] separators;
  +    public static final char[] separators = { '\\' };
   
  -    /**
  -     * Creates a parser, using '/' and '\' as the path separators.
  -     */
  -    public UriParser()
  +    private UriParser()
       {
  -        this( null );
  -    }
  -
  -    /**
  -     * Creates a parser, using '/' and '\' as the path separators, along with
  -     * a provider-specific set of separators.
  -     *
  -     * @param separators
  -     *          Additional legal separator characters.  Any occurrences of
  -     *          these in paths are replaced with the separator char.
  -     */
  -    protected UriParser( final char[] separators )
  -    {
  -        separatorChar = '/';
  -
  -        // Remove the separator char from the separators array
  -        final HashSet set = new HashSet();
  -        set.add( new Character( '\\' ) );
  -        if ( separators != null )
  -        {
  -            for ( int i = 0; i < separators.length; i++ )
  -            {
  -                char separator = separators[ i ];
  -                if ( separator == separatorChar )
  -                {
  -                    continue;
  -                }
  -                set.add( new Character( separator ) );
  -            }
  -        }
  -        this.separators = new char[ set.size() ];
  -        final Iterator iter = set.iterator();
  -        for ( int i = 0; i < this.separators.length; i++ )
  -        {
  -            final Character ch = (Character)iter.next();
  -            this.separators[ i ] = ch.charValue();
  -        }
       }
   
       /**
        * Extracts the first element of a path.
        */
  -    protected String extractFirstElement( final StringBuffer name )
  +    public static String extractFirstElement( final StringBuffer name )
       {
           final int len = name.length();
           if ( len < 1 )
  @@ -153,42 +114,6 @@
       }
   
       /**
  -     * Resolves a path, relative to a base path.  If the supplied path
  -     * is an absolute path, it is normalised and returned.  If the supplied
  -     * path is a relative path, it is resolved relative to the base path.
  -     *
  -     * @param basePath
  -     *          A <i>normalised</i> path.
  -     *
  -     * @param path
  -     *          The path to resolve.  Does not need to be normalised, but
  -     *          does need to be a path (i.e. not an absolute URI).
  -     *
  -     */
  -    public String resolvePath( final String basePath,
  -                               final String path )
  -        throws FileSystemException
  -    {
  -        final StringBuffer buffer = new StringBuffer( path );
  -
  -        // Adjust separators
  -        fixSeparators( buffer );
  -
  -        // Determine whether to prepend the base path
  -        if ( path.length() == 0 || path.charAt( 0 ) != separatorChar )
  -        {
  -            // Supplied path is not absolute
  -            buffer.insert( 0, separatorChar );
  -            buffer.insert( 0, basePath );
  -        }
  -
  -        // Normalise the path
  -        normalisePath( buffer );
  -        return buffer.toString();
  -    }
  -
  -
  -    /**
        * Normalises a path.  Does the following:
        * <ul>
        * <li>Normalises separators, where more than one can be used.
  @@ -197,7 +122,7 @@
        * <li>Removes trailing separator.
        * </ul>
        */
  -    public void normalisePath( final StringBuffer path )
  +    public static void normalisePath( final StringBuffer path )
           throws FileSystemException
       {
           if ( path.length() == 0 )
  @@ -280,9 +205,9 @@
       }
   
       /**
  -     * Adjusts the separators in a name.
  +     * Normalises the separators in a name.
        */
  -    protected boolean fixSeparators( final StringBuffer name )
  +    public static boolean fixSeparators( final StringBuffer name )
       {
           if ( separators.length == 0 )
           {
  
  
  
  1.2       +63 -26    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FtpFileName.java	23 Jan 2003 12:33:02 -0000	1.1
  +++ FtpFileName.java	24 Jan 2003 00:20:04 -0000	1.2
  @@ -56,6 +56,7 @@
   package org.apache.commons.vfs.provider.ftp;
   
   import org.apache.commons.vfs.provider.GenericFileName;
  +import org.apache.commons.vfs.provider.UriParser;
   import org.apache.commons.vfs.FileSystemException;
   
   /**
  @@ -68,64 +69,100 @@
   class FtpFileName
       extends GenericFileName
   {
  -    private String userName;
  -    private String password;
  +    private final String userName;
  +    private final String password;
   
  -    public FtpFileName( final String uri )
  +    private FtpFileName( final String scheme,
  +                         final String rootUri,
  +                         final String hostName,
  +                         final String port,
  +                         final String userInfo,
  +                         final String userName,
  +                         final String password,
  +                         final String path )
  +    {
  +        super( scheme, rootUri, hostName, port, userInfo, path );
  +        this.password = password;
  +        this.userName = userName;
  +    }
  +
  +    /**
  +     * Parses an FTP URI.
  +     */
  +    public static FtpFileName parseUri( final String uri )
           throws FileSystemException
       {
           // FTP URI are generic URI (as per RFC 2396)
  -        parseGenericUri( uri );
  +        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();
   
           // Drop the port if it is 21
  -        final String port = getPort();
  +        final String port = auth.port;
           if ( port != null && port.equals( "21" ) )
           {
  -            setPort( null );
  +            auth.port = null;
           }
   
           // Split up the userinfo into a username and password
           // TODO - push this into GenericFileName
  -        final String userInfo = getUserInfo();
  +        final String userInfo = auth.userInfo;
  +        final String userName;
  +        final String password;
           if ( userInfo != null )
           {
               int idx = userInfo.indexOf( ':' );
               if ( idx == -1 )
               {
  -                setUserName( userInfo );
  +                userName = userInfo;
  +                password = null;
               }
               else
               {
  -                String userName = userInfo.substring( 0, idx );
  -                String password = userInfo.substring( idx + 1 );
  -                setUserName( userName );
  -                setPassword( password );
  +                userName = userInfo.substring( 0, idx );
  +                password = userInfo.substring( idx + 1 );
               }
           }
  +        else
  +        {
  +            userName = null;
  +            password = null;
  +        }
   
           // Now build the root URI
  -        final StringBuffer rootUri = new StringBuffer();
  -        appendRootUri( rootUri );
  -        setRootURI( rootUri.toString() );
  +        final StringBuffer buffer = new StringBuffer();
  +        appendRootUri( auth, buffer );
  +        final String rootUri = buffer.toString();
  +
  +        return new FtpFileName( auth.scheme,
  +                                rootUri,
  +                                auth.hostName,
  +                                auth.port,
  +                                auth.userInfo,
  +                                userName,
  +                                password,
  +                                path );
       }
   
  +    /**
  +     * Returns the user name.
  +     */
       public String getUserName()
       {
           return userName;
       }
   
  -    public void setUserName( final String userName )
  -    {
  -        this.userName = userName;
  -    }
  -
  +    /**
  +     * Returns the password.
  +     */
       public String getPassword()
       {
           return password;
  -    }
  -
  -    public void setPassword( final String password )
  -    {
  -        this.password = password;
       }
   }
  
  
  
  1.11      +1 -1      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FtpFileSystemProvider.java	23 Jan 2003 12:33:02 -0000	1.10
  +++ FtpFileSystemProvider.java	24 Jan 2003 00:20:04 -0000	1.11
  @@ -75,7 +75,7 @@
       protected FileName parseUri( final String uri )
           throws FileSystemException
       {
  -        return new FtpFileName( uri );
  +        return FtpFileName.parseUri( uri );
       }
   
       /**
  
  
  
  1.14      +1 -1      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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultLocalFileSystemProvider.java	23 Jan 2003 12:33:02 -0000	1.13
  +++ DefaultLocalFileSystemProvider.java	24 Jan 2003 00:20:04 -0000	1.14
  @@ -123,7 +123,7 @@
       protected FileName parseUri( final String uri )
           throws FileSystemException
       {
  -        return new LocalFileName( uri, parser );
  +        return LocalFileName.parseUri( uri, parser );
       }
   
       /**
  
  
  
  1.2       +34 -20    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFileName.java
  
  Index: LocalFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFileName.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalFileName.java	23 Jan 2003 12:33:02 -0000	1.1
  +++ LocalFileName.java	24 Jan 2003 00:20:04 -0000	1.2
  @@ -57,6 +57,7 @@
   
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.DefaultFileName;
  +import org.apache.commons.vfs.provider.UriParser;
   
   /**
    * A local file URI.
  @@ -67,44 +68,57 @@
   class LocalFileName
       extends DefaultFileName
   {
  -    private String rootFile;
  +    private final String rootFile;
   
  -    public LocalFileName( final String uri, final LocalFileNameParser parser )
  +    private LocalFileName( final String scheme,
  +                           final String rootUri,
  +                           final String rootFile,
  +                           final String path )
  +    {
  +        super( scheme, rootUri, path );
  +        this.rootFile = rootFile;
  +    }
  +
  +    /**
  +     * Parses an absolute file URI.
  +     *
  +     * @todo Make parser a static field
  +     */
  +    public static LocalFileName parseUri( final String uri,
  +                                          final LocalFileNameParser parser )
           throws FileSystemException
       {
           final StringBuffer name = new StringBuffer();
   
           // Extract the scheme
  -        final String scheme = extractScheme( uri, name );
  -        setScheme( scheme );
  +        final String scheme = UriParser.extractScheme( uri, name );
   
           // Remove encoding, and adjust the separators
  -        decode( name, 0, name.length() );
  -        fixSeparators( name );
  +        UriParser.decode( name, 0, name.length() );
  +        UriParser.fixSeparators( name );
   
           // Extract the root prefix
           final String rootFile = parser.extractRootPrefix( uri, name );
  -        setRootFile( rootFile );
   
           // Normalise the path
  -        normalisePath( name );
  -        setPath( name.toString() );
  +        UriParser.normalisePath( name );
  +        final String path = name.toString();
   
           // Build the root URI
  -        final StringBuffer rootUri = new StringBuffer();
  -        rootUri.append( scheme );
  -        rootUri.append( "://" );
  -        rootUri.append( rootFile );
  -        setRootURI( rootUri.toString() );
  +        final StringBuffer buffer = new StringBuffer();
  +        buffer.append( scheme );
  +        buffer.append( "://" );
  +        buffer.append( rootFile );
  +        final String rootUri = buffer.toString();
  +
  +        return new LocalFileName( scheme, rootUri, rootFile, path );
       }
   
  +    /**
  +     * Returns the root file for this file.
  +     */
       public String getRootFile()
       {
           return rootFile;
  -    }
  -
  -    public void setRootFile( final String rootPrefix )
  -    {
  -        rootFile = rootPrefix;
       }
   }
  
  
  
  1.7       +1 -8      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFileNameParser.java
  
  Index: LocalFileNameParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFileNameParser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LocalFileNameParser.java	23 Jan 2003 12:27:24 -0000	1.6
  +++ LocalFileNameParser.java	24 Jan 2003 00:20:04 -0000	1.7
  @@ -55,7 +55,6 @@
    */
   package org.apache.commons.vfs.provider.local;
   
  -import java.io.File;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.UriParser;
   
  @@ -66,13 +65,7 @@
    * @version $Revision$ $Date$
    */
   abstract class LocalFileNameParser
  -    extends UriParser
   {
  -    public LocalFileNameParser()
  -    {
  -        super( new char[]{File.separatorChar, '/', '\\'} );
  -    }
  -
       /**
        * Determines if a name is an absolute file name.
        */
  @@ -82,7 +75,7 @@
           StringBuffer b = new StringBuffer( name );
           try
           {
  -            fixSeparators( b );
  +            UriParser.fixSeparators( b );
               extractRootPrefix( name, b );
               return true;
           }
  
  
  
  1.2       +43 -23    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SmbFileName.java	23 Jan 2003 12:33:02 -0000	1.1
  +++ SmbFileName.java	24 Jan 2003 00:20:04 -0000	1.2
  @@ -56,6 +56,7 @@
   package org.apache.commons.vfs.provider.smb;
   
   import org.apache.commons.vfs.provider.GenericFileName;
  +import org.apache.commons.vfs.provider.UriParser;
   import org.apache.commons.vfs.FileSystemException;
   
   /**
  @@ -67,51 +68,70 @@
   class SmbFileName
       extends GenericFileName
   {
  -    private String share;
  +    private final String share;
   
  -    public SmbFileName( final String uri )
  +    private SmbFileName( final String scheme,
  +                         final String rootUri,
  +                         final String hostName,
  +                         final String port,
  +                         final String userInfo,
  +                         final String share,
  +                         final String path )
  +    {
  +        super( scheme, rootUri, hostName, port, userInfo, path );
  +        this.share = share;
  +    }
  +
  +    /**
  +     * Parses an SMB URI.
  +     */
  +    public static SmbFileName parseUri( final String uri )
           throws FileSystemException
       {
           final StringBuffer name = new StringBuffer();
   
           // Extract the scheme and authority parts
  -        extractToPath( uri, name );
  +        final Authority auth = extractToPath( uri, name );
   
           // TODO - drop the default port
   
           // Decode and adjust separators
  -        decode( name, 0, name.length() );
  -        fixSeparators( name );
  +        UriParser.decode( name, 0, name.length() );
  +        UriParser.fixSeparators( name );
   
           // Extract the share
  -        final String share = extractFirstElement( name );
  +        final String share = UriParser.extractFirstElement( name );
           if ( share == null )
           {
               throw new FileSystemException( "vfs.provider.smb/missing-share-name.error", uri );
           }
  -        setShare( share );
  -
  -        // Normalise the path
  -        normalisePath( name );
   
  -        // Set the path
  -        setPath( name.toString() );
  +        // Normalise the path.  Do this after extracting the share name,
  +        // to deal with things like smb://hostname/share/..
  +        UriParser.normalisePath( name );
  +        final String path = name.toString();
   
           // Set the root URI
  -        StringBuffer rootUri = new StringBuffer();
  -        appendRootUri( rootUri );
  -        rootUri.append( '/' );
  -        rootUri.append( share );
  -        setRootURI( rootUri.toString() );
  +        StringBuffer buffer = new StringBuffer();
  +        appendRootUri( auth, buffer );
  +        buffer.append( '/' );
  +        buffer.append( share );
  +        final String rootUri = buffer.toString();
  +
  +        return new SmbFileName( auth.scheme,
  +                                rootUri,
  +                                auth.hostName,
  +                                auth.port,
  +                                auth.userInfo,
  +                                share,
  +                                path );
       }
   
  +    /**
  +     * Returns the share name.
  +     */
       public String getShare()
       {
           return share;
  -    }
  -
  -    public void setShare( final String share )
  -    {
  -        this.share = share;
       }
   }
  
  
  
  1.11      +1 -1      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SmbFileSystemProvider.java	23 Jan 2003 12:33:02 -0000	1.10
  +++ SmbFileSystemProvider.java	24 Jan 2003 00:20:04 -0000	1.11
  @@ -77,7 +77,7 @@
       protected FileName parseUri( final String uri )
           throws FileSystemException
       {
  -        return new SmbFileName( uri );
  +        return SmbFileName.parseUri( uri );
       }
   
       /**
  
  
  
  1.5       +4 -5      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/temp/TemporaryFileProvider.java
  
  Index: TemporaryFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/temp/TemporaryFileProvider.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TemporaryFileProvider.java	23 Jan 2003 12:27:26 -0000	1.4
  +++ TemporaryFileProvider.java	24 Jan 2003 00:20:04 -0000	1.5
  @@ -76,7 +76,6 @@
       extends AbstractFileSystemProvider
       implements FileProvider
   {
  -    private final UriParser parser = new UriParser();
       private File rootFile;
   
       public TemporaryFileProvider( final File rootFile )
  @@ -96,9 +95,9 @@
       {
           // Parse the name
           final StringBuffer buffer = new StringBuffer( uri );
  -        final String scheme = parser.extractScheme( uri, buffer );
  -        parser.decode( buffer, 0, buffer.length() );
  -        parser.normalisePath( buffer );
  +        final String scheme = UriParser.extractScheme( uri, buffer );
  +        UriParser.decode( buffer, 0, buffer.length() );
  +        UriParser.normalisePath( buffer );
           final String path = buffer.toString();
   
           // Create the temp file system if it does not exist
  
  
  
  1.2       +35 -21    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileName.java
  
  Index: ZipFileName.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileName.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ZipFileName.java	23 Jan 2003 12:33:04 -0000	1.1
  +++ ZipFileName.java	24 Jan 2003 00:20:04 -0000	1.2
  @@ -57,6 +57,7 @@
   
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.LayeredFileName;
  +import org.apache.commons.vfs.provider.UriParser;
   
   /**
    * A parser for Zip file names.
  @@ -69,36 +70,49 @@
   {
       private static final char[] ZIP_URL_RESERVED_CHARS = {'!'};
   
  -    public ZipFileName( final String uri )
  +    public ZipFileName( final String scheme,
  +                        final String zipFileUri,
  +                        final String path )
  +    {
  +        super( scheme,
  +               formatRootUri( scheme, zipFileUri ),
  +               zipFileUri, path );
  +    }
  +
  +    /**
  +     * Assembles the root URI for a Zip file.
  +     */
  +    private static String formatRootUri( final String scheme,
  +                                         final String outerFileUri )
  +    {
  +        final StringBuffer buffer = new StringBuffer();
  +        buffer.append( scheme );
  +        buffer.append( ":" );
  +        UriParser.appendEncoded( buffer, outerFileUri, ZIP_URL_RESERVED_CHARS );
  +        buffer.append( "!" );
  +        return buffer.toString();
  +    }
  +
  +    /**
  +     * Parses a Zip URI.
  +     */
  +    public static ZipFileName parseUri( final String uri )
           throws FileSystemException
       {
           final StringBuffer name = new StringBuffer();
   
           // Extract the scheme
  -        final String scheme = extractScheme( uri, name );
  -        setScheme( scheme );
  +        final String scheme = UriParser.extractScheme( uri, name );
   
           // Extract the Zip file URI
           final String zipUri = extractZipName( name );
  -        setOuterUri( zipUri );
   
           // Decode and normalise the path
  -        decode( name, 0, name.length() );
  -        normalisePath( name );
  -        setPath( name.toString() );
  -    }
  +        UriParser.decode( name, 0, name.length() );
  +        UriParser.normalisePath( name );
  +        final String path = name.toString();
   
  -    public ZipFileName( final String scheme,
  -                              final String outerFileUri,
  -                              final String path )
  -    {
  -        final StringBuffer rootUri = new StringBuffer();
  -        rootUri.append( scheme );
  -        rootUri.append( ":" );
  -        appendEncoded( rootUri, outerFileUri, ZIP_URL_RESERVED_CHARS );
  -        rootUri.append( "!" );
  -        setRootURI( rootUri.toString() );
  -        setPath( path );
  +        return new ZipFileName( scheme, zipUri, path );
       }
   
       /**
  @@ -126,6 +140,6 @@
           }
   
           // Decode the name
  -        return decode( prefix );
  +        return UriParser.decode( prefix );
       }
   }
  
  
  
  1.17      +1 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystemProvider.java
  
  Index: ZipFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystemProvider.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ZipFileSystemProvider.java	23 Jan 2003 12:33:04 -0000	1.16
  +++ ZipFileSystemProvider.java	24 Jan 2003 00:20:04 -0000	1.17
  @@ -79,7 +79,7 @@
       protected FileName parseUri( final String uri )
           throws FileSystemException
       {
  -        return new ZipFileName( uri );
  +        return ZipFileName.parseUri( uri );
       }
   
       /**
  
  
  

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