Project Wonder 2.0

er.extensions
Class ERXProperties

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byer.extensions.ERXProperties
All Implemented Interfaces:
Cloneable, Map, Serializable

public class ERXProperties
extends Properties

Collection of simple utility methods used to get and set properties in the system properties. The only reason this class is needed is because all of the methods in NSProperties have been deprecated. This is a wee bit annoying. The usual method is to have a method like getBoolean off of Boolean which would resolve the System property as a Boolean object.

See Also:
Serialized Form

Field Summary
protected  String applicationNameForAppending
          caches the application name that is appended to the key for lookup
static String DefaultString
          default string
static ERXLogger log
          logging support
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ERXProperties()
           
 
Method Summary
protected  String applicationNameForAppending()
          Caches the application name for appending to the key.
static NSArray arrayForKey(String s)
          Cover method for returning an NSArray for a given system property.
static NSArray arrayForKeyWithDefault(String s, NSArray defaultValue)
          Cover method for returning an NSArray for a given system property and set a default value if not given.
static BigDecimal bigDecimalForKey(String s)
          Cover method for returning a BigDecimal for a given system property.
static BigDecimal bigDecimalForKeyWithDefault(String s, BigDecimal defaultValue)
          Cover method for returning a BigDecimal for a given system property or a default value.
static boolean booleanForKey(String s)
          Cover method for returning a boolean for a given system property.
static boolean booleanForKeyWithDefault(String s, boolean defaultValue)
          Cover method for returning a boolean for a given system property or a default value.
static NSDictionary dictionaryForKey(String s)
          Cover method for returning an NSDictionary for a given system property.
static NSDictionary dictionaryForKeyWithDefault(String s, NSDictionary defaultValue)
          Cover method for returning an NSDictionary for a given system property or the default value.
static String getActualPath(String path)
          Returns actual full path to the given file system path that could contain symbolic links.
 String getProperty(String key)
          Overriding the default getProperty method to first check: key.
static int intForKey(String s)
          Cover method for returning an int for a given system property.
static int intForKeyWithDefault(String s, int defaultValue)
          Cover method for returning an int for a given system property with a default value.
static long longForKey(String s)
          Cover method for returning a long for a given system property.
static long longForKeyWithDefault(String s, long defaultValue)
          Cover method for returning a long for a given system property with a default value.
static NSArray optionalConfigurationFiles()
          Gets an array of optionally defined configuration files.
static String pathForPropertiesUnderProjectPath(String projectPath)
          Returns the full path to the Properties file under the given project path.
static NSArray pathsForUserAndBundleProperties()
          Returns an array of paths to the Properties and WebObjects.properties files contained in the application/framework bundles and home directory.
static NSArray pathsForUserAndBundleProperties(boolean reportLoggingEnabled)
           
static void populateSystemProperties()
          Puts handy properties such as com.webobjects.version into the system properties.
static Properties propertiesFromArgv(String[] argv)
          Sets and returns properties object with the values from the given command line arguments string array.
static Properties propertiesFromFile(File file)
          Gets the properties for a given file.
static Properties propertiesFromPath(String path)
          Reads a Java properties file at the given path and returns a Properties object as the result.
static void setArrayForKey(NSArray array, String key)
          Sets an array in the System properties for a particular key.
static void setDictionaryForKey(NSDictionary dictionary, String key)
          Sets a dictionary in the System properties for a particular key.
static void setStringForKey(String string, String key)
          Sets a string in the System properties for another string.
static String sourceVersionString()
          Returns the version string of the given framework.
static String stringForKey(String s)
          Returning an string for a given system property.
static String stringForKeyWithDefault(String s, String defaultValue)
          Returning an string for a given system property.
static void transferPropertiesFromSourceToDest(Properties source, Properties dest)
          Copies all properties from source to dest.
static String versionStringForApplication()
          Returns the version string of the application.
static String versionStringForFrameworkNamed(String frameworkName)
          Returns the version string of the given framework.
static String webObjectsVersion()
          Returns WebObjects version as string.
static double webObjectsVersionAsDouble()
          Returns WebObjects version as double.
static boolean webObjectsVersionIs522OrHigher()
          Quick convience method used to determine if the current webobjects version is 5.22 or higher.
static boolean webObjectsVersionIs52OrHigher()
          Quick convience method used to determine if the current webobjects version is 5.2 or higher.
 
Methods inherited from class java.util.Properties
getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DefaultString

public static final String DefaultString
default string

See Also:
Constant Field Values

log

public static final ERXLogger log
logging support


applicationNameForAppending

protected String applicationNameForAppending
caches the application name that is appended to the key for lookup

Constructor Detail

ERXProperties

public ERXProperties()
Method Detail

populateSystemProperties

public static void populateSystemProperties()
Puts handy properties such as com.webobjects.version into the system properties. This method is called when the framework is initialized (when WOApplication.ApplicationWillFinishLaunchingNotification is posted.)


