org.apache.commons.vfs2.provider
Class AbstractFileName

java.lang.Object
  extended by org.apache.commons.vfs2.provider.AbstractFileName
All Implemented Interfaces:
Comparable<org.apache.commons.vfs2.FileName>, org.apache.commons.vfs2.FileName

public abstract class AbstractFileName
extends Object
implements org.apache.commons.vfs2.FileName

A default file name implementation. PATCH for : https://issues.apache.org/jira/browse/VFS-178

Author:
Commons VFS team

Field Summary
 
Fields inherited from interface org.apache.commons.vfs2.FileName
ROOT_PATH, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
AbstractFileName(String scheme, String absPath, org.apache.commons.vfs2.FileType type)
           
 
Method Summary
protected abstract  void appendRootUri(StringBuilder buffer, boolean addPassword)
          Builds the root URI for this file name.
static boolean checkName(String basePath, String path, org.apache.commons.vfs2.NameScope scope)
          Checks whether a path fits in a particular scope of another path.
 int compareTo(org.apache.commons.vfs2.FileName obj)
          Implement Comparable.
abstract  org.apache.commons.vfs2.FileName createName(String absPath, org.apache.commons.vfs2.FileType type)
          Factory method for creating name instances.
protected  String createURI()
           
 boolean equals(Object o)
           
 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.
 org.apache.commons.vfs2.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 decoded path.
 String getRelativeName(org.apache.commons.vfs2.FileName name)
          Converts a file name to a relative name, relative to this file name.
 org.apache.commons.vfs2.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.
 org.apache.commons.vfs2.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()
           
 boolean isAncestor(org.apache.commons.vfs2.FileName ancestor)
          Determines if another file name is an ancestor of this file name.
 boolean isDescendent(org.apache.commons.vfs2.FileName descendent)
          Determines if another file name is a descendent of this file name.
 boolean isDescendent(org.apache.commons.vfs2.FileName descendent, org.apache.commons.vfs2.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,
                        org.apache.commons.vfs2.FileType type)
Method Detail

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(org.apache.commons.vfs2.FileName obj)
Implement Comparable.

Specified by:
compareTo in interface Comparable<org.apache.commons.vfs2.FileName>
Parameters:
obj - another abstractfilename
Returns:
negative number if less than, 0 if equal, postive if greater than.

toString

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

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

createName

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

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

appendRootUri

protected abstract void appendRootUri(StringBuilder 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 StringBuilder to use to construct the URI.
addPassword - true if the password should be added, false otherwise.

getBaseName

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

Specified by:
getBaseName in interface org.apache.commons.vfs2.FileName
Returns:
The base name of the file.

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 org.apache.commons.vfs2.FileName
Returns:
The path String.

getUriTrailer

protected String getUriTrailer()

getPathDecoded

public String getPathDecoded()
                      throws org.apache.commons.vfs2.FileSystemException
Returns the decoded path.

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

getParent

public org.apache.commons.vfs2.FileName getParent()
Returns the name of the parent of the file.

Specified by:
getParent in interface org.apache.commons.vfs2.FileName
Returns:
the FileName of the parent.

getRoot

public org.apache.commons.vfs2.FileName getRoot()
find the root of the filesystem.

Specified by:
getRoot in interface org.apache.commons.vfs2.FileName
Returns:
The root FileName.

getScheme

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

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

getURI

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

Specified by:
getURI in interface org.apache.commons.vfs2.FileName
Returns:
The absolute URI of the file.

createURI

protected String createURI()

getFriendlyURI

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

Specified by:
getFriendlyURI in interface org.apache.commons.vfs2.FileName
Returns:
The "friendly" URI.

getRelativeName

public String getRelativeName(org.apache.commons.vfs2.FileName name)
                       throws org.apache.commons.vfs2.FileSystemException
Converts a file name to a relative name, relative to this file name.

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

getRootURI

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

Specified by:
getRootURI in interface org.apache.commons.vfs2.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 org.apache.commons.vfs2.FileName
Returns:
The depth of the file name.

getExtension

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

Specified by:
getExtension in interface org.apache.commons.vfs2.FileName
Returns:
The file extension.

isAncestor

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

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

isDescendent

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

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

isDescendent

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

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

getType

public org.apache.commons.vfs2.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 org.apache.commons.vfs2.FileName
Returns:
FileType.FOLDER or FileType.FILE

checkName

public static boolean checkName(String basePath,
                                String path,
                                org.apache.commons.vfs2.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.


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.