org.codehaus.plexus.util
public class PathTool extends Object
Version: $Id: PathTool.java 8010 2009-01-07 12:59:50Z vsiveton $
Method Summary | |
---|---|
static String | calculateLink(String link, String relativePath)
Calculates the appropriate link given the preferred link and the relativePath of the document.
|
static String | getDirectoryComponent(String filename)
Determines the directory component of a filename. |
static String | getRelativeFilePath(String oldPath, String newPath)
This method can calculate the relative path between two pathes on a file system.
|
static String | getRelativePath(String basedir, String filename)
Determines the relative path of a filename from a base directory.
|
static String | getRelativePath(String filename)
Determines the relative path of a filename. |
static String | getRelativeWebPath(String oldPath, String newPath)
This method can calculate the relative path between two pathes on a web site.
|
PathTool.calculateLink( "/index.html", "../.." ) = "../../index.html" PathTool.calculateLink( "http://plexus.codehaus.org/plexus-utils/index.html", "../.." ) = "http://plexus.codehaus.org/plexus-utils/index.html" PathTool.calculateLink( "/usr/local/java/bin/java.sh", "../.." ) = "../../usr/local/java/bin/java.sh" PathTool.calculateLink( "../index.html", "/usr/local/java/bin" ) = "/usr/local/java/bin/../index.html" PathTool.calculateLink( "../index.html", "http://plexus.codehaus.org/plexus-utils" ) = "http://plexus.codehaus.org/plexus-utils/../index.html"
Parameters: link relativePath
Returns: String
$context.getAppValue("infilename")
to get the
current directory that is currently being processed.
This method is thread-safe.
PathTool.getDirectoryComponent( null ) = "" PathTool.getDirectoryComponent( "/usr/local/java/bin" ) = "/usr/local/java" PathTool.getDirectoryComponent( "/usr/local/java/bin/" ) = "/usr/local/java/bin" PathTool.getDirectoryComponent( "/usr/local/java/bin/java.sh" ) = "/usr/local/java/bin"
Parameters: filename The filename to be parsed.
Returns: The directory portion of the filename
. If
the filename does not contain a directory component, "." is
returned.
PathTool.getRelativeFilePath( null, null ) = "" PathTool.getRelativeFilePath( null, "/usr/local/java/bin" ) = "" PathTool.getRelativeFilePath( "/usr/local", null ) = "" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) = "../.." PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh" PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.." PathTool.getRelativeFilePath( "/usr/local/", "/bin" ) = "../../bin" PathTool.getRelativeFilePath( "/bin", "/usr/local/" ) = "../usr/local"Note: On Windows based system, the
/
character should be replaced by \
character.
Parameters: oldPath newPath
Returns: a relative file path from oldPath
.
$relativePath
context variable. The arguments to
this method may contain either forward or backward slashes as
file separators. The relative path returned is formed using
forward slashes as it is expected this path is to be used as a
link in a web page (again mimicking Anakia's behavior).
This method is thread-safe.
PathTool.getRelativePath( null, null ) = "" PathTool.getRelativePath( null, "/usr/local/java/bin" ) = "" PathTool.getRelativePath( "/usr/local/", null ) = "" PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin" ) = ".." PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "../.." PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = ""
Parameters: basedir The base directory. filename The filename that is relative to the base directory.
Returns: The relative path of the filename from the base
directory. This value is not terminated with a forward slash.
A zero-length string is returned if: the filename is not relative to
the base directory, basedir
is null or zero-length,
or filename
is null or zero-length.
$relativePath
context variable. The argument to
this method may contain either forward or backward slashes as
file separators. The relative path returned is formed using
forward slashes as it is expected this path is to be used as a
link in a web page (again mimicking Anakia's behavior).
This method is thread-safe.
Parameters: filename The filename to be parsed.
Returns: The relative path of the filename. This value is not
terminated with a forward slash. A zero-length string is
returned if: filename
is null or zero-length.
See Also: PathTool
PathTool.getRelativeWebPath( null, null ) = "" PathTool.getRelativeWebPath( null, "http://plexus.codehaus.org/" ) = "" PathTool.getRelativeWebPath( "http://plexus.codehaus.org/", null ) = "" PathTool.getRelativeWebPath( "http://plexus.codehaus.org/", "http://plexus.codehaus.org/plexus-utils/index.html" ) = "plexus-utils/index.html" PathTool.getRelativeWebPath( "http://plexus.codehaus.org/plexus-utils/index.html", "http://plexus.codehaus.org/" = "../../"
Parameters: oldPath newPath
Returns: a relative web path from oldPath
.