org.webmacro.util
Class Settings

java.lang.Object
  extended byorg.webmacro.util.Settings
Direct Known Subclasses:
SubSettings

public class Settings
extends java.lang.Object


Nested Class Summary
static class Settings.ListSettingHandler
           
 
Field Summary
protected static java.lang.String[] stringArray
           
 
Constructor Summary
  Settings()
          Create an empty Settings object
protected Settings(java.util.Properties values)
          Instantiate a new Settings object using the properties supplied as the settings values.
  Settings(Settings defaults)
          Instantaite a new Settings object using the supplied Settings as the defaults
  Settings(java.lang.String settingsFile)
          Search for the named settingsFile on the classpath and instantiate a Settings object based on its values
  Settings(java.net.URL settingsFile)
          Search for the named settingsFile from the supplied URL and instantiate a Settings object based on its values
 
Method Summary
 boolean containsKey(java.lang.String key)
          Find out if a setting is defined
 java.util.Properties getAsProperties()
          Get the values from this settings object as a properties
 boolean getBooleanSetting(java.lang.String key)
          Get a setting and convert it to a boolean.
 boolean getBooleanSetting(java.lang.String key, boolean defaultValue)
          Get a setting with a default value in case it is not set
 int getIntegerSetting(java.lang.String key)
          Get a setting and convert it to an int
 int getIntegerSetting(java.lang.String key, int defaultValue)
          Get a setting with a default value in case it is not set
 java.lang.String[] getKeys()
          Get the keys for this settings object as an array
 java.lang.String getSetting(java.lang.String key)
          Get a setting.
 java.lang.String getSetting(java.lang.String key, java.lang.String defaultValue)
          Get a setting with a default value in case it is not set
 void load(java.io.InputStream in)
          Load settings from the supplied input stream
 void load(java.util.Properties props)
          Load settings from a Properties
 void load(java.util.Properties props, java.lang.String prefix)
          Load settings from a Properties, only extracting properties which have the specified prefix
 void load(Settings defaults)
          Load settings from a Settings
 void load(java.lang.String fileName)
          Load settings from the supplied fileName, searching for the file along the classpath, and then search for the settings file as a file: URL.
 void load(java.net.URL u)
          Load settings from the supplied URL
static void main(java.lang.String[] arg)
          Brief test
 void processListSetting(java.lang.String settingName, Settings.ListSettingHandler h)
          Iterate through a list of settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringArray

protected static final java.lang.String[] stringArray
Constructor Detail

Settings

public Settings()
Create an empty Settings object


Settings

public Settings(java.lang.String settingsFile)
         throws InitException,
                java.io.IOException
Search for the named settingsFile on the classpath and instantiate a Settings object based on its values


Settings

public Settings(java.net.URL settingsFile)
         throws InitException,
                java.io.IOException
Search for the named settingsFile from the supplied URL and instantiate a Settings object based on its values


Settings

protected Settings(java.util.Properties values)
Instantiate a new Settings object using the properties supplied as the settings values.


Settings

public Settings(Settings defaults)
Instantaite a new Settings object using the supplied Settings as the defaults

Method Detail

load

public void load(java.lang.String fileName)
          throws InitException,
                 java.io.IOException
Load settings from the supplied fileName, searching for the file along the classpath, and then search for the settings file as a file: URL.

Throws:
InitException
java.io.IOException

load

public void load(java.net.URL u)
          throws java.io.IOException
Load settings from the supplied URL

Throws:
java.io.IOException

load

public void load(java.io.InputStream in)
          throws java.io.IOException
Load settings from the supplied input stream

Throws:
java.io.IOException

load

public void load(Settings defaults)
Load settings from a Settings


load

public void load(java.util.Properties props,
                 java.lang.String prefix)
Load settings from a Properties, only extracting properties which have the specified prefix


load

public void load(java.util.Properties props)
Load settings from a Properties


containsKey

public boolean containsKey(java.lang.String key)
Find out if a setting is defined


getSetting

public java.lang.String getSetting(java.lang.String key)
Get a setting. We trim leading and trailing spaces (since the property file loader doesn't) and, if the result is a quoted string, remove the quotes.


getSetting

public java.lang.String getSetting(java.lang.String key,
                                   java.lang.String defaultValue)
Get a setting with a default value in case it is not set


getIntegerSetting

public int getIntegerSetting(java.lang.String key)
Get a setting and convert it to an int


getIntegerSetting

public int getIntegerSetting(java.lang.String key,
                             int defaultValue)
Get a setting with a default value in case it is not set


getBooleanSetting

public boolean getBooleanSetting(java.lang.String key)
Get a setting and convert it to a boolean. The values "on", "true", and "yes" are considered to be TRUE values, everything else is FALSE.


getBooleanSetting

public boolean getBooleanSetting(java.lang.String key,
                                 boolean defaultValue)
Get a setting with a default value in case it is not set


getKeys

public java.lang.String[] getKeys()
Get the keys for this settings object as an array


getAsProperties

public java.util.Properties getAsProperties()
Get the values from this settings object as a properties


processListSetting

public void processListSetting(java.lang.String settingName,
                               Settings.ListSettingHandler h)
Iterate through a list of settings. If the settingName is "foo", then the SettingHandler will be called once for each element of the space-separated list setting "foo", plus once for each setting of the form "foo.x". In the case of "foo.x", settingName will be passed as "x"; when processing the list setting, settingName will be passed as "". This is designed to support settings of the form Directives.a: ADirective Directives.b: BDirective Directives: CDirective DDirective


main

public static void main(java.lang.String[] arg)
                 throws java.lang.Exception
Brief test

Throws:
java.lang.Exception