at.knowcenter.wag.egov.egiz.cfg
Class SettingsReader

java.lang.Object
  extended by at.knowcenter.wag.egov.egiz.cfg.SettingsReader
All Implemented Interfaces:
Settings, Serializable

public class SettingsReader
extends Object
implements Settings, Serializable

The SettingsReader reads the settings.txt file. The settings.txt is a simple java property file that collects all parameters used in different modules. The SettingsReader provides methods to get the property keys and the corresponding values. The keys could be defined as combinations of single keys. Therefore it is possible to combine differen classes of keys. An example could be:

     
      
       
        
         
          
           
            
             
              
               
                        #SettingNotFoundException
                        error.code.100=Interner Fehler
                        error.code.101=Die Konfigurationsdatei konnte nicht geladen werden
                        
                        #PDFDocumentException
                        error.code.200=Das Dokument konnte nicht geladen werden
                        
                        #SignatureException
                        error.code.300=Die Signatur ist ungültig
                        
                        #NormalizeException
                        error.code.400=Die angegebene Version ist nicht bekannt
                       
                        normalizer.version=V01
                
               
              
             
            
           
          
         
        
       
      
 
The internal representation of the example above is:
     
      
       
        
         
          
           
            
             
              
               
                        .error|
                              |.code|
                              |     |.200=Das Dokument konnte nicht geladen werden
                              |     |.100=Interner Fehler
                              |     |.400=Die angegebene Version ist nicht bekannt
                              |     |.101=Die Konfigurationsdatei konnte nicht geladen werden
                              |     |.300=Die Signatur ist ungültig
                       .normalizer|
                                  |.version=V01
                
               
              
             
            
           
          
         
        
       
      
 

Author:
wlackner
See Also:
Serialized Form

Field Summary
static String CERT_PATH
          The path of the certificated directory.
static String CONFIG_FILE_DEFAULT_NAME
          The name of the default configuration file.
static String CONFIG_PATH
          The path of the configuration directory.
static String HELP_TEXT_FILE_DEFAULT_NAME
          The name of the help text configuration file.
static String RESOURCES_PATH
          The path of the resources repository.
protected static String TEMP_DIR_NAME
          The name of the directory, where temporary files are stored.
 
Method Summary
protected static File assembleTemporaryDirectoryFile()
          Assembles the File of the temporary directory without checking if it really exists.
static void clearTemporaryDirectory()
          Deletes all files in the temporary directory, if it exists.
static SettingsReader getInstance()
          This method returns an synchronized instance of this class.
 int getIntSetting(String key, int defaultValue)
          If a property value is number (interger) this method extracts the value and convert it to an int.
 ArrayList getKeys(String key)
          This method returns an array of sub keys (children references) of the key.
 PropertyTree getPTree()
          This method returns the PropertyTree representation of the configuration file.
 String getSetting(String key)
          This method returns a property value to the corresponding key.
 String getSetting(String key, String defaultValue)
          This method returns a property value to the corresponding key.
 String getSetting(String primaryKey, String defaultKey, String defaultValue)
          This method returns a property value to the corresponding key.
 Vector getSettingKeys(String keyPrefix)
          This method returns an array of keys in the same hierarchy of the keyPrefix.
static File getTemporaryDirectory()
          Returns the directory where temporary files should be stored.
 String getValueFromKey(String key)
          This method returns a the first value from a key.
static void initializeForCommandLine()
          Initializes the paths of the SettingsReader for commanline usage.
static void initializeForWeb(String base_dir)
          Initializes the paths of the SettingsReader for web application usage.
static String relocateFile(String file)
          Relocates the relative file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCES_PATH

public static String RESOURCES_PATH
The path of the resources repository.

This usually contains sub directories for the templates, the configuration files, etc.


CONFIG_PATH

public static String CONFIG_PATH
The path of the configuration directory.


CERT_PATH

public static String CERT_PATH
The path of the certificated directory.


TEMP_DIR_NAME

protected static String TEMP_DIR_NAME
The name of the directory, where temporary files are stored.


CONFIG_FILE_DEFAULT_NAME

public static final String CONFIG_FILE_DEFAULT_NAME
The name of the default configuration file. The definition syntax is the java property config syntax.

See Also:
Constant Field Values

HELP_TEXT_FILE_DEFAULT_NAME

public static final String HELP_TEXT_FILE_DEFAULT_NAME
The name of the help text configuration file. The definition syntax is the java property config syntax.

