Author: imario
Date: Mon May 14 11:24:35 2007
New Revision: 537936

URL: http://svn.apache.org/viewvc?view=rev&rev=537936
Log:
VFS-145 + VFS-157: Use HashMap for caches and cache calculated hashCode in 
FileName - Thanks to Adam Heath for the patch!

Modified:
    
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/DefaultFilesCache.java
    
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
    
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileName.java

Modified: 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/DefaultFilesCache.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/DefaultFilesCache.java?view=diff&rev=537936&r1=537935&r2=537936
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/DefaultFilesCache.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/DefaultFilesCache.java
 Mon May 14 11:24:35 2007
@@ -22,7 +22,6 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.TreeMap;
 
 /**
  * A [EMAIL PROTECTED] org.apache.commons.vfs.FilesCache} implementation.<br>
@@ -58,7 +57,7 @@
         Map files = (Map) filesystemCache.get(filesystem);
         if (files == null)
         {
-            files = new TreeMap();
+            files = new HashMap();
             filesystemCache.put(filesystem, files);
         }
 

Modified: 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java?view=diff&rev=537936&r1=537935&r2=537936
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
 Mon May 14 11:24:35 2007
@@ -16,14 +16,6 @@
  */
 package org.apache.commons.vfs.cache;
 
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.vfs.FileName;
@@ -33,6 +25,13 @@
 import org.apache.commons.vfs.impl.DefaultFileSystemManager;
 import org.apache.commons.vfs.util.Messages;
 
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
 /**
  * This implementation caches every file as long as it is strongly reachable by
  * the java vm. As soon as the vm needs memory - every softly reachable file
@@ -289,7 +288,7 @@
                        Map files = (Map) filesystemCache.get(filesystem);
                        if (files == null)
                        {
-                               files = new TreeMap();
+                               files = new HashMap();
                                filesystemCache.put(filesystem, files);
                        }
 

Modified: 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileName.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileName.java?view=diff&rev=537936&r1=537935&r2=537936
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileName.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/AbstractFileName.java
 Mon May 14 11:24:35 2007
@@ -29,479 +29,487 @@
  * @version $Revision$ $Date$
  */
 public abstract class AbstractFileName
