Class PropertiesManager

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class PropertiesManager extends Properties
Reads and writes Java properties files. Properties files can be on disc or contained within a Jar file.
Version:
$Id: PropertiesManager.java,v 1.6 2009/03/20 23:33:54 jweather Exp $
Author:
John Weatherley
See Also:
  • Constructor Details

    • PropertiesManager

      public PropertiesManager()
      Create an unloaded Properties object. Same as Properties().
    • PropertiesManager

      public PropertiesManager(String propsFileName) throws IOException
      Create and load this Properties hash map from the given Properties file or properties resource located in the jar.
      Parameters:
      propsFileName - The name of the Properties file to load or URL to the properties location inside a jar
      Throws:
      IOException - If unable to load the properties.
  • Method Details

    • loadPropertiesFile

      public void loadPropertiesFile() throws IOException
      Loads or re-loads the properties from its file or JAR, replacing all previously loaded properties, if any. If the file or JAR is not configured, does nothing.
      Throws:
      IOException - If error
    • writePropsFile

      public void writePropsFile() throws IOException
      Writes the properties to the same file that was used to read them, preserving any comments in the file. If the original file was contained in a jar then an I/O excetion is thrown.
      Throws:
      IOException - If error in input/output
    • writePropsFile

      public void writePropsFile(String propsFilePath) throws IOException
      Writes the properties to the given file path. If the file path is the same as the one used to upen this file, then all comments in the file are preserved.
      Parameters:
      propsFilePath - The full path to the props file to be written.
      Throws:
      IOException - If error in input/output
    • getProp

      public String getProp(String property, String defaultValue) throws Exception
      Retrieves the property value from this object's property file. If the property does not exist and a default value is specified, the default is set in the Properties and is returned.
      Parameters:
      property - The property sting to retrieve
      defaultValue - The default value for this property, if none is found
      Returns:
      The prop value
      Throws:
      Exception - If error
    • getPropAsInt

      public int getPropAsInt(String property, String defaultValue) throws Exception
      Same as the getProp(String,String) method only it returns it's parameter as an integer.
      Parameters:
      property - The property sting to retrieve
      defaultValue - The default value for this property, if none is found
      Returns:
      The prop value
      Throws:
      Exception - If error
    • getPropAsBoolean

      public boolean getPropAsBoolean(String property, String defaultValue) throws Exception
      Same as the getProp(String,String) method only it returns it's parameter as a boolean. Possible inputs are [yes|no|true|false|on|off|enabled|disabled].
      Parameters:
      property - The property sting to retrieve
      defaultValue - The default value for this property, if none is found
      Returns:
      The prop value
      Throws:
      Exception - If error