See Also:
Constant Field Values
Method Detail

getInstance

public static SettingsReader getInstance()
                                  throws SettingsException
This method returns an synchronized instance of this class. The settings file is read only once using this class. This method returns the instance holding the definitions of the default settings file. Default file: CONFIG_FILE_DEFAULT_NAME: "settings.txt"

Returns:
an instance of the SettingsReader
Throws:
SettingsException - if the default settings file could not be read

getSetting

public String getSetting(String key)
                  throws SettingNotFoundException
This method returns a property value to the corresponding key. If the key is not found in the property file a SettingNotFoundException is thrown.

Specified by:
getSetting in interface Settings
Parameters:
key - get the value for that key in the property file
Returns:
the value of the property key.
Throws:
SettingNotFoundException - ErrorCode: 100

relocateFile

public static String relocateFile(String file)
Relocates the relative file.

Parameters:
file - The relative file.
Returns:
Returns the usable file.

getSetting

public String getSetting(String key,
                         String defaultValue)
This method returns a property value to the corresponding key. If the key is not found in the property file the input param defaultValue is returned.

Specified by:
getSetting in interface Settings
Parameters:
key - get the value for that key in the property file
defaultValue - the default value if the key is not found
Returns:
the value of the property key

getSetting

public String getSetting(String primaryKey,
                         String defaultKey,
                         String defaultValue)
This method returns a property value to the corresponding key. If the key is not found in the property file the input param defaultKey is searched. If the default key is not found the input param defaultValue is returned.

Specified by:
getSetting in interface Settings
Parameters:
primaryKey - get the value for that key in the property file
defaultKey - the default key that should be searched if the primaryKey is not found
defaultValue - the default value if the defaultKey is not found
Returns:
the value of the property key

getSettingKeys

public Vector getSettingKeys(String keyPrefix)
This method returns an array of keys in the same hierarchy of the keyPrefix. The method search all keys in the property file that has the keyPrefix as leading substring. The Object[] collects all sub keys without the keyPrefix.

Parameters:
keyPrefix - to search for sub keys
Returns:
alls keys starting with the keyPrefix

getIntSetting

public int getIntSetting(String key,
                         int defaultValue)
If a property value is number (interger) this method extracts the value and convert it to an int. If the key ist not found or the conversion fails, the defaultValue is returned.

Parameters:
key - get the value for that key in the property file
defaultValue - the default value if the key is not found
Returns:
the int value of the property key

getKeys

public ArrayList getKeys(String key)
This method returns an array of sub keys (children references) of the key. The method is a wrapper calling the method PropertyTree.getKeys(String key).

Parameters:
key - get all sub keys for that key in the property file
Returns:
an list of sub keys (type String)
See Also:
PropertyTree

getValueFromKey

public String getValueFromKey(String key)
This method returns a the first value from a key. This means the method search in the PropertyTree representation of the config file. The PropertyTree class can overload key value paires. But the config file can not overload keys. If a key is defined more than one times the last definition is stored it the property list. The method is a wrapper calling the method PropertyTree.getFirstValue(String key).

Parameters:
key - get the value for that key in the property file
Returns:
the value of the property key
See Also:
PropertyTree

getPTree

public PropertyTree getPTree()
This method returns the PropertyTree representation of the configuration file.

Returns:
Returns the pTree.
See Also:
PropertyTree

assembleTemporaryDirectoryFile

protected static File assembleTemporaryDirectoryFile()
Assembles the File of the temporary directory without checking if it really exists.


getTemporaryDirectory

public static File getTemporaryDirectory()
Returns the directory where temporary files should be stored.

If the directory doesn't exist, it is created.

Returns:
Returns the directory where temporary files should be stored.

clearTemporaryDirectory

public static void clearTemporaryDirectory()
Deletes all files in the temporary directory, if it exists.

This should be used to clear temporary files when the application shuts down.


initializeForWeb

public static void initializeForWeb(String base_dir)
Initializes the paths of the SettingsReader for web application usage.

Parameters:
base_dir - The base directory of this web application. E.g. TOMCAT_HOME/webapps/pdf-as

initializeForCommandLine

public static void initializeForCommandLine()
Initializes the paths of the SettingsReader for commanline usage.



Copyright © 2006-2007 EGIZ - E-Government Innovationszentrum. All Rights Reserved.