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/24 08:28:20 UTC

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

adammurdoch    2003/02/23 23:28:20

  Modified:    vfs/src/java/org/apache/commons/vfs FileSystemManager.java
               vfs/src/java/org/apache/commons/vfs/impl
                        DefaultFileSystemManager.java
               vfs/src/test/org/apache/commons/vfs/provider/jar/test
                        NestedJarTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/test
                        JunctionProviderConfig.java JunctionTests.java
                        VirtualProviderTestCase.java
               vfs/src/test/org/apache/commons/vfs/provider/zip/test
                        NestedZipTestCase.java
  Added:       vfs/src/java/org/apache/commons/vfs/impl FileTypeMap.java
  Log:
  FileSystemManager:
  - Renamed createFileSystem() to createVirtualFileSystem().
  - Added createFileSystem() that guesses the file-system type from the file's mime type
    and name.  Changed tests to use this.
  
  Revision  Changes    Path
  1.11      +45 -42    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemManager.java
  
  Index: FileSystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FileSystemManager.java	12 Feb 2003 07:56:09 -0000	1.10
  +++ FileSystemManager.java	24 Feb 2003 07:28:19 -0000	1.11
  @@ -113,13 +113,11 @@
        * Locates a file by name.  Equivalent to calling
        * <code>resolveFile(uri, getBaseName())</code>.
        *
  -     * @param name
  -     *          The name of the file.
  +     * @param name The name of the file.
        *
        * @return The file.  Never returns null.
        *
  -     * @throws FileSystemException
  -     *          On error parsing the file name.
  +     * @throws FileSystemException On error parsing the file name.
        */
       FileObject resolveFile( String name )
           throws FileSystemException;
  @@ -132,16 +130,14 @@
        *
        * <p>Note that the file does not have to exist when this method is called.
        *
  -     * @param name
  -     *          The name of the file.
  +     * @param name The name of the file.
        *
  -     * @param baseFile
  -     *          The base file to use to resolve relative paths.  May be null.
  +     * @param baseFile The base file to use to resolve relative paths.
  +     *        May be null.
        *
        * @return The file.  Never returns null.
        *
  -     * @throws FileSystemException
  -     *          On error parsing the file name.
  +     * @throws FileSystemException On error parsing the file name.
        */
       FileObject resolveFile( FileObject baseFile, String name )
           throws FileSystemException;
  @@ -150,16 +146,14 @@
        * Locates a file by name.  See {@link #resolveFile(FileObject, String)}
        * for details.
        *
  -     * @param baseFile
  -     *          The base file to use to resolve relative paths.  May be null.
  +     * @param baseFile The base file to use to resolve relative paths.
  +     *        May be null.
        *
  -     * @param name
  -     *          The name of the file.
  +     * @param name The name of the file.
        *
        * @return The file.  Never returns null.
        *
  -     * @throws FileSystemException
  -     *          On error parsing the file name.
  +     * @throws FileSystemException On error parsing the file name.
        *
        */
       FileObject resolveFile( File baseFile, String name )
  @@ -168,51 +162,54 @@
       /**
        * Converts a local file into a {@link FileObject}.
        *
  -     * @param file
  -     *          The file to convert.
  +     * @param file The file to convert.
        *
  -     * @return
  -     *          The {@link FileObject} that represents the local file.  Never
  -     *          returns null.
  +     * @return The {@link FileObject} that represents the local file.  Never
  +     *         returns null.
        *
  -     * @throws FileSystemException
  -     *          On error converting the file.
  +     * @throws FileSystemException On error converting the file.
        */
       FileObject toFileObject( File file )
           throws FileSystemException;
   
       /**
        * Creates a layered file system.  A layered file system is a file system
  -     * that is created from the contents of another file, such as a zip
  -     * or tar file.
  +     * that is created from the contents of a file, such as a zip or tar file.
        *
  -     * @param provider
  -     *          The name of the file system provider to use.  This name is
  -     *          the same as the scheme used in URI to identify the provider.
  +     * @param provider The name of the file system provider to use.  This name
  +     *        is the same as the scheme used in URI to identify the provider.
        *
  -     * @param file
  -     *          The file to use to create the file system.
  +     * @param file The file to use to create the file system.
        *
  -     * @return
  -     *          The root file of the new file system.
  +     * @return The root file of the new file system.
        *
  -     * @throws FileSystemException
  -     *          On error creating the file system.
  +     * @throws FileSystemException On error creating the file system.
        */
       FileObject createFileSystem( String provider, FileObject file )
           throws FileSystemException;
   
       /**
  +     * Creates a layered file system.  A layered file system is a file system
  +     * that is created from the contents of a file, such as a zip or tar file.
  +     *
  +     * @param file The file to use to create the file system.
  +     *
  +     * @return The root file of the new file system.
  +     *
  +     * @throws FileSystemException On error creating the file system.
  +     */
  +    FileObject createFileSystem( FileObject file )
  +        throws FileSystemException;
  +
  +    /**
        * Creates an empty virtual file system.  Can be populated by adding
        * junctions to it.
        *
  -     * @param rootUri
  -     *          The root URI to use for the new file system.  Can be null.
  +     * @param rootUri The root URI to use for the new file system.  Can be null.
        *
  -     * @return
  -     *          The root file of the new file system.
  +     * @return The root file of the new file system.
        */
  -    FileObject createFileSystem( String rootUri )
  +    FileObject createVirtualFileSystem( String rootUri )
           throws FileSystemException;
   
       /**
  @@ -221,10 +218,9 @@
        *
        * @param rootFile The root file to backs the file system.
        *
  -     * @return
  -     *          The root of the new file system.
  +     * @return The root of the new file system.
        */
  -    FileObject createFileSystem( FileObject rootFile )
  +    FileObject createVirtualFileSystem( FileObject rootFile )
           throws FileSystemException;
   
       /**
  @@ -232,4 +228,11 @@
        * FileSystemManager.
        */
       URLStreamHandlerFactory getURLStreamHandlerFactory();
  +
  +    /**
  +     * Determines if a layered file system can be created for a given file.
  +     *
  +     * @param file The file to check for.
  +     */
  +    boolean canCreateFileSystem( FileObject file ) throws FileSystemException;
   }
  
  
  
  1.21      +51 -9     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
  
  Index: DefaultFileSystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DefaultFileSystemManager.java	21 Feb 2003 05:13:58 -0000	1.20
  +++ DefaultFileSystemManager.java	24 Feb 2003 07:28:19 -0000	1.21
  @@ -110,7 +110,7 @@
           new DefaultVfsComponentContext( this );
   
       private TemporaryFileStore tempFileStore;
  -
  +    private final FileTypeMap map = new FileTypeMap();
       private final VirtualFileProvider vfsProvider = new VirtualFileProvider();
       private boolean init;
   
  @@ -128,8 +128,7 @@
   
       /**
        * Registers a file system provider.  The manager takes care of all
  -     * lifecycle management.  A provider may be registered multiple times
  -     * with different schemes.
  +     * lifecycle management.  A provider may be registered multiple times.
        *
        * @param urlScheme The scheme the provider will handle.
        * @param provider The provider.
  @@ -143,8 +142,7 @@
   
       /**
        * Registers a file system provider.  The manager takes care of all
  -     * lifecycle management.  A provider may be registered multiple times
  -     * with different schemes.
  +     * lifecycle management.  A provider may be registered multiple times.
        *
        * @param urlSchemes The schemes the provider will handle.
        * @param provider The provider.
  @@ -188,6 +186,26 @@
       }
   
       /**
  +     * Adds an filename extension mapping.
  +     * @param extension The file name extension.
  +     * @param scheme The scheme to use for files with this extension.
  +     */
  +    public void addExtensionMap( final String extension, final String scheme )
  +    {
  +        map.addExtension( extension, scheme );
  +    }
  +
  +    /**
  +     * Adds a mime type mapping.
  +     * @param mimeType The mime type.
  +     * @param scheme The scheme to use for files with this mime type.
  +     */
  +    public void addMimeTypeMap( final String mimeType, final String scheme )
  +    {
  +        map.addMimeType( mimeType, scheme );
  +    }
  +
  +    /**
        * Sets the default provider.  This is the provider that will handle URI
        * with unknown schemes.  The manager takes care of all lifecycle
        * management.
  @@ -442,18 +460,42 @@
                                           final FileObject file )
           throws FileSystemException
       {
  -        FileProvider provider = (FileProvider)providers.get( scheme );
  +        final FileProvider provider = (FileProvider)providers.get( scheme );
           if ( provider == null )
           {
  -            throw new FileSystemException( "vfs.impl/unknown-provider.error", scheme );
  +            throw new FileSystemException( "vfs.impl/unknown-provider.error", new Object[] { scheme, file } );
           }
           return provider.createFileSystem( scheme, file );
       }
   
       /**
  +     * Creates a layered file system.
  +     */
  +    public FileObject createFileSystem( final FileObject file )
  +        throws FileSystemException
  +    {
  +        final String scheme = map.getScheme( file );
  +        if ( scheme == null )
  +        {
  +            throw new FileSystemException( "vfs.impl/no-provider-for-file.error", file );
  +        }
  +        return createFileSystem( scheme, file );
  +    }
  +
  +    /**
  +     * Determines if a layered file system can be created for a given file.
  +     *
  +     * @param file The file to check for.
  +     */
  +    public boolean canCreateFileSystem( final FileObject file ) throws FileSystemException
  +    {
  +        return ( map.getScheme( file ) != null );
  +    }
  +
  +    /**
        * Creates a virtual file system.
        */
  -    public FileObject createFileSystem( final FileObject rootFile )
  +    public FileObject createVirtualFileSystem( final FileObject rootFile )
           throws FileSystemException
       {
           return vfsProvider.createFileSystem( rootFile );
  @@ -462,7 +504,7 @@
       /**
        * Creates an empty virtual file system.
        */
  -    public FileObject createFileSystem( final String rootUri )
  +    public FileObject createVirtualFileSystem( final String rootUri )
           throws FileSystemException
       {
           return vfsProvider.createFileSystem( rootUri );
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/FileTypeMap.java
  
  Index: FileTypeMap.java
  ===================================================================
  /* ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.vfs.impl;
  
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.commons.vfs.FileContent;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  
  /**
   * A helper class that determines the provider to use for a file.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2003/02/24 07:28:19 $
   */
  class FileTypeMap
  {
      private final Map mimeTypeMap = new HashMap();
      private final Map extensionMap = new HashMap();
  
      /**
       * Adds a MIME type mapping.
       */
      public void addMimeType( final String mimeType, final String scheme )
      {
          mimeTypeMap.put( mimeType, scheme );
      }
  
      /**
       * Adds a filename extension mapping.
       */
      public void addExtension( final String extension, final String scheme )
      {
          extensionMap.put( extension, scheme );
      }
  
      /**
       * Finds the provider to use to create a filesystem from a given file.
       */
      public String getScheme( final FileObject file ) throws FileSystemException
      {
          // Check the file's mime type for a match
          final FileContent content = file.getContent();
          final String mimeType = (String)content.getAttribute( "content-type" );
          if ( mimeType != null )
          {
              final String scheme = (String)mimeTypeMap.get( mimeType );
              if ( scheme != null )
              {
                  return scheme;
              }
          }
  
          // Check the file's extension for a match
          final String extension = file.getName().getExtension();
          return (String)extensionMap.get( extension );
      }
  }
  
  
  
  1.8       +2 -1      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/NestedJarTestCase.java
  
  Index: NestedJarTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/NestedJarTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NestedJarTestCase.java	17 Feb 2003 09:22:15 -0000	1.7
  +++ NestedJarTestCase.java	24 Feb 2003 07:28:19 -0000	1.8
  @@ -90,6 +90,7 @@
           throws Exception
       {
           manager.addProvider( "jar", new JarFileProvider() );
  +        manager.addExtensionMap( "jar", "jar" );
       }
   
       /**
  @@ -103,7 +104,7 @@
           final FileObject jarFile = manager.resolveFile( uri );
   
           // Now build the nested file system
  -        final FileObject nestedFS = manager.createFileSystem( "jar", jarFile );
  +        final FileObject nestedFS = manager.createFileSystem( jarFile );
           return nestedFS.resolveFile( "/" );
       }
   }
  
  
  
  1.6       +2 -2      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java
  
  Index: JunctionProviderConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JunctionProviderConfig.java	23 Feb 2003 00:40:37 -0000	1.5
  +++ JunctionProviderConfig.java	24 Feb 2003 07:28:19 -0000	1.6
  @@ -94,7 +94,7 @@
           final FileObject baseFolder = config.getBaseTestFolder( manager );
   
           // Create an empty file system, then link in the base folder
  -        final FileSystem newFs = manager.createFileSystem( "vfs:" ).getFileSystem();
  +        final FileSystem newFs = manager.createVirtualFileSystem( "vfs:" ).getFileSystem();
           final String junctionPoint = "/some/dir";
           newFs.addJunction( junctionPoint, baseFolder );
   
  
  
  
  1.5       +3 -3      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionTests.java
  
  Index: JunctionTests.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionTests.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JunctionTests.java	21 Feb 2003 13:18:17 -0000	1.4
  +++ JunctionTests.java	24 Feb 2003 07:28:19 -0000	1.5
  @@ -83,7 +83,7 @@
        */
       public void testNestedJunction() throws Exception
       {
  -        final FileSystem fs = getManager().createFileSystem( "vfs:" ).getFileSystem();
  +        final FileSystem fs = getManager().createVirtualFileSystem( "vfs:" ).getFileSystem();
           final FileObject baseDir = getBaseDir();
           fs.addJunction( "/a", baseDir );
   
  @@ -115,7 +115,7 @@
        */
       public void testAncestors() throws Exception
       {
  -        final FileSystem fs = getManager().createFileSystem( "vfs://" ).getFileSystem();
  +        final FileSystem fs = getManager().createVirtualFileSystem( "vfs://" ).getFileSystem();
           final FileObject baseDir = getBaseDir();
   
           // Make sure the file at the junction point and its ancestors do not exist
  
  
  
  1.5       +2 -2      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/VirtualProviderTestCase.java
  
  Index: VirtualProviderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/VirtualProviderTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- VirtualProviderTestCase.java	12 Feb 2003 07:56:19 -0000	1.4
  +++ VirtualProviderTestCase.java	24 Feb 2003 07:28:19 -0000	1.5
  @@ -86,6 +86,6 @@
       {
           final File baseDir = AbstractVfsTestCase.getTestDirectory();
           final FileObject baseFile = manager.toFileObject( baseDir );
  -        return manager.createFileSystem( baseFile );
  +        return manager.createVirtualFileSystem( baseFile );
       }
   }
  
  
  
  1.6       +2 -1      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java
  
  Index: NestedZipTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/zip/test/NestedZipTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NestedZipTestCase.java	17 Feb 2003 09:22:16 -0000	1.5
  +++ NestedZipTestCase.java	24 Feb 2003 07:28:20 -0000	1.6
  @@ -89,6 +89,7 @@
           throws Exception
       {
           manager.addProvider( "zip", new ZipFileProvider() );
  +        manager.addExtensionMap( "zip", "zip" );
       }
   
       /**
  @@ -102,7 +103,7 @@
           final FileObject zipFile = manager.resolveFile( uri );
   
           // Now build the nested file system
  -        final FileObject nestedFS = manager.createFileSystem( "zip", zipFile );
  +        final FileObject nestedFS = manager.createFileSystem( zipFile );
           return nestedFS.resolveFile( "/" );
       }
   }
  
  
  

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