com.mucommander.file.util
Class PathUtils

java.lang.Object
  extended by com.mucommander.file.util.PathUtils

public class PathUtils
extends java.lang.Object

This class contains static helper methods that operate on file paths.

Author:
Maxence Bernard

Nested Class Summary
static class PathUtils.ResolvedDestination
          This class represents a destination entered by the user and resolved by resolveDestination(String, com.mucommander.file.AbstractFile) into an AbstractFile and a destination type.
 
Constructor Summary
PathUtils()
           
 
Method Summary
static java.lang.String removeLeadingSeparator(java.lang.String path)
          Removes any leading separator character (slash or backslash) from the given path and returns the modified path.
static java.lang.String removeLeadingSeparator(java.lang.String path, java.lang.String separator)
          Removes any leading separator character from the given path and returns the modified path.
static java.lang.String removeTrailingSeparator(java.lang.String path)
          Removes any trailing separator character (slash or backslash) from the given path and returns the modified path.
static java.lang.String removeTrailingSeparator(java.lang.String path, java.lang.String separator)
          Removes any trailing separator character (slash or backslash) from the given path and returns the modified path.
static PathUtils.ResolvedDestination resolveDestination(java.lang.String destPath, AbstractFile baseFolder)
          Resolves a destination path entered by the user and returns a PathUtils.ResolvedDestination object that that contains a AbstractFile instance corresponding to the path and a type that describes the kind of destination that was resolved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathUtils

public PathUtils()
Method Detail

resolveDestination

public static PathUtils.ResolvedDestination resolveDestination(java.lang.String destPath,
                                                               AbstractFile baseFolder)
Resolves a destination path entered by the user and returns a PathUtils.ResolvedDestination object that that contains a AbstractFile instance corresponding to the path and a type that describes the kind of destination that was resolved. null is returned if the path is not a valid destination (see below) or could not be resolved, for example becuase of I/O or authentication error.

The given path may be either absolute or relative to the specified base folder. If the base folder argument is null and the path is relative, null will always be returned. The path may contain '.', '..' and '~' tokens which will be left for the corresponding SchemeParser to canonize.

The path may refer to the following listed destination types. In all cases, the destination's parent folder must exist, if it doesn't null will always be returned. For example, /non_existing_folder/file is not a valid destination (provided that '/non_existing_folder' does not exist).

PathUtils.ResolvedDestination.EXISTING_FOLDER
if the path denotes a folder, either a directory or a browsable archive.
PathUtils.ResolvedDestination.EXISTING_FILE
if the path denotes a regular file. The file may be a browsable archive, see below.
PathUtils.ResolvedDestination.NEW_FILE
if the path denotes a non-existing file whose parent exists.
Paths to browsable archives are considered as denoting a folder only if they end with a trailing separator character. If they don't, they're considered as denoting a regular file. For example, /existing_folder/existing_archive.zip/ refers to the archive as a folder where as /existing_folder/existing_archive.zip refers to the archive as a regular file.

Parameters:
destPath - the destination path to resolve
baseFolder - the base folder used for relative paths, null to accept only absolute paths
Returns:
the object that that contains a AbstractFile instance corresponding to the path and a type that describes the kind of destination that was resolved

removeLeadingSeparator

public static java.lang.String removeLeadingSeparator(java.lang.String path)
Removes any leading separator character (slash or backslash) from the given path and returns the modified path.

Parameters:
path - the path to modify
Returns:
the modified path, free of any leading separator

removeLeadingSeparator

public static java.lang.String removeLeadingSeparator(java.lang.String path,
                                                      java.lang.String separator)
Removes any leading separator character from the given path and returns the modified path.

Parameters:
path - the path to modify
separator - the path separator, usually "/" or "\\"
Returns:
the modified path, free of any leading separator

removeTrailingSeparator

public static java.lang.String removeTrailingSeparator(java.lang.String path)
Removes any trailing separator character (slash or backslash) from the given path and returns the modified path.

Parameters:
path - the path to modify
Returns:
the modified path, free of any trailing separator

removeTrailingSeparator

public static java.lang.String removeTrailingSeparator(java.lang.String path,
                                                       java.lang.String separator)
Removes any trailing separator character (slash or backslash) from the given path and returns the modified path.

Parameters:
path - the path to modify
separator - the path separator, usually "/" or "\\"
Returns:
the modified path, free of any trailing separator


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard