artisynth.core.util
Class ArtisynthPath

java.lang.Object
  extended by artisynth.core.util.ArtisynthPath

public class ArtisynthPath
extends java.lang.Object


Method Summary
static java.lang.String convertToLocalSeparators(java.lang.String pathName)
          Tries to convert file separation characters in a path name to ones appropriate for the local system.
static java.lang.String convertToUnixSeparators(java.lang.String pathName)
          Tries to convert file separation characters in a path name to ones appropriate for Unix.
static java.lang.String convertToWindowsSeparators(java.lang.String pathName)
          Tries to convert file separation characters in a path name to ones appropriate for Windows.
static boolean filesAreTheSame(java.io.File f1, java.io.File f2)
           
static java.io.File findFile(java.lang.String relpath)
           
static java.io.File[] findFiles(java.lang.String relpath)
          Searches for files.
static java.io.File[] findFilesMatching(java.lang.String pattern)
           
static java.net.URL findResource(java.lang.String relpath)
           
static java.net.URL[] findResources(java.lang.String relpath)
          Searches for resources.
static java.lang.String getHomeDir()
          Returns the Artisynth home directory, as specified by the ARTISYNTH_HOME environment variable.
static java.io.File getHomeRelativeFile(java.lang.String relpath, java.lang.String alternate)
          Returns a file specified relative to the Artisynth home directory, as specified by the environment variable ARTISYNTH_HOME.
static java.lang.String getHomeRelativePath(java.lang.String relpath, java.lang.String alternate)
          Creates a full path from a path specified relative to the Artisynth home directory, as specified by the environment variable ARTISYNTH_HOME.
static java.net.URL getRelativeResource(java.lang.Object refObj, java.lang.String relpath)
          Returns a URL resource specified by a path relative to a given reference object.
static java.net.URL getResource(java.lang.String abspath)
          Returns a URL resource specified by an absolute path with respect to the ArtiSynth package hierarchy.
static java.io.File getRootRelativeFile(java.lang.Object classObj, java.lang.String relpath)
          Returns a File specified relative to the root directory associated with a class.
static java.lang.String getRootRelativePath(java.lang.Object classObj, java.lang.String relpath)
          Returns a file path specified relative to the root directory associated with a class.
static java.io.File getSrcRelativeFile(java.lang.Object classObj, java.lang.String relpath)
          Returns a File specified relative to the source directory for a specified class.
static java.lang.String getSrcRelativePath(java.lang.Object classObj, java.lang.String relpath)
          Returns a complete file path from a path relative to the source directory for a specified class.
static java.io.File getWorkingDir()
          Gets the current working directory.
static java.lang.String getWorkingDirPath()
          Gets the canonical path name for the working directory.
static void main(java.lang.String[] args)
           
static void setWorkingDir(java.io.File dir)
          Sets the current working directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getResource

public static java.net.URL getResource(java.lang.String abspath)
Returns a URL resource specified by an absolute path with respect to the ArtiSynth package hierarchy.

The path should be a standard UNIX-style path, with / as a file separator and parent directories delimited by ... It may optionally begin with a / character.

If the source file hierarchy is separate from the class file hierarchy, then the resource is first sought with respect to the source file hierarchy. If the requested resource cannot be found with respect to either a source file hierarchy or the class file hierarchy, then null is returned.

Parameters:
abspath - absolute path for the resource.
Throws:
java.lang.IllegalArgumentException - if the path is improperly specified.

getRelativeResource

public static java.net.URL getRelativeResource(java.lang.Object refObj,
                                               java.lang.String relpath)
Returns a URL resource specified by a path relative to a given reference object.

The path should be a standard UNIX-style path, with / as a file separator and parent directories delimited by ... It should not begin with a /.

The reference object must be a associated with class contained within the ArtiSynth package hierarchy. If the reference object is itself a Class object, then the associated class is the object itself. The location of the resource within the package hierarchy is given by appending the specified path to the class package path.

If the source file hierarchy is separate from the class file hierarchy, then the resource is first sought with respect to the source file hierarchy. If the requested resource cannot be found with respect to either a source file hierarchy or the class file hierarchy, then null is returned.

Parameters:
refObj - reference object or class
relpath - resource path
Returns:
URL for the resource, or null if no resource was found
Throws:
java.lang.IllegalArgumentException - if the path is improperly specified.

getHomeDir

public static java.lang.String getHomeDir()
Returns the Artisynth home directory, as specified by the ARTISYNTH_HOME environment variable. If this variable is not set, an attempt is made to infer the home location from the location of this class, and if that is not successful, "." is returned.

Returns:
Artisynth home directory

getHomeRelativeFile

public static java.io.File getHomeRelativeFile(java.lang.String relpath,
                                               java.lang.String alternate)
