WebObjects 5.4.2

com.webobjects.foundation
Class NSPathUtilities

java.lang.Object
  extended by com.webobjects.foundation.NSPathUtilities

public class NSPathUtilities
extends Object

This class provides static methods that are useful when working with paths. Specifically, it includes methods that extract particular path components, modify paths, and return special paths.

This class cannot be instantiated.

See Also:
NSPathUtilities.lastPathComponent(String path), NSPathUtilities.pathExtension(String path), NSPathUtilities.stringByAppendingPathComponent(String path, String component), NSPathUtilities.stringByAppendingPathExtension(String path, String extension), NSPathUtilities.stringByDeletingLastPathComponent(String path), NSPathUtilities.stringByDeletingPathExtension(String path), NSPathUtilities.stringByStandardizingPath(String path), NSPathUtilities.homeDirectory()

Method Summary
static boolean fileExistsAtPath(String path)
          Deprecated. Use (new File(aString)).exists() or fileExistsAtPathURL()
static boolean fileExistsAtPathURL(URL pathURL)
           
static String homeDirectory()
          Returns a String representing the home directory path of the user who executes the application.
static String lastPathComponent(String path)
          Returns the last path component of path.
static String pathExtension(String path)
          Returns a path's extension, if any (not including the extension divider).
static boolean pathIsAbsolute(String path)
          Deprecated. Use (new File(aString)).isAbsolute().
static boolean pathIsEqualToString(String path1, String path2)
          Deprecated. This method should not be used.
static String stringByAppendingPathComponent(String path, String component)
          Returns a String made by appending path with component, preceded, if necessary, by a path separator.
static String stringByAppendingPathExtension(String path, String extension)
          Returns a string made by appending to path an extension separator, followed by extension.
static String stringByDeletingLastPathComponent(String path)
          Returns a string made by deleting the last path component from path, along with any final path separator.
static String stringByDeletingPathExtension(String path)
          Returns a String made by deleting the extension (if any, and only the last) from path.
static String stringByNormalizingExistingPath(String path)
          Returns a String containing the normalized path for an existing file.
static String stringByNormalizingPath(String path)
          Returns a String containing the normalized path for a path string.
static String stringByStandardizingPath(String path)
          Deprecated. This method should not be used.
static URL URLWithPath(String path)
          Deprecated. Use new URL("file", "", path).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

homeDirectory

public static String homeDirectory()
Returns a String representing the home directory path of the user who executes the application.

Returns:
string representing the home directory path of the user who executes the application

pathExtension

public static String pathExtension(String path)
Returns a path's extension, if any (not including the extension divider).

The following table illustrates the effect of this method on a variety of paths:

path's Result
"/tmp/scratch.tiff" "tiff"
"/tmp/scratch" "" (an empty string)
"/tmp/" "" (an empty string)
"/tmp/scratch..tiff" "tiff"
"/tmp/test.eomodeld/" "eomodeld"

Parameters:
path - the file system path
Returns:
the extension of the path indicated in path

lastPathComponent

public static String lastPathComponent(String path)
Returns the last path component of path.

The following table illustrates the effect of this method on a variety of paths:

path Result
"/tmp/scratch.tiff" "scratch.tiff"
"/tmp/scratch" "scratch"
"/tmp/" "tmp"
"scratch" "scratch"
"/" "" (an empty string)

Parameters:
path - the file system path
Returns:
the last path component of path

stringByDeletingLastPathComponent

public static String stringByDeletingLastPathComponent(String path)
Returns a string made by deleting the last path component from path, along with any final path separator. If path represents the root path, however, it's returned unaltered. The following table illustrates the effect of this method on a variety of paths:

path Result
"/tmp/scratch.tiff" "/tmp"
"/tmp/lock/" "/tmp"
"/tmp/" "/"
"/tmp" "/"
"/" "/"
"scratch.tiff" "" (an empty string)

Parameters:
path - the path to process
Returns:
string made by deleting the last path component from path
See Also:
NSPathUtilities.stringByDeletingPathExtension(java.lang.String), NSPathUtilities.stringByAppendingPathComponent(java.lang.String, java.lang.String)

stringByDeletingPathExtension

public static String stringByDeletingPathExtension(String path)
Returns a String made by deleting the extension (if any, and only the last) from path. Strips any trailing path separator before checking for an extension. If path represents the root path, however, it's returned unaltered. The following table illustrates the effect of this method on a variety of paths:

path Result
"/tmp/scratch.tiff" "/tmp/scratch"
"/tmp/" "/tmp"
"scratch.bundle/" "scratch"
"scratch..tiff" "scratch."
".tiff" "" (an empty string)
"/" "/"

Parameters:
path - the path to process
Returns:
string made by deleting the extension from path
See Also:
NSPathUtilities.pathExtension(java.lang.String), NSPathUtilities.stringByDeletingLastPathComponent(java.lang.String)

stringByAppendingPathComponent

public static String stringByAppendingPathComponent(String path,
                                                    String component)
Returns a String made by appending path with component, preceded, if necessary, by a path separator. The following table illustrates the effect of this method on a variety of paths, assuming that component is supplied as "scratch.tiff":

path Result
"/tmp" "/tmp/scratch.tiff"
"/tmp/" "/tmp/scratch.tiff"
"/" "/scratch.tiff"
"" (an empty string) "scratch.tiff"

Parameters:
path - string to which component is added
component - string to add to path
Returns:
string made by adding component to path
See Also:
NSPathUtilities.stringByAppendingPathExtension(java.lang.String, java.lang.String), NSPathUtilities.stringByDeletingLastPathComponent(java.lang.String)

stringByAppendingPathExtension

public static String stringByAppendingPathExtension(String path,
                                                    String extension)
Returns a string made by appending to path an extension separator, followed by extension. Note that if path ends with one or more slashes ("/"), these slashes are deleted. The following table illustrates the effect of this method on a variety of different paths, assuming that extension is supplied as "tiff":

path Result
"/tmp/scratch.old" "/tmp/scratch.old.tiff"
"/tmp/scratch." "/tmp/scratch..tiff"
"/tmp/" "/tmp.tiff"
"scratch" "scratch.tiff"

Parameters:
path - the path to append the extension to
extension - extension to be appended to path
Returns:
string made by appending to path an extension separator and extension

stringByNormalizingExistingPath

public static String stringByNormalizingExistingPath(String path)
Returns a String containing the normalized path for an existing file.

If the file does not exist, this method returns an empty string. The normalized path is always absolute and corresponds to the canonical path returned by the java.io.File.getCanonicalPath method.

Parameters:
path - path to be normalized
Returns:
the normalized path
See Also:
NSPathUtilities.stringByStandardizingPath(java.lang.String)

stringByStandardizingPath

@Deprecated
public static String stringByStandardizingPath(String path)
Deprecated. This method should not be used.

Parameters:
path - path string to standardize
Returns:
a standardized path string

pathIsEqualToString

@Deprecated
public static boolean pathIsEqualToString(String path1,
                                                     String path2)
Deprecated. This method should not be used.

Parameters:
path1 - a path string to compare for equality
path2 - a path string to compare for equality
Returns:
true if path1 and path2 are equal

pathIsAbsolute

@Deprecated
public static boolean pathIsAbsolute(String path)
Deprecated. Use (new File(aString)).isAbsolute().

Parameters:
path - the file system path
Returns:
true if path is an absolute path
See Also:
File

fileExistsAtPath

@Deprecated
public static boolean fileExistsAtPath(String path)
Deprecated. Use (new File(aString)).exists() or fileExistsAtPathURL()

Parameters:
path - the file system path
Returns:
true if the file at path exists
See Also:
File, NSPathUtilities.fileExistsAtPathURL(java.net.URL)

fileExistsAtPathURL

public static boolean fileExistsAtPathURL(URL pathURL)
Parameters:
pathURL - the file URL
Returns:
true if the file at pathURL exists.
Since:
5.2.2
See Also:
URL

URLWithPath

@Deprecated
public static URL URLWithPath(String path)
Deprecated. Use new URL("file", "", path).

Parameters:
path - the file system path
Returns:
URL for path
See Also:
URL

stringByNormalizingPath

public static String stringByNormalizingPath(String path)
Returns a String containing the normalized path for a path string.

This is exactly like stringByNormalizingExistingPath, except that the path does not have to reference an existing file.The normalized path is always absolute and corresponds to the canonical path returned by the java.io.File.getCanonicalPath method.

Parameters:
path - path to be normalized
Returns:
the normalized path
Since:
5.2.2
See Also:
NSPathUtilities.stringByNormalizingExistingPath(java.lang.String)

Last updated June 2008

Copyright © 2000-2008 Apple Inc.