com.cafesoft.core.util
Class PropertyUtils

java.lang.Object
  |
  +--com.cafesoft.core.util.PropertyUtils

public class PropertyUtils
extends Object

PropertyUtils provides convenience methods for loading Java Properties from disk.


Constructor Summary
PropertyUtils()
           
 
Method Summary
static boolean getBooleanValue(Properties properties, String propertyName, boolean defaultValue)
          Get a boolean value from a Properties object.
static int getIntegerValue(Properties properties, String propertyName, int defaultValue)
          Get a integer value from a Properties object.
static int getIntegerValue(Properties properties, String propertyName, int defaultValue, Object source, Logger logger)
          Get a integer value from a Properties object.
static Properties load(File file)
          Load Properties from a File.
static Properties load(String filePath)
          Load Properties from a file at the specified path.
static Properties parseProperties(String propString, char pairSep, char namevalSep)
          Parse Properties from a String.
static Properties parseProperties(String propString, String pairSep, char namevalSep)
          Parse Properties from a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyUtils

public PropertyUtils()
Method Detail

load

public static Properties load(File file)
Load Properties from a File.

If an Exception occurs, write a stack trace to the current PrintStream. (The default PrintStream is System.err).

Parameters:
file - the Properties File to be loaded.
Returns:
the Properties.

load

public static Properties load(String filePath)
Load Properties from a file at the specified path.

If an Exception occurs, write a stack trace to the current PrintStream. (The default PrintStream is System.err).

Parameters:
filePath - the path to the Properties file to be loaded.
Returns:
the Properties.

parseProperties

public static Properties parseProperties(String propString,
                                         char pairSep,
                                         char namevalSep)
Parse Properties from a String.

For example, if propString is: name1=value1,name2=value2

then pairSep = ',' and namevalSep = '='

Parameters:
propString - the String containing properties to be parsed.
pairSep - the character used to separate name=value pairs.
namevalSep - the character used to separate a name from a value.
Returns:
the Properties.

parseProperties

public static Properties parseProperties(String propString,
                                         String pairSep,
                                         char namevalSep)
Parse Properties from a String.

For example, if propString is: name1=value1, name2=value2

and pairSep = ", " and namevalSep = '='

Parameters:
propString - the String containing properties to be parsed.
pairSep - a String containing the characters than can separate name=value pairs. For example: ", \t\n\r" would match a comma, space, tab, newline, and carriage return characters.
namevalSep - the character used to separate a name from a value.
Returns:
the Properties.

getBooleanValue

public static boolean getBooleanValue(Properties properties,
                                      String propertyName,
                                      boolean defaultValue)
Get a boolean value from a Properties object.

This method will get the property specified by the propertyName parameter from the given properties object. If the value does not exist the defaultValue parameter will be returned.

Parameters:
properties - the Properties object to get the boolean value from.
propertyName - the parameter name to get.
defaultValue - the default value to return if the parameter name does not exist in the Properties object.
Returns:
a boolean value that represents the value contained by the property specified by the paramName parameter, or the defaultValue if the property does not exist.

getIntegerValue

public static int getIntegerValue(Properties properties,
                                  String propertyName,
                                  int defaultValue)
Get a integer value from a Properties object.

This method will get the property specified by the propertyName parameter from the given properties object. If the value does not exist the defaultValue parameter will be returned.

Parameters:
properties - the Properties object to get the int value from.
propertyName - the parameter name to get.
defaultValue - the default value to return if the parameter name does not exist in the Properties object.
Returns:
a int value that represents the value contained by the property specified by the paramName parameter, or the defaultValue if the property does not exist.

getIntegerValue

public static int getIntegerValue(Properties properties,
                                  String propertyName,
                                  int defaultValue,
                                  Object source,
                                  Logger logger)
Get a integer value from a Properties object.

This method will get the property specified by the propertyName parameter from the given properties object. If the value does not exist the defaultValue parameter will be returned. If the logger is not null a warning message will be logged.

Parameters:
properties - the Properties object to get the int value from.
propertyName - the parameter name to get.
defaultValue - the default value to return if the parameter name does not exist in the Properties object.
source - the object attempting to get the int value. Used for logging purposes. If null the PropertyUtils.class value is used.
logger - the logger to log the warning message to. If the logger is null then no error message is logged.
Returns:
a int value that represents the value contained by the property specified by the paramName parameter, or the defaultValue if the property does not exist.


Generated on 8:41:50 AM June 06, 2005, © 1996-2005 Cafésoft LLC. All rights reserved.