org.pf.settings.rw
Class PropertiesReaderWriter

java.lang.Object
  extended by org.pf.settings.rw.AbstractSettingsReaderWriter
      extended by org.pf.settings.rw.AbstractSettingsFileReaderWriter
          extended by org.pf.settings.rw.PropertiesReaderWriter
All Implemented Interfaces:
SettingsFileReader, SettingsReader, SettingsWriter

public class PropertiesReaderWriter
extends AbstractSettingsFileReaderWriter

A reader that can load a properties file into a settings object.

Version:
1.7
Author:
Manfred Duchrow

Constructor Summary
PropertiesReaderWriter()
          Create a new reader for properties file.
PropertiesReaderWriter(FileLocator locator)
          Create a new reader for properties file that loads from the file specified by the given locator.
PropertiesReaderWriter(FileLocator locator, java.lang.String charsetName)
          Create a new reader for properties file that loads from the file specified by the given locator using the specified character encoding.
PropertiesReaderWriter(java.lang.String filename)
          Create a new reader for properties file that loads from a file with the given name.
PropertiesReaderWriter(java.lang.String filename, java.lang.String charsetName)
          Create a new reader for properties file that loads from a file with the given name using the specified character encoding.
 
Method Summary
 boolean getBackslashIsEscapeChar()
          Sets whether or not backslashes should be treated as escape character.
static Settings loadSettings(FileLocator locator, java.lang.Class settingsClass)
          Loads the properties from the specified file and returns them as settings.
static Settings loadSettings(java.lang.String filename, java.lang.Class settingsClass)
          Loads the properties from the specified file and returns them as settings.
static Settings propertiesToSettings(java.util.Properties properties, java.lang.Class settingsClass)
          Converts the given properties object to a settings object and returns it.
 void setBackslashIsEscapeChar(boolean newValue)
          Returns whether or not backslashes should be treated as escape character.
 boolean storeSettings(Settings settings)
          Stores the given settings to the file with this object's filename in the format of Java properties files.
 
Methods inherited from class org.pf.settings.rw.AbstractSettingsFileReaderWriter
getEncoding, getFileName, loadSettings, loadSettingsFrom, loadSettingsFrom, setEncoding, setFileName
 
Methods inherited from class org.pf.settings.rw.AbstractSettingsReaderWriter
loadSettings
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pf.settings.SettingsReader
loadSettings
 

Constructor Detail

PropertiesReaderWriter

public PropertiesReaderWriter()
Create a new reader for properties file.


PropertiesReaderWriter

public PropertiesReaderWriter(java.lang.String filename)
Create a new reader for properties file that loads from a file with the given name.

Parameters:
filename - The name of the file to read from

PropertiesReaderWriter

public PropertiesReaderWriter(java.lang.String filename,
                              java.lang.String charsetName)
Create a new reader for properties file that loads from a file with the given name using the specified character encoding.

Parameters:
filename - The name of the file to read from
charsetName - The character encoding (e.g. "UTF-8") or null

PropertiesReaderWriter

public PropertiesReaderWriter(FileLocator locator)
Create a new reader for properties file that loads from the file specified by the given locator.

Parameters:
locator - The locator that points to the file to read from

PropertiesReaderWriter

public PropertiesReaderWriter(FileLocator locator,
                              java.lang.String charsetName)
Create a new reader for properties file that loads from the file specified by the given locator using the specified character encoding.

Parameters:
locator - The locator that points to the file to read from
charsetName - The character encoding (e.g. "UTF-8") or null
Method Detail

getBackslashIsEscapeChar

public boolean getBackslashIsEscapeChar()
Sets whether or not backslashes should be treated as escape character.


setBackslashIsEscapeChar

public void setBackslashIsEscapeChar(boolean newValue)
Returns whether or not backslashes should be treated as escape character.


propertiesToSettings

public static Settings propertiesToSettings(java.util.Properties properties,
                                            java.lang.Class settingsClass)
Converts the given properties object to a settings object and returns it.


loadSettings

public static Settings loadSettings(java.lang.String filename,
                                    java.lang.Class settingsClass)
Loads the properties from the specified file and returns them as settings.

Parameters:
filename - The name of the properties file.
settingsClass - The class that implements the Settings interface of which an instance will be created

loadSettings

public static Settings loadSettings(FileLocator locator,
                                    java.lang.Class settingsClass)
Loads the properties from the specified file and returns them as settings.

Parameters:
locator - The locator that points to the properties file.
settingsClass - The class that implements the Settings interface of which an instance will be created

storeSettings

public boolean storeSettings(Settings settings)
Stores the given settings to the file with this object's filename in the format of Java properties files.

Parameters:
settings - The settings to store
Returns:
true, if the settings have been successfully stored. Otherwise false.