org.apache.commons.vfs.provider
Class AbstractFileName

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

public abstract class AbstractFileName
extends Object
implements FileName

A default file name implementation.

Version:
$Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
Author:
Adam Murdoch

Field Summary
 
Fields inherited from interface org.apache.commons.vfs.FileName
ROOT_PATH, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
AbstractFileName(String scheme, String absPath, FileType type)
           
 
Method Summary
protected abstract  void appendRootUri(StringBuffer buffer, boolean addPassword)
          Builds the root URI for this file name.
static boolean checkName(String basePath, String path, NameScope scope)
          Checks whether a path fits in a particular scope of another path.
 int compareTo(Object obj)
          Implement Comparable
abstract  FileName createName(String absPath, FileType type)
          Factory method for creating name instances.
protected  String createURI()
           
 boolean equals(Object obj)
          Determines if this object is equal to another.
 String getBaseName()
          Returns the base name of the file.
 int getDepth()
          Returns the depth of this file name, within its file system.
 String getExtension()
          Returns the extension of this file name.
 String getFriendlyURI()
          returns a "friendly path", this is a path without a password.
 FileName getParent()
          Returns the name of the parent of the file.
 String getPath()
          Returns the absolute path of the file, relative to the root of the file system that the file belongs to.
 String getPathDecoded()
          Returns the absolute path of this file, within its file system.
 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
 String getRootURI()
          Returns the root URI of the file system this file belongs to.
 String getScheme()
          Returns the URI scheme of this file.
 FileType getType()
          Returns the requested or current type of this name.
 String getURI()
          Returns the absolute URI of the file.
protected  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.
 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(String scheme,
                        String absPath,
                        FileType type)
Method Detail

hashCode

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


equals

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


compareTo

public int compareTo(Object obj)
Implement Comparable

Specified by:
compareTo in interface Comparable
Parameters:
obj - another abstractfilename

toString

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


createName

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


appendRootUri

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


getBaseName

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

Specified by:
getBaseName in interface FileName
Returns:
The base name. Never returns null.

getPath

public 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. Never returns null.

getUriTrailer

protected String getUriTrailer()

getPathDecoded

public String getPathDecoded()
                      throws FileSystemException
Description copied from interface: FileName
Returns the absolute path of this file, within its file system. This path is normalised, so that . and .. elements have been removed. Also, the path only contains / as its separator character. The path always starts with /

The root of a file system has / as its absolute path.

In contrast to FileName.getPath() the path is decoded i.e. all %nn stuff replaced by its character.

Specified by:
getPathDecoded in interface FileName
Returns:
The path. Never returns null.
Throws:
FileSystemException - if the path is not correctly encoded

getParent

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

Specified by:
getParent in interface FileName
Returns:
A FileName object representing the parent name. Returns null for the root of a file system.

getRoot

public FileName getRoot()
find the root of the filesystem

Specified by:
getRoot in interface FileName

getScheme

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

Specified by:
getScheme in interface FileName

getURI

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

Specified by:
getURI in interface FileName

createURI

protected String createURI()

getRelativeName

public 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 name to convert to a relative path.
Returns:
The relative name.
Throws:
FileSystemException - On error.

getRootURI

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

Specified by:
getRootURI in interface FileName

getDepth

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

Specified by:
getDepth in interface FileName

getExtension

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

Specified by:
getExtension in interface FileName
Returns:
The extension. Returns an empty string if the name has no 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

isDescendent

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

Specified by:
isDescendent in interface FileName

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

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(String basePath,
                                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.

getFriendlyURI

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

Specified by:
getFriendlyURI in interface FileName


Copyright © 2002-2006 The Apache Software Foundation. All Rights Reserved.