Package org.apache.commons.vfs2.provider
Class AbstractFileName
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileName
-
- Direct Known Subclasses:
GenericFileName
,LayeredFileName
,LocalFileName
,ResourceFileName
,VirtualFileName
public abstract class AbstractFileName extends java.lang.Object implements FileName
A default file name implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
absPath
private java.lang.String
baseName
private java.lang.String
decodedAbsPath
private java.lang.String
extension
private java.lang.String
key
private static char[]
RESERVED_URI_CHARS
private java.lang.String
rootUri
private java.lang.String
scheme
private FileType
type
private java.lang.String
uriString
-
Fields inherited from interface org.apache.commons.vfs2.FileName
EMPTY_ARRAY, ROOT_PATH, SEPARATOR, SEPARATOR_CHAR
-
-
Constructor Summary
Constructors Constructor Description AbstractFileName(java.lang.String scheme, java.lang.String absPath, FileType type)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
appendRootUri(java.lang.StringBuilder 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(FileName obj)
Implement Comparable.abstract FileName
createName(java.lang.String absolutePath, FileType fileType)
Factory method for creating name instances.protected java.lang.String
createURI()
private java.lang.String
createURI(boolean useAbsolutePath, boolean usePassword)
boolean
equals(java.lang.Object o)
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 the URI without a password.private java.lang.String
getKey()
Create a path that does not use the FileType since that field is not immutable.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 file system.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()
private java.lang.String
handleURISpecialCharacters(java.lang.String uri)
int
hashCode()
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.boolean
isFile()
Checks if this file name is a name for a regular file by using its type.(package private) void
setType(FileType type)
Sets the type of this file e.g.java.lang.String
toString()
Returns the URI of the file.
-
-
-
Field Detail
-
RESERVED_URI_CHARS
private static final char[] RESERVED_URI_CHARS
-
scheme
private final java.lang.String scheme
-
absPath
private final java.lang.String absPath
-
type
private FileType type
-
uriString
private java.lang.String uriString
-
baseName
private java.lang.String baseName
-
rootUri
private java.lang.String rootUri
-
extension
private java.lang.String extension
-
decodedAbsPath
private java.lang.String decodedAbsPath
-
key
private java.lang.String key
-
-
Constructor Detail
-
AbstractFileName
public AbstractFileName(java.lang.String scheme, java.lang.String absPath, FileType type)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(FileName obj)
Implement Comparable.- Specified by:
compareTo
in interfacejava.lang.Comparable<FileName>
- Parameters:
obj
- another abstract file name- Returns:
- negative number if less than, 0 if equal, positive if greater than.
-
toString
public java.lang.String toString()
Returns the URI of the file.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the FileName as a URI.
-
createName
public abstract FileName createName(java.lang.String absolutePath, FileType fileType)
Factory method for creating name instances.- Parameters:
absolutePath
- The absolute path.fileType
- The FileType.- Returns:
- The FileName.
-
appendRootUri
protected abstract void appendRootUri(java.lang.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 java.lang.String getBaseName()
Returns the base name of the file.- Specified by:
getBaseName
in interfaceFileName
- 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.
-
getUriTrailer
protected java.lang.String getUriTrailer()
-
getPathDecoded
public java.lang.String getPathDecoded() throws FileSystemException
Returns the decoded path.- Specified by:
getPathDecoded
in interfaceFileName
- Returns:
- The decoded path String.
- Throws:
FileSystemException
- If an error occurs.
-
getParent
public FileName getParent()
Returns the name of the parent of the file.
-
getRoot
public FileName getRoot()
find the root of the file system.
-
getScheme
public java.lang.String getScheme()
Returns the URI scheme of this file.
-
getURI
public java.lang.String getURI()
Returns the absolute URI of the file.
-
createURI
protected java.lang.String createURI()
-
getKey
private java.lang.String getKey()
Create a path that does not use the FileType since that field is not immutable.- Returns:
- The key.
-
getFriendlyURI
public java.lang.String getFriendlyURI()
Returns the URI without a password.- Specified by:
getFriendlyURI
in interfaceFileName
- Returns:
- Returns the URI without a password.
-
createURI
private java.lang.String createURI(boolean useAbsolutePath, boolean usePassword)
-
handleURISpecialCharacters
private java.lang.String handleURISpecialCharacters(java.lang.String uri)
-
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 interfaceFileName
- 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 interfaceFileName
- Returns:
- The URI of the root.
-
getDepth
public int getDepth()
Returns the depth of this file name, within its file system.
-
getExtension
public java.lang.String getExtension()
Returns the extension of this file name.- Specified by:
getExtension
in interfaceFileName
- 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 interfaceFileName
- 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 interfaceFileName
- 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 interfaceFileName
- Parameters:
descendent
- The FileName to check.scope
- The NameScope.- Returns:
- true if the FileName is a descendent, false otherwise.
-
isFile
public boolean isFile() throws FileSystemException
Checks if this file name is a name for a regular file by using its type.- Specified by:
isFile
in interfaceFileName
- Returns:
- true if this file is a regular file.
- Throws:
FileSystemException
- may be thrown by subclasses.- See Also:
getType()
,FileType.FILE
-
getType
public FileType getType()
Returns the requested or current type of this name.The "requested" type is the one determined during resolving the name. n this case the name is a
FileType.FOLDER
if it ends with an "/" else it will be aFileType.FILE
.Once attached it will be changed to reflect the real type of this resource.
- Specified by:
getType
in interfaceFileName
- Returns:
FileType.FOLDER
orFileType.FILE
-
setType
void setType(FileType type) throws FileSystemException
Sets the type of this file e.g. when it will be attached.- Parameters:
type
-FileType.FOLDER
orFileType.FILE
- Throws:
FileSystemException
- if an error occurs.
-
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.
-
-