versionStringForApplication

public static String versionStringForApplication()
Returns the version string of the application. It checks CFBundleShortVersionString property in the info.plist resource and returns a trimmed version of the value.

Returns:
version number as string; can be a null-string when the applicaiton doesn't have the value of CFBundleShortVersionString in its info.plist resource.
See Also:
versionStringForFrameworkNamed(java.lang.String), webObjectsVersion()

versionStringForFrameworkNamed

public static String versionStringForFrameworkNamed(String frameworkName)
Returns the version string of the given framework. It checks CFBundleShortVersionString property in the info.plist resource and returns a trimmed version of the value.

Parameters:
frameworkName - name
Returns:
version number as string; can be null-string when the framework is not found or the framework doesn't have the value of CFBundleShortVersionString in its info.plist resource.
See Also:
versionStringForApplication(), webObjectsVersion(), ERXStringUtilities.removeExtraDotsFromVersionString(java.lang.String)

sourceVersionString

public static String sourceVersionString()
Returns the version string of the given framework. It checks SourceVersion property in the info.plist resource and returns a trimmed version of the value.

Returns:
version number as string; can be null-string when the framework is not found or the framework doesn't have the value of SourceVersion in its info.plist resource.
See Also:
versionStringForApplication(), webObjectsVersion()

webObjectsVersion

public static String webObjectsVersion()
Returns WebObjects version as string. If it's one of those version 5.1s (5.1, 5.1.1, 5.1.2...), this method will only return 5.1. If it's 5.2s, this mothod will return more precise version numbers such as 5.2.1. Note that version 5.0 series is not supported and may return incorrect version numbers (it will return 5.1).

Returns:
WebObjects version number as string
See Also:
webObjectsVersionAsDouble(), ERXStringUtilities.removeExtraDotsFromVersionString(java.lang.String)

webObjectsVersionAsDouble

public static double webObjectsVersionAsDouble()
Returns WebObjects version as double. If it's one of those version 5.1s (5.1, 5.1.1, 5.1.2...), this method will only return 5.1. If it's 5.2s, this mothod will return more precise version numbers such as 5.2.1. Note that version 5.0 series is not supported and may return incorrect version numbers (it will return 5.1).

Returns:
WebObjects version number as double
See Also:
webObjectsVersion()

webObjectsVersionIs52OrHigher

public static boolean webObjectsVersionIs52OrHigher()
Quick convience method used to determine if the current webobjects version is 5.2 or higher.

Returns:
if the version of webobjects is 5.2 or better

webObjectsVersionIs522OrHigher

public static boolean webObjectsVersionIs522OrHigher()
Quick convience method used to determine if the current webobjects version is 5.22 or higher.

Returns:
if the version of webobjects is 5.22 or better

arrayForKey

public static NSArray arrayForKey(String s)
Cover method for returning an NSArray for a given system property.

Parameters:
s - system property
Returns:
array de-serialized from the string in the system properties

arrayForKeyWithDefault

public static NSArray arrayForKeyWithDefault(String s,
                                             NSArray defaultValue)
Cover method for returning an NSArray for a given system property and set a default value if not given.

Parameters:
s - system property
defaultValue - default value
Returns:
array de-serialized from the string in the system properties or default value

booleanForKey

public static boolean booleanForKey(String s)
Cover method for returning a boolean for a given system property. This method uses the method booleanValue from ERXUtilities.

Parameters:
s - system property
Returns:
boolean value of the string in the system properties.

booleanForKeyWithDefault

public static boolean booleanForKeyWithDefault(String s,
                                               boolean defaultValue)
Cover method for returning a boolean for a given system property or a default value. This method uses the method booleanValue from ERXUtilities.

Parameters:
s - system property
defaultValue - default value
Returns:
boolean value of the string in the system properties.

dictionaryForKey

public static NSDictionary dictionaryForKey(String s)
Cover method for returning an NSDictionary for a given system property.

Parameters:
s - system property
Returns:
dictionary de-serialized from the string in the system properties

dictionaryForKeyWithDefault

public static NSDictionary dictionaryForKeyWithDefault(String s,
                                                       NSDictionary defaultValue)
Cover method for returning an NSDictionary for a given system property or the default value.

Parameters:
s - system property
defaultValue - default value
Returns:
dictionary de-serialized from the string in the system properties

intForKey

public static int intForKey(String s)
Cover method for returning an int for a given system property.

Parameters:
s - system property
Returns:
int value of the system property or 0

longForKey

public static long longForKey(String s)
Cover method for returning a long for a given system property.

Parameters:
s - system property
Returns:
long value of the system property or 0

bigDecimalForKey

public static BigDecimal bigDecimalForKey(String s)
Cover method for returning a BigDecimal for a given system property. This method uses the method bigDecimalValueWithDefault from ERXValueUtilities.