Returns a file specified relative to the Artisynth home directory, as specified by the environment variable ARTISYNTH_HOME. If ARTISYNTH_HOME is not set, alternate is used instead. Any instances of either the Unix or Windows file separator characters (i.e., '/' or '\') are mapped to the file separator character for the current system.

Parameters:
relpath - file path name relative to ARTISYNTH_HOME
alternate - used if ARTISYNTH_HOME is not set
Returns:
file relative to ARTISYNTH_HOME

getRootRelativePath

public static java.lang.String getRootRelativePath(java.lang.Object classObj,
                                                   java.lang.String relpath)
Returns a file path specified relative to the root directory associated with a class. This method works by climbing the class resource hierarchy. The root directory is assumed to be one level above the top directory for the class hierarchy. For example, if the class is artisynth.core.workspace.RootModel, and its class file is located in
    /users/home/joe/artisynth_core/classes/artisynth/core/modelbase
 
then the root directory is
    /users/home/joe/artisynth_core
 

The class is determined from classObj, either directly, if classObj is an instance of Class, or by calling classObj.getClass(). The class must be associated with a package.

If the relative path specified by relpath is null, then the path for the root directory itself is returned. Within the returned file path, instances of either the Unix or Windows file separator characters (i.e., '/' or '\') are mapped to the file separator character for the current system.

Parameters:
classObj - object used to determine the class
relpath - path relative to the root directory
Returns:
file path specified relative to the root directory

getRootRelativeFile

public static java.io.File getRootRelativeFile(java.lang.Object classObj,
                                               java.lang.String relpath)
Returns a File specified relative to the root directory associated with a class. This method is a wrapper for getRootRelativePath(); see that method for more information about how the file path is created.

Parameters:
classObj - object used to determine the class
relpath - path relative to the root directory
Returns:
file specified relative to the root directory

getHomeRelativePath

public static java.lang.String getHomeRelativePath(java.lang.String relpath,
                                                   java.lang.String alternate)
Creates a full path from a path specified relative to the Artisynth home directory, as specified by the environment variable ARTISYNTH_HOME. If ARTISYNTH_HOME is not set, alternate is used instead. Any instances of either the Unix or Windows file separator characters (i.e., '/' or '\') are mapped to the file separator character for the current system.

Parameters:
relpath - file path name relative to ARTISYNTH_HOME
alternate - used if ARTISYNTH_HOME is not set
Returns:
full path

getSrcRelativePath

public static java.lang.String getSrcRelativePath(java.lang.Object classObj,
                                                  java.lang.String relpath)
Returns a complete file path from a path relative to the source directory for a specified class. This method works by climbing the class's resource hierarchy. For this method to work, the root directory of the source file hierarchy must be named src, and if classes are stored in a separate file hierarchy, the root directory of that must be named classes and must be a sibling of src.

The class is determined from classObj, either directly, if classObj is an instance of Class, or by calling classObj.getClass(). The class must be associated with a package.

If the relative path specified by relpath is null, then the path for the source directory itself is returned. Within the returned file path, instances of either the Unix or Windows file separator characters (i.e., '/' or '\') are mapped to the file separator character for the current system.

Parameters:
classObj - object used to deterine the class
relpath - path relative to class's source directory
Returns:
file path specified relative to the source directory

getSrcRelativeFile

public static java.io.File getSrcRelativeFile(java.lang.Object classObj,
                                              java.lang.String relpath)
Returns a File specified relative to the source directory for a specified class. This method is a wrapper for getSrcRelativePath(); see that method for more information about how the file path is created.

Parameters:
classObj - object uses to determine the class
relpath - path relative to class's source directory
Returns:
file specified relative to the source directory

findResource

public static java.net.URL findResource(java.lang.String relpath)

findFile

public static java.io.File findFile(java.lang.String relpath)

findFiles

public static java.io.File[] findFiles(java.lang.String relpath)
Searches for files. Initially, we look among the directories listed in the environment variable ARTISYNTH_PATH, and the first readable file found is returned. If ARTISYNTH_PATH is not set, then we check the current working directory, the user's home directory, and finally the Artisynth home directory.

Parameters:
relpath - name of the desired file relative to the directories being searched.
Returns:
an array of the files found, or null if no file was found

findFilesMatching

public static java.io.File[] findFilesMatching(java.lang.String pattern)

findResources

public static java.net.URL[] findResources(java.lang.String relpath)
Searches for resources. Initially, we look among the directories listed in the environment variable ARTISYNTH_PATH, and the first readable file found is returned. If ARTISYNTH_PATH is not set, then we check the current working directory, the user's home directory, and finally the Artisynth home directory.

Parameters:
relpath - name of the desired resource relative to the directories being searched.
Returns:
an array of the resources found, or null if no resource was found

getWorkingDir

public static java.io.File getWorkingDir()
Gets the current working directory. By default, this is whatever directory corresponds to ".".

Returns:
current working directory

getWorkingDirPath

public static java.lang.String getWorkingDirPath()
Gets the canonical path name for the working directory. If for some reason this can't be determined, a warning is printed and the absolute path name is returned.

Returns:
canonical path name for working directory

setWorkingDir

public static void setWorkingDir(java.io.File dir)
Sets the current working directory. If null is specified, then the current working directory is set to whatever directory corresponds to ".".

Parameters:
dir - new working directory
Throws:
java.lang.IllegalArgumentException - if dir is not a directory

convertToLocalSeparators

public static java.lang.String convertToLocalSeparators(java.lang.String pathName)
Tries to convert file separation characters in a path name to ones appropriate for the local system. In particular, on Unix, the Windows separation character '\' will be converted to '/', and on Windows, '/' will be converted to a '\'.

Returns:
converted path name

convertToUnixSeparators

public static java.lang.String convertToUnixSeparators(java.lang.String pathName)
Tries to convert file separation characters in a path name to ones appropriate for Unix. In particular, the Windows separation character '\' will be converted to '/'.

Returns:
converted path name

convertToWindowsSeparators

public static java.lang.String convertToWindowsSeparators(java.lang.String pathName)
Tries to convert file separation characters in a path name to ones appropriate for Windows. In particular, the Unix separation character '/' will be converted to '\'.

Returns:
converted path name

filesAreTheSame

public static boolean filesAreTheSame(java.io.File f1,
                                      java.io.File f2)

main

public static void main(java.lang.String[] args)