WebObjects 5.2.3

com.webobjects.foundation
Class NSPathUtilities

java.lang.Object
  extended bycom.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:
lastPathComponent(String path), pathExtension(String path), stringByAppendingPathComponent(String path, String component), stringByAppendingPathExtension(String path, String extension), stringByDeletingLastPathComponent(String path), stringByDeletingPathExtension(String path), stringByStandardizingPath(String path), homeDirectory()

Constructor Summary
NSPathUtilities()
           
 
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
 

Constructor Detail

NSPathUtilities

public NSPathUtilities()
Method Detail

URLWithPath

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

fileExistsAtPath

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, 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

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

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

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

pathIsAbsolute

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

pathIsEqualToString

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

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:
stringByAppendingPathExtension(java.lang.String, java.lang.String), 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

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:
stringByDeletingPathExtension(java.lang.String), 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:
pathExtension(java.lang.String), stringByDeletingLastPathComponent(java.lang.String)

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:
stringByStandardizingPath(java.lang.String)

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:
stringByNormalizingExistingPath(java.lang.String)

stringByStandardizingPath

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

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

Last updated Thu Oct 21 15:04:16 PDT 2004.

Copyright © 2004 Apple Computer, Inc.