public class PathTool
extends java.lang.Object
Constructor and Description |
---|
PathTool() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
buildRelativePath(java.lang.String toPath,
java.lang.String fromPath,
char separatorChar) |
static java.lang.String |
calculateLink(java.lang.String link,
java.lang.String relativePath)
Calculates the appropriate link given the preferred link and the relativePath of the document.
|
private static java.lang.String |
determineRelativePath(java.lang.String filename,
java.lang.String separator)
Determines the relative path of a filename.
|
private static java.lang.String |
determineSeparator(java.lang.String filename)
Helper method to determine the file separator (forward or backward slash) used in a filename.
|
static java.lang.String |
getDirectoryComponent(java.lang.String filename)
Determines the directory component of a filename.
|
static java.lang.String |
getRelativeFilePath(java.lang.String oldPath,
java.lang.String newPath)
This method can calculate the relative path between two paths on a file system.
|
static java.lang.String |
getRelativePath(java.lang.String filename)
Determines the relative path of a filename.
|
static java.lang.String |
getRelativePath(java.lang.String basedir,
java.lang.String filename)
Determines the relative path of a filename from a base directory.
|
static java.lang.String |
getRelativeWebPath(java.lang.String oldPath,
java.lang.String newPath)
This method can calculate the relative path between two paths on a web site.
|
(package private) static java.lang.String |
uppercaseDrive(java.lang.String path)
Cygwin prefers lowercase drive letters, but other parts of maven use uppercase
|
public static final java.lang.String getRelativePath(java.lang.String basedir, java.lang.String filename)
$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/" ) = ""
basedir
- The base directory.filename
- The filename that is relative to the base directory.basedir
is null or zero-length, or filename
is null or zero-length.public static final java.lang.String getRelativePath(java.lang.String filename)
$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.filename
- The filename to be parsed.filename
is null or zero-length.getRelativeFilePath(String, String)
public static final java.lang.String getDirectoryComponent(java.lang.String filename)
$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"
filename
- The filename to be parsed.filename
. If the filename does not contain a directory
component, "." is returned.public static final java.lang.String calculateLink(java.lang.String link, java.lang.String relativePath)
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"
link
- relativePath
- public static final java.lang.String getRelativeWebPath(java.lang.String oldPath, java.lang.String newPath)
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/" = "../../"
oldPath
- newPath
- oldPath
.public static final java.lang.String getRelativeFilePath(java.lang.String oldPath, java.lang.String newPath)
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.oldPath
- newPath
- oldPath
.private static final java.lang.String determineRelativePath(java.lang.String filename, java.lang.String separator)
filename
- The filename to parse.separator
- The separator used within the filename.private static final java.lang.String determineSeparator(java.lang.String filename)
filename
- The filename parsed to determine the file separator.filename
. This value is either a forward or backward slash.static final java.lang.String uppercaseDrive(java.lang.String path)
path
- private static final java.lang.String buildRelativePath(java.lang.String toPath, java.lang.String fromPath, char separatorChar)