net.sf.taverna.raven.appconfig
Class ApplicationUserHome

java.lang.Object
  extended by net.sf.taverna.raven.appconfig.ApplicationUserHome

public class ApplicationUserHome
extends java.lang.Object

Find and create an application's user directory according to operating system standards.

For example for the application "MyApp" this class will be able to find $HOME/.myapp on Linux or C:\Document and settings\MyUsername\Application Data\MyApplication on Windows XP.

Author:
Stian Soiland-Reyes, Stuart Owen

Constructor Summary
ApplicationUserHome(java.lang.String applicationName)
          Initialise with the name of the application.
ApplicationUserHome(java.lang.String applicationName, java.lang.String defaultApplicationHome)
          Initialise with the name of the application and a default application home.
 
Method Summary
 java.lang.String getApplicationName()
          The application's name.
 java.io.File getAppUserHome()
          Find (and if necessary create) the user's application directory, according to operating system standards.
 java.lang.String getDefaultApplicationHome()
          The full path to the default home directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationUserHome

public ApplicationUserHome(java.lang.String applicationName)
Initialise with the name of the application.

Parameters:
applicationName - This name will be used as a template for creating the application home directory (but might be transcribed, for instance to lowercase). It is generally recommended, but not required - that this name does not contain spaces or any special international/Unicode characters.

ApplicationUserHome

public ApplicationUserHome(java.lang.String applicationName,
                           java.lang.String defaultApplicationHome)
Initialise with the name of the application and a default application home.

Parameters:
applicationName - This name will be used as a template for creating the application home directory (but might be transcribed, for instance to lowercase). It is generally recommended, but not required - that this name does not contain spaces or any special international/Unicode characters.
defaultApplicationHome - The full path to the default home directory. If this string is not null, then a File based on this directory will always be returned by getDefaultApplicationHome() - otherwise the normal operating system logic is used to determine the application's home directory.
Method Detail

getAppUserHome

public java.io.File getAppUserHome()
Find (and if necessary create) the user's application directory, according to operating system standards. The resolved directory is then returned as a File object.

The application's name as defined by getApplicationName() is used as a basis for naming the directory of the application's user directory, but the directory name might for instance be transformed to lowercase.

If getDefaultApplicationHome() returns a non-null value, the directory specified by that path will be used instead of the operation system specific directory. The directory will be created if needed.

If any exception occurs (such as out of diskspace), null will be returned.

On Windows XP, this will typically be something like:

        C:\Document and settings\MyUsername\Application Data\MyApplication
 
and on Windows Vista it would be something like:
          C:\Users\MyUsername\Application Data\MyApplication
 
while on Mac OS X it will be something like:
        /Users/MyUsername/Library/Application Support/MyApplication
 
All other OS'es are assumed to be UNIX-alike, returning something like:
        /user/myusername/.myapplication
 

If the directory does not already exist, it will be created.

Returns:
An File referring to an existing directory for user-specific configuration etc. for the given application.

getApplicationName

public java.lang.String getApplicationName()
The application's name. This name will be used as a template for creating the application home directory (but might be transcribed, for instance to lowercase). It is generally recommended, but not required - that this name does not contain spaces or any special international/Unicode characters.

Returns:
The application's name.

getDefaultApplicationHome

public java.lang.String getDefaultApplicationHome()
The full path to the default home directory. If this string is not null, then a File based on this directory will always be returned by getDefaultApplicationHome() - otherwise the normal operating system logic is used to determine the application's home directory.

Returns:
The full path to the application's home directory, or null if the operation system specific logic is to be used.