Parameters:
s - system property
Returns:
bigDecimal value of the string in the system properties. Scale is controlled by the string, ie "4.400" will have a scale of 3.

bigDecimalForKeyWithDefault

public static BigDecimal bigDecimalForKeyWithDefault(String s,
                                                     BigDecimal defaultValue)
Cover method for returning a BigDecimal for a given system property or a default value. This method uses the method bigDecimalValueWithDefault from ERXValueUtilities.

Parameters:
s - system property
defaultValue - default value
Returns:
BigDecimal value of the string in the system properties. Scale is controlled by the string, ie "4.400" will have a scale of 3.

intForKeyWithDefault

public static int intForKeyWithDefault(String s,
                                       int defaultValue)
Cover method for returning an int for a given system property with a default value.

Parameters:
s - system property
defaultValue - default value
Returns:
int value of the system property or the default value

longForKeyWithDefault

public static long longForKeyWithDefault(String s,
                                         long defaultValue)
Cover method for returning a long for a given system property with a default value.

Parameters:
s - system property
defaultValue - default value
Returns:
long value of the system property or the default value

stringForKey

public static String stringForKey(String s)
Returning an string for a given system property. This is a cover method of System.getProperty(java.lang.String)

Parameters:
s - system property
Returns:
string value of the system propery or null

stringForKeyWithDefault

public static String stringForKeyWithDefault(String s,
                                             String defaultValue)
Returning an string for a given system property. This is a cover method of System.getProperty(java.lang.String)

Parameters:
s - system property
Returns:
string value of the system propery or null

setArrayForKey

public static void setArrayForKey(NSArray array,
                                  String key)
Sets an array in the System properties for a particular key.

Parameters:
array - to be set in the System properties
key - to be used to get the value

setDictionaryForKey

public static void setDictionaryForKey(NSDictionary dictionary,
                                       String key)
Sets a dictionary in the System properties for a particular key.

Parameters:
dictionary - to be set in the System properties
key - to be used to get the value

setStringForKey

public static void setStringForKey(String string,
                                   String key)
Sets a string in the System properties for another string.

Parameters:
string - to be set in the System properties
key - to be used to get the value

transferPropertiesFromSourceToDest

public static void transferPropertiesFromSourceToDest(Properties source,
                                                      Properties dest)
Copies all properties from source to dest.

Parameters:
source - proeprties copied from
dest - properties copied to

propertiesFromPath

public static Properties propertiesFromPath(String path)
Reads a Java properties file at the given path and returns a Properties object as the result. If the file does not exist, returns an empty properties object.

Parameters:
path - file path to the properties file
Returns:
properties object with the values from the file specified.

propertiesFromFile

public static Properties propertiesFromFile(File file)
                                     throws IOException
Gets the properties for a given file.

Returns:
properties from the given file
Throws:
IOException

propertiesFromArgv

public static Properties propertiesFromArgv(String[] argv)
Sets and returns properties object with the values from the given command line arguments string array.

Parameters:
argv - string array typically provided by the command line arguments
Returns:
properties object with the values from the argv

pathsForUserAndBundleProperties

public static NSArray pathsForUserAndBundleProperties()
Returns an array of paths to the Properties and WebObjects.properties files contained in the application/framework bundles and home directory.

If ProjectBuilder (for Mac OS X) has the project opened, it will attempt to get the path to the one in the project directory instead of the one in the bundle.

This opened project detection feature is pretty fragile and will change between versions of the dev-tools.

Returns:
paths to Properties files

pathsForUserAndBundleProperties

public static NSArray pathsForUserAndBundleProperties(boolean reportLoggingEnabled)

pathForPropertiesUnderProjectPath

public static String pathForPropertiesUnderProjectPath(String projectPath)
Returns the full path to the Properties file under the given project path. At the current implementation, it looks for /Properties and /Resources/Properties. If the Properties file doesn't exist, returns null.

Parameters:
projectPath - string to the project root directory
Returns:
the path to the Properties file if it exists

optionalConfigurationFiles

public static NSArray optionalConfigurationFiles()
Gets an array of optionally defined configuration files.

Returns:
array of configuration file names (absolute paths)

getActualPath

public static String getActualPath(String path)
Returns actual full path to the given file system path that could contain symbolic links. For example: /Resources will be converted to /Versions/A/Resources when /Resources is a symbolic link.

Parameters:
path - path string to a resource that could contain symbolic links
Returns:
actual path to the resource

applicationNameForAppending

protected String applicationNameForAppending()
Caches the application name for appending to the key. Note that for a period when the application is starting up application() will be null and name() will be null.

Returns:
application name used for appending, for example ".ERMailer"

getProperty

public String getProperty(String key)
Overriding the default getProperty method to first check: key. before checking for key. If nothing is found then key.Default is checked.

Parameters:
key - to check
Returns:
property value

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.