org.apache.commons.vfs.provider
Class AbstractFileName

java.lang.Object
  extended by org.apache.commons.vfs.provider.AbstractFileName
All Implemented Interfaces:
java.lang.Comparable, FileName
Direct Known Subclasses:
GenericFileName, LayeredFileName, LocalFileName, VirtualFileName

public abstract class AbstractFileName
extends java.lang.Object
implements FileName

A default file name implementation.

Version:
$Revision: 804548 $ $Date: 2009-08-16 04:12:32 +0200 (So, 16. Aug 2009) $
Author:
Adam Murdoch

Field Summary
 
Fields inherited from interface org.apache.commons.vfs.FileName
ROOT_PATH, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
AbstractFileName(java.lang.String scheme, java.lang.String absPath, FileType type)
           
 
Method Summary
protected abstract  void appendRootUri(java.lang.StringBuffer buffer, boolean addPassword)
          Builds the root URI for this file name.
static boolean checkName(java.lang.String basePath, java.lang.String path, NameScope scope)
          Checks whether a path fits in a particular scope of another path.
 int compareTo(java.lang.Object obj)
          Implement Comparable.
abstract  FileName createName(java.lang.String absPath, FileType type)
          Factory method for creating name instances.
protected  java.lang.String createURI()
           
 boolean equals(java.lang.Object obj)
          Determines if this object is equal to another.
 java.lang.String getBaseName()
          Returns the base name of the file.
 int getDepth()
          Returns the depth of this file name, within its file system.
 java.lang.String getExtension()
          Returns the extension of this file name.
 java.lang.String getFriendlyURI()
          returns a "friendly path", this is a path without a password.
 FileName getParent()
          Returns the name of the parent of the file.
 java.lang.String getPath()
          Returns the absolute path of the file, relative to the root of the file system that the file belongs to.
 java.lang.String getPathDecoded()
          Returns the decoded path.
 java.lang.String getRelativeName(FileName name)
          Converts a file name to a relative name, relative to this file name.
 FileName getRoot()
          find the root of the filesystem.
 java.lang.String getRootURI()
          Returns the root URI of the file system this file belongs to.
 java.lang.String getScheme()
          Returns the URI scheme of this file.
 FileType getType()
          Returns the requested or current type of this name.
 java.lang.String getURI()
          Returns the absolute URI of the file.
protected  java.lang.String getUriTrailer()
           
 int hashCode()
          Returns the hashcode for this name.
 boolean isAncestor(FileName ancestor)
          Determines if another file name is an ancestor of this file name.
 boolean isDescendent(FileName descendent)
          Determines if another file name is a descendent of this file name.
 boolean isDescendent(FileName descendent, NameScope scope)
          Determines if another file name is a descendent of this file name.
 java.lang.String toString()
          Returns the URI of the file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractFileName

public AbstractFileName(java.lang.String scheme,
                        java.lang.String absPath,
                        FileType type)
Method Detail

hashCode

public int hashCode()
Returns the hashcode for this name.

Overrides:
hashCode in class java.lang.Object
Returns:
The hashCode.

equals

public boolean equals(java.lang.Object obj)
Determines if this object is equal to another.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare.
Returns:
true if equal, false if not.

compareTo

public int compareTo(java.lang.Object obj)
Implement Comparable.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - another abstractfilename
Returns:
negative number if less than, 0 if equal, postive if greater than.

toString

public java.lang.String toString()
Returns the URI of the file.

Overrides:
toString in class java.lang.Object
Returns:
the FileName as a URI.

createName

public abstract FileName createName(java.lang.String absPath,
                                    FileType type)
Factory method for creating name instances.

Parameters:
absPath - The absolute path.
type - The FileType.
Returns:
The FileName.

appendRootUri

protected abstract void appendRootUri(java.lang.StringBuffer buffer,
                                      boolean addPassword)
Builds the root URI for this file name. Note that the root URI must not end with a separator character.