-    implements FileName
+       implements FileName
 {
 
-    private final String scheme;
-    private final String absPath;
-    private FileType type;
-
-    // Cached stuff
-    private String uri;
-    private String baseName;
-    private String rootUri;
-    private String extension;
-    private String decodedAbsPath;
-
-    public AbstractFileName(final String scheme,
-                            final String absPath, FileType type)
-    {
-        this.rootUri = null;
-        this.scheme = scheme;
-        this.type = type;
-        if (absPath != null && absPath.length() > 0)
-        {
-            if (absPath.length() > 1 && absPath.endsWith("/"))
-            {
-                this.absPath = absPath.substring(0, absPath.length() - 1);
-            }
-            else
-            {
-                this.absPath = absPath;
-            }
-        }
-        else
-        {
-            this.absPath = ROOT_PATH;
-        }
-    }
-
-    /**
-     * Returns the hashcode for this name.
-     */
-    public int hashCode()
-    {
-        return (getRootURI().hashCode() ^ getPath().hashCode());
-    }
-
-    /**
-     * Determines if this object is equal to another.
-     */
-    public boolean equals(final Object obj)
-    {
+       private final String scheme;
+       private final String absPath;
+       private FileType type;
+
+       // Cached stuff
+       private String uri;
+       private String baseName;
+       private String rootUri;
+       private String extension;
+       private String decodedAbsPath;
+
+       private boolean calculateHashCode = true;
+       private int calculatedHashCode;
+
+       public AbstractFileName(final String scheme,
+                                                       final String absPath, 
FileType type)
+       {
+               this.rootUri = null;
+               this.scheme = scheme;
+               this.type = type;
+               if (absPath != null && absPath.length() > 0)
+               {
+                       if (absPath.length() > 1 && absPath.endsWith("/"))
+                       {
+                               this.absPath = absPath.substring(0, 
absPath.length() - 1);
+                       }
+                       else
+                       {
+                               this.absPath = absPath;
+                       }
+               }
+               else
+               {
+                       this.absPath = ROOT_PATH;
+               }
+       }
+
+       /**
+        * Returns the hashcode for this name.
+        */
+       public int hashCode()
+       {
+               if (calculateHashCode)
+               {
+                       calculatedHashCode = (getRootURI().hashCode() ^ 
getPath().hashCode());
+                       calculateHashCode = false;
+               }
+               return calculatedHashCode;
+       }
+
+       /**
+        * Determines if this object is equal to another.
+        */
+       public boolean equals(final Object obj)
+       {
                if (!(obj instanceof AbstractFileName))
                {
                        return false;
                }
                final AbstractFileName name = (AbstractFileName) obj;
-        return (getRootURI().equals(name.getRootURI()) && 
getPath().equals(name.getPath()));
-    }
+               return (getRootURI().equals(name.getRootURI()) && 
getPath().equals(name.getPath()));
+       }
+
+       /**
+        * Implement Comparable
+        *
+        * @param obj another abstractfilename
+        */
+       public int compareTo(Object obj)
+       {
+               final AbstractFileName name = (AbstractFileName) obj;
+               int ret = getRootURI().compareTo(name.getRootURI());
+               if (ret != 0)
+               {
+                       return ret;
+               }
+
+               // return absPath.compareTo(name.absPath);
+               try
+               {
+                       return 
getPathDecoded().compareTo(name.getPathDecoded());
+               }
+               catch (FileSystemException e)
+               {
+                       throw new RuntimeException(e.getMessage());
+               }
+       }
+
+       /**
+        * Returns the URI of the file.
+        */
+       public String toString()
+       {
+               return getURI();
+       }
+
+       /**
+        * Factory method for creating name instances.
+        */
+       public abstract FileName createName(String absPath, FileType type);
+
+       /**
+        * 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, boolean 
addPassword);
+
+       /**
+        * Returns the base name of the file.
+        */
+       public String getBaseName()
+       {
+               if (baseName == null)
+               {
+                       final int idx = getPath().lastIndexOf(SEPARATOR_CHAR);
+                       if (idx == -1)
+                       {
+                               baseName = getPath();
+                       }
+                       else
+                       {
+                               baseName = getPath().substring(idx + 1);
+                       }
+               }
+
+               return baseName;
+       }
+
+       /**
+        * Returns the absolute path of the file, relative to the root of the
+        * file system that the file belongs to.
+        */
+       public String getPath()
+       {
+               if (VFS.isUriStyle())
+               {
+                       return absPath + getUriTrailer();
+               }
+               return absPath;
+       }
+
+       protected String getUriTrailer()
+       {
+               return getType().hasChildren() ? "/" : "";
+       }
+
+       public String getPathDecoded() throws FileSystemException
+       {
+               if (decodedAbsPath == null)
+               {
+                       decodedAbsPath = UriParser.decode(getPath());
+               }
+
+               return decodedAbsPath;
+       }
+
+       /**
+        * Returns the name of the parent of the file.
+        */
+       public FileName getParent()
+       {
+               final String parentPath;
+               final int idx = getPath().lastIndexOf(SEPARATOR_CHAR);
+               if (idx == -1 || idx == getPath().length() - 1)
+               {
+                       // No parent
+                       return null;
+               }
+               else if (idx == 0)
+               {
+                       // Root is the parent
+                       parentPath = SEPARATOR;
+               }
+               else
+               {
+                       parentPath = getPath().substring(0, idx);
+               }
+               return createName(parentPath, FileType.FOLDER);
+       }
+
+       /**
+        * find the root of the filesystem
+        */
+       public FileName getRoot()
+       {
+               FileName root = this;
+               while (root.getParent() != null)
+               {
+                       root = root.getParent();
+               }
+
+               return root;
+       }
+
+       /**
+        * Returns the URI scheme of this file.
+        */
+       public String getScheme()
+       {
+               return scheme;
+       }
+
+       /**
+        * Returns the absolute URI of the file.
+        */
+       public String getURI()
+       {
+               if (uri == null)
+               {
+                       uri = createURI();
+               }
+               return uri;
+       }
+
+       protected String createURI()
+       {
+               final StringBuffer buffer = new StringBuffer();
+               appendRootUri(buffer, true);
+               buffer.append(getPath());
+               return buffer.toString();
+       }
+
+       /**
+        * Converts a file name to a relative name, relative to this file name.
+        */
+       public String getRelativeName(final FileName name) throws 
FileSystemException
+       {
+               final String path = name.getPath();
+
+               // Calculate the common prefix
+               final int basePathLen = getPath().length();
+               final int pathLen = path.length();
+
+               // Deal with root
+               if (basePathLen == 1 && pathLen == 1)
+               {
+                       return ".";
+               }
+               else if (basePathLen == 1)
+               {
+                       return path.substring(1);
+               }
+
+               final int maxlen = Math.min(basePathLen, pathLen);
+               int pos = 0;
+               for (; pos < maxlen && getPath().charAt(pos) == 
path.charAt(pos); pos++)
+               {
+               }
+
+               if (pos == basePathLen && pos == pathLen)
+               {
+                       // Same names
+                       return ".";
+               }
+               else if (pos == basePathLen && pos < pathLen && 
path.charAt(pos) == SEPARATOR_CHAR)
+               {
+                       // A descendent of the base path
+                       return path.substring(pos + 1);
+               }
+
+               // Strip the common prefix off the path
+               final StringBuffer buffer = new StringBuffer();
+               if (pathLen > 1 && (pos < pathLen || getPath().charAt(pos) != 
SEPARATOR_CHAR))
+               {
+                       // Not a direct ancestor, need to back up
+                       pos = getPath().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 = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
+               while (pos != -1)
+               {
+                       buffer.insert(0, "../");
+                       pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
+               }
+
+               return buffer.toString();
+       }
+
+       /**
+        * Returns the root URI of the file system this file belongs to.
+        */
+       public String getRootURI()
+       {
+               if (rootUri == null)
+               {
+                       final StringBuffer buffer = new StringBuffer();
+                       appendRootUri(buffer, true);
+                       buffer.append(SEPARATOR_CHAR);
+                       rootUri = buffer.toString().intern();
+               }
+               return rootUri;
+       }
+
+       /**
+        * Returns the depth of this file name, within its file system.
+        */
+       public int getDepth()
+       {
+               final int len = getPath().length();
+               if (len == 0 || (len == 1 && getPath().charAt(0) == 
SEPARATOR_CHAR))
+               {
+                       return 0;
+               }
+               int depth = 1;
+               for (int pos = 0; pos > -1 && pos < len; depth++)
+               {
+                       pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
+               }
+               return depth;
+       }
+
+       /**
+        * Returns the extension of this file name.
+        */
+       public String getExtension()
+       {
+               if (extension == null)
+               {
+                       getBaseName();
+                       final int pos = baseName.lastIndexOf('.');
+                       // if ((pos == -1) || (pos == baseName.length() - 1))
+                       // [EMAIL PROTECTED]: Review of patch from [EMAIL 
PROTECTED]
+                       // do not treat filenames like
+                       // .bashrc c:\windows\.java c:\windows\.javaws 
c:\windows\.jedit c:\windows\.appletviewer
+                       // as extension
+                       if ((pos < 1) || (pos == baseName.length() - 1))
+                       {
+                               // No extension
+                               extension = "";
+                       }
+                       else
+                       {
+                               extension = baseName.substring(pos + 
1).intern();
+                       }
+               }
+               return extension;
+       }
+
+       /**
+        * Determines if another file name is an ancestor of this file name.
+        */
+       public boolean isAncestor(final FileName ancestor)
+       {
+               if (!ancestor.getRootURI().equals(getRootURI()))
+               {
+                       return false;
+               }
+               return checkName(ancestor.getPath(), getPath(), 
NameScope.DESCENDENT);
+       }
+
+       /**
+        * Determines if another file name is a descendent of this file name.
+        */
+       public boolean isDescendent(final FileName descendent)
+       {
+               return isDescendent(descendent, NameScope.DESCENDENT);
+       }
+
+       /**
+        * Determines if another file name is a descendent of this file name.
+        */
+       public boolean isDescendent(final FileName descendent,
+                                                               final NameScope 
scope)
+       {
+               if (!descendent.getRootURI().equals(getRootURI()))
+               {
+                       return false;
+               }
+               return checkName(getPath(), descendent.getPath(), scope);
+       }
+
+       /**
+        * Returns the requested or current type of this name. <br />
+        * <p/>
+        * The "requested" type is the one determined during resolving the 
name. <br/>
+        * In this case the name is a [EMAIL PROTECTED] FileType#FOLDER} if it 
ends with an "/" else
+        * it will be a [EMAIL PROTECTED] FileType#FILE}<br/>
+        * </p>
+        * <p/>
+        * Once attached it will be changed to reflect the real type of this 
resource.
+        * </p>
+        *
+        * @return [EMAIL PROTECTED] FileType#FOLDER} or [EMAIL PROTECTED] 
FileType#FILE}
+        */
+       public FileType getType()
+       {
+               return type;
+       }
+
+       /**
+        * sets the type of this file e.g. when it will be attached.
+        *
+        * @param type [EMAIL PROTECTED] FileType#FOLDER} or [EMAIL PROTECTED] 
FileType#FILE}
+        */
+       void setType(FileType type) throws FileSystemException
+       {
+               if (type != FileType.FOLDER && type != FileType.FILE && type != 
FileType.FILE_OR_FOLDER)
+               {
+                       throw new 
FileSystemException("vfs.provider/filename-type.error");
+               }
+
+               this.type = type;
+       }
+
+       /**
+        * Checks whether a path fits in a particular scope of another path.
+        *
+        * @param basePath An absolute, normalised path.
+        * @param path   An absolute, normalised path.
+        */
+       public static boolean checkName(final String basePath,
+                                                                       final 
String path,
+                                                                       final 
NameScope scope)
+       {
+               if (scope == NameScope.FILE_SYSTEM)
+               {
+                       // All good
+                       return true;
+               }
+
+               if (!path.startsWith(basePath))
+               {
+                       return false;
+               }
+
+               int baseLen = basePath.length();
+               if (VFS.isUriStyle())
+               {
+                       // strip the trailing "/"
+                       baseLen--;
+               }
+
+               if (scope == NameScope.CHILD)
+               {
+                       if (path.length() == baseLen
+                               || (baseLen > 1 && path.charAt(baseLen) != 
SEPARATOR_CHAR)
+                               || path.indexOf(SEPARATOR_CHAR, baseLen + 1) != 
-1)
+                       {
+                               return false;
+                       }
+               }
+               else if (scope == NameScope.DESCENDENT)
+               {
+                       if (path.length() == baseLen
+                               || (baseLen > 1 && path.charAt(baseLen) != 
SEPARATOR_CHAR))
+                       {
+                               return false;
+                       }
+               }
+               else if (scope == NameScope.DESCENDENT_OR_SELF)
+               {
+                       if (baseLen > 1
+                               && path.length() > baseLen
+                               && path.charAt(baseLen) != SEPARATOR_CHAR)
+                       {
+                               return false;
+                       }
+               }
+               else if (scope != NameScope.FILE_SYSTEM)
+               {
+                       throw new IllegalArgumentException();
+               }
+
+               return true;
+       }
 
-    /**
-     * Implement Comparable
-     *
-     * @param obj another abstractfilename
-     */
-    public int compareTo(Object obj)
-    {
-        final AbstractFileName name = (AbstractFileName) obj;
-        int ret = getRootURI().compareTo(name.getRootURI());
-        if (ret != 0)
-        {
-            return ret;
-        }
-
-        // return absPath.compareTo(name.absPath);
-        try
-        {
-            return getPathDecoded().compareTo(name.getPathDecoded());
-        }
-        catch (FileSystemException e)
-        {
-            throw new RuntimeException(e.getMessage());
-        }
-    }
-
-    /**
-     * Returns the URI of the file.
-     */
-    public String toString()
-    {
-        return getURI();
-    }
-
-    /**
-     * Factory method for creating name instances.
-     */
-    public abstract FileName createName(String absPath, FileType type);
-
-    /**
-     * 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, boolean 
addPassword);
-
-    /**
-     * Returns the base name of the file.
-     */
-    public String getBaseName()
-    {
-        if (baseName == null)
-        {
-            final int idx = getPath().lastIndexOf(SEPARATOR_CHAR);
-            if (idx == -1)
-            {
-                baseName = getPath();
-            }
-            else
-            {
-                baseName = getPath().substring(idx + 1);
-            }
-        }
-
-        return baseName;
-    }
-
-    /**
-     * Returns the absolute path of the file, relative to the root of the
-     * file system that the file belongs to.
-     */
-    public String getPath()
-    {
-        if (VFS.isUriStyle())
-        {
-            return absPath + getUriTrailer();
-        }
-        return absPath;
-    }
-
-    protected String getUriTrailer()
-    {
-        return getType().hasChildren() ? "/" : "";
-    }
-
-    public String getPathDecoded() throws FileSystemException
-    {
-        if (decodedAbsPath == null)
-        {
-            decodedAbsPath = UriParser.decode(getPath());
-        }
-
-        return decodedAbsPath;
-    }
-
-    /**
-     * Returns the name of the parent of the file.
-     */
-    public FileName getParent()
-    {
-        final String parentPath;
-        final int idx = getPath().lastIndexOf(SEPARATOR_CHAR);
-        if (idx == -1 || idx == getPath().length() - 1)
-        {
-            // No parent
-            return null;
-        }
-        else if (idx == 0)
-        {
-            // Root is the parent
-            parentPath = SEPARATOR;
-        }
-        else
-        {
-            parentPath = getPath().substring(0, idx);
-        }
-        return createName(parentPath, FileType.FOLDER);
-    }
-
-    /**
-     * find the root of the filesystem
-     */
-    public FileName getRoot()
-    {
-        FileName root = this;
-        while (root.getParent() != null)
-        {
-            root = root.getParent();
-        }
-
-        return root;
-    }
-
-    /**
-     * Returns the URI scheme of this file.
-     */
-    public String getScheme()
-    {
-        return scheme;
-    }
-
-    /**
-     * Returns the absolute URI of the file.
-     */
-    public String getURI()
-    {
-        if (uri == null)
-        {
-            uri = createURI();
-        }
-        return uri;
-    }
-
-    protected String createURI()
-    {
-        final StringBuffer buffer = new StringBuffer();
-        appendRootUri(buffer, true);
-        buffer.append(getPath());
-        return buffer.toString();
-    }
-
-    /**
-     * Converts a file name to a relative name, relative to this file name.
-     */
-    public String getRelativeName(final FileName name) throws 
FileSystemException
-    {
-        final String path = name.getPath();
-
-        // Calculate the common prefix
-        final int basePathLen = getPath().length();
-        final int pathLen = path.length();
-
-        // Deal with root
-        if (basePathLen == 1 && pathLen == 1)
-        {
-            return ".";
-        }
-        else if (basePathLen == 1)
-        {
-            return path.substring(1);
-        }
-
-        final int maxlen = Math.min(basePathLen, pathLen);
-        int pos = 0;
-        for (; pos < maxlen && getPath().charAt(pos) == path.charAt(pos); 
pos++)
-        {
-        }
-
-        if (pos == basePathLen && pos == pathLen)
-        {
-            // Same names
-            return ".";
-        }
-        else if (pos == basePathLen && pos < pathLen && path.charAt(pos) == 
SEPARATOR_CHAR)
-        {
-            // A descendent of the base path
-            return path.substring(pos + 1);
-        }
-
-        // Strip the common prefix off the path
-        final StringBuffer buffer = new StringBuffer();
-        if (pathLen > 1 && (pos < pathLen || getPath().charAt(pos) != 
SEPARATOR_CHAR))
-        {
-            // Not a direct ancestor, need to back up
-            pos = getPath().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 = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
-        while (pos != -1)
-        {
-            buffer.insert(0, "../");
-            pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
-        }
-
-        return buffer.toString();
-    }
-
-    /**
-     * Returns the root URI of the file system this file belongs to.
-     */
-    public String getRootURI()
-    {
-        if (rootUri == null)
-        {
-            final StringBuffer buffer = new StringBuffer();
-            appendRootUri(buffer, true);
-            buffer.append(SEPARATOR_CHAR);
-            rootUri = buffer.toString().intern();
-        }
-        return rootUri;
-    }
-
-    /**
-     * Returns the depth of this file name, within its file system.
-     */
-    public int getDepth()
-    {
-        final int len = getPath().length();
-        if (len == 0 || (len == 1 && getPath().charAt(0) == SEPARATOR_CHAR))
-        {
-            return 0;
-        }
-        int depth = 1;
-        for (int pos = 0; pos > -1 && pos < len; depth++)
-        {
-            pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
-        }
-        return depth;
-    }
-
-    /**
-     * Returns the extension of this file name.
-     */
-    public String getExtension()
-    {
-        if (extension == null)
-        {
-            getBaseName();
-            final int pos = baseName.lastIndexOf('.');
-            // if ((pos == -1) || (pos == baseName.length() - 1))
-            // [EMAIL PROTECTED]: Review of patch from [EMAIL PROTECTED]
-            // do not treat filenames like
-            // .bashrc c:\windows\.java c:\windows\.javaws c:\windows\.jedit 
c:\windows\.appletviewer
-            // as extension
-            if ((pos < 1) || (pos == baseName.length() - 1))
-            {
-                // No extension
-                extension = "";
-            }
-            else
-            {
-                extension = baseName.substring(pos + 1).intern();
-            }
-        }
-        return extension;
-    }
-
-    /**
-     * Determines if another file name is an ancestor of this file name.
-     */
-    public boolean isAncestor(final FileName ancestor)
-    {
-        if (!ancestor.getRootURI().equals(getRootURI()))
-        {
-            return false;
-        }
-        return checkName(ancestor.getPath(), getPath(), NameScope.DESCENDENT);
-    }
-
-    /**
-     * Determines if another file name is a descendent of this file name.
-     */
-    public boolean isDescendent(final FileName descendent)
-    {
-        return isDescendent(descendent, NameScope.DESCENDENT);
-    }
-
-    /**
-     * Determines if another file name is a descendent of this file name.
-     */
-    public boolean isDescendent(final FileName descendent,
-                                final NameScope scope)
-    {
-        if (!descendent.getRootURI().equals(getRootURI()))
-        {
-            return false;
-        }
-        return checkName(getPath(), descendent.getPath(), scope);
-    }
-
-    /**
-     * Returns the requested or current type of this name. <br />
-     * <p/>
-     * The "requested" type is the one determined during resolving the name. 
<br/>
-     * In this case the name is a [EMAIL PROTECTED] FileType#FOLDER} if it 
ends with an "/" else
-     * it will be a [EMAIL PROTECTED] FileType#FILE}<br/>
-     * </p>
-     * <p/>
-     * Once attached it will be changed to reflect the real type of this 
resource.
-     * </p>
-     *
-     * @return [EMAIL PROTECTED] FileType#FOLDER} or [EMAIL PROTECTED] 
FileType#FILE}
-     */
-    public FileType getType()
-    {
-        return type;
-    }
-
-    /**
-     * sets the type of this file e.g. when it will be attached.
-     *
-     * @param type [EMAIL PROTECTED] FileType#FOLDER} or [EMAIL PROTECTED] 
FileType#FILE}
-     */
-    void setType(FileType type) throws FileSystemException
-    {
-        if (type != FileType.FOLDER && type != FileType.FILE && type != 
FileType.FILE_OR_FOLDER)
-        {
-            throw new FileSystemException("vfs.provider/filename-type.error");
-        }
-
-        this.type = type;
-    }
-
-    /**
-     * Checks whether a path fits in a particular scope of another path.
-     *
-     * @param basePath An absolute, normalised path.
-     * @param path     An absolute, normalised path.
-     */
-    public static boolean checkName(final String basePath,
-                                    final String path,
-                                    final NameScope scope)
-    {
-        if (scope == NameScope.FILE_SYSTEM)
-        {
-            // All good
-            return true;
-        }
-
-        if (!path.startsWith(basePath))
-        {
-            return false;
-        }
-
-        int baseLen = basePath.length();
-        if (VFS.isUriStyle())
-        {
-            // strip the trailing "/"
-            baseLen--;
-        }
-
-        if (scope == NameScope.CHILD)
-        {
-            if (path.length() == baseLen
-                || (baseLen > 1 && path.charAt(baseLen) != SEPARATOR_CHAR)
-                || path.indexOf(SEPARATOR_CHAR, baseLen + 1) != -1)
-            {
-                return false;
-            }
-        }
-        else if (scope == NameScope.DESCENDENT)
-        {
-            if (path.length() == baseLen
-                || (baseLen > 1 && path.charAt(baseLen) != SEPARATOR_CHAR))
-            {
-                return false;
-            }
-        }
-        else if (scope == NameScope.DESCENDENT_OR_SELF)
-        {
-            if (baseLen > 1
-                && path.length() > baseLen
-                && path.charAt(baseLen) != SEPARATOR_CHAR)
-            {
-                return false;
-            }
-        }
-        else if (scope != NameScope.FILE_SYSTEM)
-        {
-            throw new IllegalArgumentException();
-        }
-
-        return true;
-    }
-
-    /**
-     * returns a "friendly path", this is a path without a password.
-     */
-    public String getFriendlyURI()
-    {
-        final StringBuffer buffer = new StringBuffer();
-        appendRootUri(buffer, false);
-        buffer.append(getPath());
-        return buffer.toString();
-    }
+       /**
+        * returns a "friendly path", this is a path without a password.
+        */
+       public String getFriendlyURI()
+       {
+               final StringBuffer buffer = new StringBuffer();
+               appendRootUri(buffer, false);
+               buffer.append(getPath());
+               return buffer.toString();
+       }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to