com.borland.primetime.vfs
Class AbstractFilesystem

java.lang.Object
  |
  +--com.borland.primetime.vfs.AbstractFilesystem
Direct Known Subclasses:
FileFilesystem, NewFilesystem, ZipFilesystem

public abstract class AbstractFilesystem
extends java.lang.Object
implements Filesystem

AbstractFilesystem is an abstract class that implementats a subset of the Filesystem interface that should be fairly consistent from one filesystem to the next. Standardized support for hashing, Url comparison and evaluating relative paths is included. The latter may be customized by overriding some or all of getChild, getParent, getAbsoluteUrl, and getRelativeUrl.

See Also:
Filesystem

Fields inherited from interface com.borland.primetime.vfs.Filesystem
TYPE_BOTH, TYPE_DIRECTORY, TYPE_FILE
 
Constructor Summary
AbstractFilesystem()
           
 
Method Summary
 boolean fileEquals(Url url, Url otherUrl)
          Compares the file portion of two Url objects in a case sensitive manner.
 int fileHashCode(Url url)
          Produces a hash value for the file portion of a Url compatible with the definition of equality provided by fileEquals.
protected  Url getAbsoluteUrl(java.lang.String newHost, java.lang.String absoluteFilePath)
          Assists in interpreting a relative path by creating a full Url for a file path if it represents an absolute path.
 Url getCanonicalUrl(Url url)
          Reports the exact Url representation of a resource.
 Url getChild(Url url, java.lang.String subpath)
          Creates a new Url that adds the specified subpath to an existing Url's file path.
 java.io.File getFileObject(Url url)
          Describes a Url in terms of a java.io.File instance.
 java.lang.String getName(Url url)
          Returns a short name for the Url.
 Url getParent(Url url)
          Returns a Url with the last subpath from the supplied Url's file path removed.
 java.lang.String getRelativePath(Url root, Url target, boolean onlyChildren)
          Create a relative path from an root Url to specified target Url.
 Url getRelativeUrl(Url root, java.lang.String relativePath)
          Create a new Url from an existing root Url and a relative component.
 boolean isValid(Url url)
          Determines whether the state of a Url instance is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFilesystem

public AbstractFilesystem()
Method Detail

getAbsoluteUrl

protected Url getAbsoluteUrl(java.lang.String newHost,
                             java.lang.String absoluteFilePath)
Assists in interpreting a relative path by creating a full Url for a file path if it represents an absolute path.
Returns:
The Url defined by the absolute path provided, or null if the path is not actually an absolute path.

getChild

public Url getChild(Url url,
                    java.lang.String subpath)
Creates a new Url that adds the specified subpath to an existing Url's file path. The new Url will typically retain the protocol and host of the existing Url, but will always lose the anchor component.
Specified by:
getChild in interface Filesystem
Parameters:
url - The existing Url.
subpath - The subpath to be added to the Url's file path.
Returns:
The newly created Url.

getParent

public Url getParent(Url url)
Returns a Url with the last subpath from the supplied Url's file path removed. The anchor for the parent Url is always set to null, but the filesystem and protocol are typically inherited from the supplied Url.
Specified by:
getParent in interface Filesystem
Parameters:
url - The Url for which a parent is desired.
Returns:
The Url that serves as a logical parent the the supplied Url, or null if there is no parent Url, such as when the file path contains only a single subpath.

getFileObject

public java.io.File getFileObject(Url url)
Describes a Url in terms of a java.io.File instance. Note that this may not be appropriate for many filesystem types, and will return null in these cases.
Specified by:
getFileObject in interface Filesystem
Parameters:
url - The Url in question.
Returns:
An appropriate File object representation, or null if no equivelant file exists.

getCanonicalUrl

public Url getCanonicalUrl(Url url)
Reports the exact Url representation of a resource. By default this implementation assumes that there are no two equivalent Url representations and returns the original Url unchanged. Subclasses may change this behavior.
Specified by:
getCanonicalUrl in interface Filesystem
Parameters:
url - The Url in question.
Returns:
The canonical representation of the Url, or the original Url if no canonical representation can be determined.

isValid

public boolean isValid(Url url)
Determines whether the state of a Url instance is valid. By default, this only requires that the filesystem/protocol, host, and file are non-null.
Specified by:
isValid in interface Filesystem
Parameters:
url - The Url in question.
Returns:
True if the Url is valid, false otherwise.

fileHashCode

public int fileHashCode(Url url)
Produces a hash value for the file portion of a Url compatible with the definition of equality provided by fileEquals.
Specified by:
fileHashCode in interface Filesystem
Parameters:
url - The Url to produce a hash value based on.
Returns:
The appropriate hash value.

fileEquals

public boolean fileEquals(Url url,
                          Url otherUrl)
Compares the file portion of two Url objects in a case sensitive manner.
Specified by:
fileEquals in interface Filesystem
Parameters:
url - The first of the two Urls to be compared.
otherUrl - The second of the two Urls to be compared.
Returns:
True if the file portions of the two Urls are identical, false otherwise.

getName

public java.lang.String getName(Url url)
Returns a short name for the Url.
Specified by:
getName in interface Filesystem
Returns:
The last subpath in the file portion of the Url.

getRelativeUrl

public Url getRelativeUrl(Url root,
                          java.lang.String relativePath)
Create a new Url from an existing root Url and a relative component. This method doesn't need to process the anchor portion of the relative path since it has already been removed by the VFS.
Specified by:
getRelativeUrl in interface Filesystem
Parameters:
root - The Url root.
relativePath - The relative path from the root.
Returns:
The Url defined by following the relative path from the root Url.

getRelativePath

public java.lang.String getRelativePath(Url root,
                                        Url target,
                                        boolean onlyChildren)
Create a relative path from an root Url to specified target Url. The anchor portions are taken care of by the VFS and are guaranteed to be null in this method.
Specified by:
getRelativePath in interface Filesystem
Parameters:
root - The Url root.
target - The Url target.
onlyChildren - True if the target must be a descendant of the root, false if absolute paths and paths with leading "../" entries should be considered.
Returns:
The relative path to the target Url from this Url, or null if there is no valid path from the root Url to the target Url.