org.ibisph.util
Class IOPath

java.lang.Object
  extended by org.ibisph.util.IOPath

public abstract class IOPath
extends java.lang.Object

Abstract library which provides methods for building consistent file and/or URL paths, getting filenames from end of paths, getting file extensions, getting paths from a path and filename string, and for working with a path separator.

Author:
Garth Braithwaite, STG

Constructor Summary
IOPath()
           
 
Method Summary
static java.lang.String concat(java.lang.String leftSide, java.lang.String rightSide)
          Builds a standardized path based on the File.separator.
static java.lang.String concat(java.lang.String leftSide, java.lang.String rightSide, java.lang.String separator)
          Builds a standardized path based on the separator passed in.
static java.lang.String createAdjusted(java.lang.String path, java.lang.String pathType, java.lang.String contextPath)
          Helper that builds a path based on the pathType.
static java.lang.String getFilename(java.lang.String filenameWithPath)
          Gets the filename and extension portion of and path and filename source string.
static java.lang.String getFilenameExtension(java.lang.String filename)
          Gets only the filename extension - all text past the last file extension character.
static java.lang.String getFilenameExtension(java.lang.String filename, java.lang.String defaultExtension)
          Gets only the filename extension - all text past the last file extension character.
static java.lang.String getFilenameWithoutExtension(java.lang.String filenameWithPathAndExtension)
          Gets the filename without any path or extension information.
static java.lang.String getPath(java.lang.String filenameWithPath)
          Gets the path portion of filename.extension and path source string.
static java.lang.String getPathAndFilenameWithoutExtension(java.lang.String filenameWithPathAndExtension)
          Gets the path and filename sans the extension separator and text that follows the extension.
static int indexOfLastExtensionSeparator(java.lang.String filename)
          Gets the last position of the "." filename extension separator.
static int indexOfLastPathSeparator(java.lang.String filename)
          Gets the position of the last path separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOPath

public IOPath()
Method Detail

concat

public static java.lang.String concat(java.lang.String leftSide,
                                      java.lang.String rightSide,
                                      java.lang.String separator)
Builds a standardized path based on the separator passed in. If the separator is null, the paths are searched for the "/" character. If found then this is used. If not, the File.separator is used. Before concatenating the paths together, the strings are trimmed of white space then joined together using the separator.

Parameters:
leftSide - Optional left side of a path.
rightSide - Optional right side of a path.
separator - Optional path separator to be used to join the left and and right side strings.
Returns:
leftSide + separator + rightSide.

concat

public static java.lang.String concat(java.lang.String leftSide,
                                      java.lang.String rightSide)
Builds a standardized path based on the File.separator.

Parameters:
leftSide - Optional left side of a path.
rightSide - Optional right side of a path.
Returns:
leftSide + File.separator + rightSide.

createAdjusted

public static java.lang.String createAdjusted(java.lang.String path,
                                              java.lang.String pathType,
                                              java.lang.String contextPath)
Helper that builds a path based on the pathType. This method is useful for servlet init parameters and/or beans that use a path type property to specify the type of path to use. Note that this method really is only helpful/used for context based paths.

Parameters:
path - Core path.
pathType - "F" = path is a file type path, "U" = path is a URL type path, "C" = context based path so prefix the path with the supplied contextPath.
contextPath - Optional context path prefix.
Returns:
path as is if "://" found, else if "C"ontext type path then concat the context path with the path, else return the path as is.

indexOfLastPathSeparator

public static int indexOfLastPathSeparator(java.lang.String filename)
Gets the position of the last path separator. Instead of relying on the File.separator, the "/" character is checked first then the "\" character. The reason is that this method is used for both file and URL based paths. URL paths only use th "/" character plus with Java's file system the "/" character works just like the Windows "\" character.

Parameters:
filename - Source string that contains the path/filename to be searched for.
Returns:
String position of the last path separator (string.lastIndexOf).

indexOfLastExtensionSeparator

public static int indexOfLastExtensionSeparator(java.lang.String filename)
Gets the last position of the "." filename extension separator. This basically provides a localized filename extension lastIndexOf.

Parameters:
filename - Source string that contains the path/filename.ext to be searched for.
Returns:
String position of the last file extension separator "." (string.lastIndexOf).

getPath

public static java.lang.String getPath(java.lang.String filenameWithPath)
Gets the path portion of filename.extension and path source string.

Parameters:
filenameWithPath -
Returns:
Source string with everything truncated past the last path separator.

getFilename

public static java.lang.String getFilename(java.lang.String filenameWithPath)
Gets the filename and extension portion of and path and filename source string.

Parameters:
filenameWithPath -
Returns:
Source string with everything truncated to the left of the last path separator.

getPathAndFilenameWithoutExtension

public static java.lang.String getPathAndFilenameWithoutExtension(java.lang.String filenameWithPathAndExtension)
Gets the path and filename sans the extension separator and text that follows the extension.

Parameters:
filenameWithPathAndExtension - Source string that contains the path/filename.ext to be searched.
Returns:
String entire string value up to the last file extension character ".".

getFilenameWithoutExtension

public static java.lang.String getFilenameWithoutExtension(java.lang.String filenameWithPathAndExtension)
Gets the filename without any path or extension information.

Parameters:
filenameWithPathAndExtension - Source text to have path and extension removed from.
Returns:
Source string with all paths and the last extension text removed.

getFilenameExtension

public static java.lang.String getFilenameExtension(java.lang.String filename,
                                                    java.lang.String defaultExtension)
Gets only the filename extension - all text past the last file extension character.

Parameters:
filename - Source text to find the end extension from. This text can have path information.
defaultExtension - Default extension if one is not found in the filename passed in.
Returns:
text to the right of the last extension character.

getFilenameExtension

public static java.lang.String getFilenameExtension(java.lang.String filename)
Gets only the filename extension - all text past the last file extension character.

Parameters:
filename - Source text to find the end extension from. This text can have path information.
Returns:
text to the right of the last extension character.