Parameters:
buffer - A StringBuffer to use to construct the URI.
addPassword - true if the password should be added, false otherwise.

getBaseName

public java.lang.String getBaseName()
Returns the base name of the file.

Specified by:
getBaseName in interface FileName
Returns:
The base name of the file.

getPath

public java.lang.String getPath()
Returns the absolute path of the file, relative to the root of the file system that the file belongs to.

Specified by:
getPath in interface FileName
Returns:
The path String.

getUriTrailer

protected java.lang.String getUriTrailer()

getPathDecoded

public java.lang.String getPathDecoded()
                                throws FileSystemException
Returns the decoded path.

Specified by:
getPathDecoded in interface FileName
Returns:
The decoded path String.
Throws:
FileSystemException - If an error occurs.

getParent

public FileName getParent()
Returns the name of the parent of the file.

Specified by:
getParent in interface FileName
Returns:
the FileName of the parent.

getRoot

public FileName getRoot()
find the root of the filesystem.

Specified by:
getRoot in interface FileName
Returns:
The root FileName.

getScheme

public java.lang.String getScheme()
Returns the URI scheme of this file.

Specified by:
getScheme in interface FileName
Returns:
The protocol used to access the file.

getURI

public java.lang.String getURI()
Returns the absolute URI of the file.

Specified by:
getURI in interface FileName
Returns:
The absolute URI of the file.

createURI

protected java.lang.String createURI()

getRelativeName

public java.lang.String getRelativeName(FileName name)
                                 throws FileSystemException
Converts a file name to a relative name, relative to this file name.

Specified by:
getRelativeName in interface FileName
Parameters:
name - The FileName.
Returns:
The relative path to the file.
Throws:
FileSystemException - if an error occurs.

getRootURI

public java.lang.String getRootURI()
Returns the root URI of the file system this file belongs to.

Specified by:
getRootURI in interface FileName
Returns:
The URI of the root.

getDepth

public int getDepth()
Returns the depth of this file name, within its file system.

Specified by:
getDepth in interface FileName
Returns:
The depth of the file name.

getExtension

public java.lang.String getExtension()
Returns the extension of this file name.

Specified by:
getExtension in interface FileName
Returns:
The file extension.

isAncestor

public boolean isAncestor(FileName ancestor)
Determines if another file name is an ancestor of this file name.

Specified by:
isAncestor in interface FileName
Parameters:
ancestor - The FileName to check.
Returns:
true if the FileName is an ancestor, false otherwise.

isDescendent

public boolean isDescendent(FileName descendent)
Determines if another file name is a descendent of this file name.

Specified by:
isDescendent in interface FileName
Parameters:
descendent - The FileName to check.
Returns:
true if the FileName is a descendent, false otherwise.

isDescendent

public boolean isDescendent(FileName descendent,
                            NameScope scope)
Determines if another file name is a descendent of this file name.

Specified by:
isDescendent in interface FileName
Parameters:
descendent - The FileName to check.
scope - The NameScope.
Returns:
true if the FileName is a descendent, false otherwise.

getType

public FileType getType()
Returns the requested or current type of this name.

The "requested" type is the one determined during resolving the name.
In this case the name is a FileType.FOLDER if it ends with an "/" else it will be a FileType.FILE

Once attached it will be changed to reflect the real type of this resource.

Specified by:
getType in interface FileName
Returns:
FileType.FOLDER or FileType.FILE

checkName

public static boolean checkName(java.lang.String basePath,
                                java.lang.String path,
                                NameScope scope)
Checks whether a path fits in a particular scope of another path.

Parameters:
basePath - An absolute, normalised path.
path - An absolute, normalised path.
scope - The NameScope.
Returns:
true if the path fits in the scope, false otherwise.

getFriendlyURI

public java.lang.String getFriendlyURI()
returns a "friendly path", this is a path without a password.

Specified by:
getFriendlyURI in interface FileName
Returns:
The "friendly" URI.


Copyright © 2002-2009 Apache Software Foundation. All Rights Reserved.