com.Prominic.jFTPd
Class VirtualFile

java.lang.Object
  extended by com.Prominic.jFTPd.VirtualFile

 class VirtualFile
extends java.lang.Object

This class does the conversion between a virtual file and its corresponding file on disk. As the user sees virtual directories so the FTP commands are based on virtual paths, these paths need to be converted to actual directories for download/uploads to happen. Also, virtual parent directories need to be also computed.

Author:
Iulian

Field Summary
private  java.io.File file
           
private  boolean isWindows
           
private  java.lang.String realPath
           
static java.lang.String root
           
private  java.util.Hashtable virtualDirs
           
private  java.lang.String virtualPath
           
 
Constructor Summary
VirtualFile(java.lang.String virtualPath, java.util.Hashtable virtualDirs)
          Constructs a virtual file, based on the virtual path and the list of virtual directories representing the client's home directories.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Checks if two virtual paths are identical.
 boolean exists()
          Checks if a virtual path exists on disk.
 java.io.File getFileMember()
          Obtains a File object representing the real file on disk.
 java.lang.String getParent()
          Returns a virtual parent for this object.
protected  java.lang.String getRealPath()
          Returns the real path corresponding to a virtual path.
protected  java.lang.String getVirtualPath()
           
 boolean inVirtualRoot()
          Checks if the virtual path is the virtual home directory (virtual root)
 boolean isDirectory()
          Checks if a virtual path represents a directory on disk.
 long lastModified()
          Checks when's the last modified time for a virtual path (in fact the last modified time for actual file represented by the virtual path).
 long length()
           
 java.lang.String[] list()
          Composes the virtual root directory contents (where links to each home directories will be found).
 java.lang.String[] list(WildcardFilter filter)
          Gets a file list based on the given filter.
 java.lang.String replaceSlash(java.lang.String oldPath)
          Path fixups.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

virtualDirs

private java.util.Hashtable virtualDirs

file

private java.io.File file

virtualPath

private java.lang.String virtualPath

realPath

private java.lang.String realPath

isWindows

private boolean isWindows

root

public static java.lang.String root
Constructor Detail

VirtualFile

public VirtualFile(java.lang.String virtualPath,
                   java.util.Hashtable virtualDirs)
Constructs a virtual file, based on the virtual path and the list of virtual directories representing the client's home directories. Creation date: (07-Dec-01 21:31:56)

Parameters:
virtualPath - - virtual path
virtualDirs - - virtual home directories.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Checks if two virtual paths are identical. Follows the recomandations for the equal() method suggested by Sun.

Overrides:
equals in class java.lang.Object
Parameters:
obj - - some virtual path.
Returns:
true - if both objects (this and obj) have the same virtual path, false otherwise.

exists

public boolean exists()
Checks if a virtual path exists on disk.

Returns:
true if the virtual path has a corresponding file/path on disk, false otherwise.

getFileMember

public java.io.File getFileMember()
Obtains a File object representing the real file on disk.

Returns:
File file object to which the virtual file points.

getParent

public java.lang.String getParent()
Returns a virtual parent for this object.

Returns:
- the virtual parent for this virtual path.

getRealPath

protected java.lang.String getRealPath()
Returns the real path corresponding to a virtual path. The first directory in a virtual path is a virtual home directory, and the virtualDirs parameters from the constructor are checked for the real paths of the home dirs. Then the real path is composed.

Returns:
- corresponding real path, or null if something went wrong.

getVirtualPath

protected java.lang.String getVirtualPath()
Returns:
the virtual path.

inVirtualRoot

public boolean inVirtualRoot()
Checks if the virtual path is the virtual home directory (virtual root)

Returns:
true if the parent of the current directory is root (true for root itself and for directories in virtual root.

isDirectory

public boolean isDirectory()
Checks if a virtual path represents a directory on disk.

Returns:
true if the virtual path is a directory on disk. false otherwise.

lastModified

public long lastModified()
Checks when's the last modified time for a virtual path (in fact the last modified time for actual file represented by the virtual path). If file is virtual root, the lastModified will return the current time.

Returns:
- last modified date/time, or System.currentTimeMillis() if virtual path is root.

length

public long length()
Returns:
length of the real path on disk (or 0 if virtual path is root).

list

public java.lang.String[] list()
Composes the virtual root directory contents (where links to each home directories will be found).

Returns:
array of virtual home directories.

list

public java.lang.String[] list(WildcardFilter filter)
Gets a file list based on the given filter.

Parameters:
filter - - filter
Returns:
- array of virtual paths to be returned back to user when it uses the LIST command.

replaceSlash

public java.lang.String replaceSlash(java.lang.String oldPath)
Path fixups. Replaces '\' with '/'.

Parameters:
oldPath - - path to be replaces
Returns:
- new path.