Package net.sourceforge.drpetrea.jsettings

This package holds the framework for loading settings into a program from external files, managing them (adding, deleting, modifying and validating) and flushing the changes back to files.

See:
          Description

Class Summary
DefaultSettingsLoader This class is used for loading the defaults and the rules for validating the settings of the program.
FstabSettings This is a generic class for handling settings.
IniSettings This is a generic class for handling settings.
jSettings This class is meant to act as an interface to the other jsettings classes for ease of use.
jSettings.FstabModification The class that maintains the changes to the fstab settings.
jSettings.IniModification The class that maintains the changes to the ini settings.
SettingsLoader This class is used for loading the settings of the program.
 

Package net.sourceforge.drpetrea.jsettings Description

This package holds the framework for loading settings into a program from external files, managing them (adding, deleting, modifying and validating) and flushing the changes back to files. For the moment, the package handles ini-type files (IniSettings) and fstab-type files (FstabSettings). Further file types (probably xml amonst others) can be added in the future, but only if there will seem to be demand for it. Also, there is support for dealing with system-wide and user-specific settings files.

One of the key features of the library is support for default values for the settings. The intention is for the developer of a program that uses settings to distribute it with a zip file containing the default settings and the validation laws for the respective program. That takes the settings that would normally be hard-coded into the application and puts them into a centralized place where it can easily be more easily maintained. The library provides also support for defining regular expressions for validating the settings, both the default values and the values that may be added/changed by the user at a later stage.

For example, if you have a setting intended to hold the number of retries for an operation you would probably want it to be numeric and therefore you may define such a rule for this setting. All values are handled as String (so conversion from String to its intended usage type lays with the programmer) which means that Java regular expressions can be used.

There are several ways to use the package. Its main intended use would be something like the following:

// All the below arguments are ArrayList with their contents being obvious from the names.

jSettings js = new jSettings(DefaultPaths,DefaultNames, SystemPaths, SystemNames,UserPaths,UserNames);

//Read the value of an Ini-type setting.

System.out.println(js.IniSetting("settings:section1").getValue("setting1"));

//Modify the value of an Ini-type setting. The value will be checked against the laws defined in the default files.

js.modifyIni("settings","section1","settings1","newValue");

//Get all the fstab rows.

System.out.println(js.FstabSetting("fstab:section1").getRows());

//Get all the fstab rows containing "value" in field 2

System.out.println(js.FstabSetting("fstab:section1").getRowsForValue("value",2));

//Get from the rows returned above the values in field 3.

//Basically it returns the values in field 3 corresponding to "value" in field 2.

System.out.println(js.FstabSetting("fstab:section1").getValuesForValue("value",2,3));

//Add a row (an ArrayList) to the system-wide settings (true)

System.out.println(js.addFstabRow("fstab:section1", row, true));

//Delete a row (an ArrayList) from the user-specific settings (false)

System.out.println(js.addFstabRow("fstab:section1", row, false));

//Modify the value of field 4 in all occurances of row to newValue in the system-wide settings

System.out.println(js.modifyFstab("fstab:section1",row,4,newValue,true);

//Flush all the changes made to files - this is when the previous booleans regarding

//system-wide or user-specific changes come in place. The changes affect the same set

//of settings used for the functioning of the application, but their changes are effected

//to different files on the file system. (e.g. in a Unix environment, the system-wide

//changes will be flushed to /etc/applicationrc, while the user-specific ones will be made

//to ~/.applicationrc).

js.flushChanges();