net.sourceforge.drpetrea.jsettings
Class jSettings

Object
  extended by jSettings

public class jSettings
extends Object

This class is meant to act as an interface to the other jsettings classes for ease of use. It holds the two static maps of settings (ini and fstab) that will be modified by the other classes and will be available to the user by means of methods. Please mind the large choice of constructors - the ones that are missing some 'regular' arguments have some boolean arguments in place that never get used so the user can differentiate between the different constructors. Only the last boolean argument ("hierarchical") is used. All the constructor take ArrayLists of Strings as arguments and not simple strings because of the complexity of writtin all the possible constructors. I don't believe it will be added later, so here's a quick-and-dirty trick for making a one-element ArrayList of String

new ArrayList(Arrays.asList(new String[]{"your_string_here"}))

If you figure out a nicer way to do this, please drop me a line.

Author:
Dragos Petre
See Also:
IniSettings, FstabSettings

Nested Class Summary
static class jSettings.FstabModification
          The class that maintains the changes to the fstab settings.
static class jSettings.IniModification
          The class that maintains the changes to the ini settings.
 
Field Summary
static LocaleTools lt
          The LocaleTools object.
 
Constructor Summary
jSettings()
          The constructor that takes the default arguments
jSettings(ArrayList<String> DefaultPaths, ArrayList<String> DefaultNames, ArrayList<String> SystemPaths, ArrayList<String> SystemNames, ArrayList<String> UserPaths, ArrayList<String> UserNames)
          The most extended constructor to use - specifies the paths and the names of the default settings file and of the system-wide and user settings files.
jSettings(ArrayList<String> DefaultPaths, ArrayList<String> DefaultNames, ArrayList<String> SystemPaths, ArrayList<String> SystemNames, ArrayList<String> UserPaths, ArrayList<String> UserNames, boolean hierarchical)
          The most extended constructor to use - specifies the paths and the names of the default settings file and of the system-wide and user settings files.
 
Method Summary
static boolean addFstabRow(String section, ArrayList<String> row, boolean system)
          The method adds a row to the specified section and makes sure the action can be latter reflected in the settings files
static boolean deleteFstabRow(String section, ArrayList<String> row, boolean system)
          The method deletes the specified row from the specified section and makes sure the action can be latter reflected in the settings files
static void flushChanges()
          Puts the changes made by the user to the settings into the settings files.
static ArrayList<String> FstabSections()
          The method returns the names of all the available fstab sections
static FstabSettings FstabSetting(String name)
          The method returns a reference to the desired FstabSetting object
static ArrayList<jSettings.FstabModification> getFstabModifications()
          The method returns an ArrayList of all the jSettings.FstabModification objects recorded.
static ArrayList<jSettings.IniModification> getIniModifications()
          The method returns an ArrayList of all the jSettings.IniModification objects recorded.
static ArrayList<jSettings.IniModification> getIniModifications(String section, String setting)
          The method returns an ArrayList of the IniModification objects recorded for the specific section and setting.
static ArrayList<String> IniSections()
          The method returns the names of all the available ini sections
static ArrayList<String> IniSections(String setting)
          The method returns the names of all the ini sections in which a setting is found
static IniSettings IniSetting(String name)
          The method returns a reference to the desired IniSettings object
static String modifyFstab(String section, ArrayList<String> row, int field, String value, boolean system)
          The method modifies one field in a specific row of a specific section.
static String modifyFstab(String section, ArrayList<String> row, String field, String value, boolean system)
          The method modifies one field in a specific row of a specific section.
static String modifyIni(String section, String name, String value, boolean system)
          The method modifies an existing ini setting.
static ArrayList<String> undoFstabMemory(jSettings.FstabModification fm)
          The method undos a change to the Fstab Settings described by fm if it exists.
static String undoIniMemory(jSettings.IniModification im)
          The method undos the change described by the im object if such a change was made.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lt

public static LocaleTools lt
The LocaleTools object.

Constructor Detail

jSettings

public jSettings(ArrayList<String> DefaultPaths,
                 ArrayList<String> DefaultNames,
                 ArrayList<String> SystemPaths,
                 ArrayList<String> SystemNames,
                 ArrayList<String> UserPaths,
                 ArrayList<String> UserNames,
                 boolean hierarchical)
The most extended constructor to use - specifies the paths and the names of the default settings file and of the system-wide and user settings files. The user specific settings are loaded after the system-wide ones so that they can overwrite anything.

Because of complexity I took out the possibility of skipping some arguments - if you would rather use the default, please give as argument null.

Parameters:
DefaultPaths - The places where the zip with the default settings can be found
DefaultNames - The possible names of the default settings file
SystemPaths - The possible paths where the system-wide settings files can be found
SystemNames - The possible names of the system-wide settings files
UserPaths - The places where the user settings file can be found
UserNames - The possible names of the user settings files
hierarchical - True if the files should produce a hierarchical settings structure

jSettings

public jSettings(ArrayList<String> DefaultPaths,
                 ArrayList<String> DefaultNames,
                 ArrayList<String> SystemPaths,
                 ArrayList<String> SystemNames,
                 ArrayList<String> UserPaths,
                 ArrayList<String> UserNames)
The most extended constructor to use - specifies the paths and the names of the default settings file and of the system-wide and user settings files. The user specific settings are loaded after the system-wide ones so that they can overwrite anything.

Parameters:
DefaultPaths - The places where the zip with the default settings can be found
DefaultNames - The possible names of the default settings file
SystemPaths - The possible paths where the system-wide settings files can be found
SystemNames - The possible names of the system-wide settings files
UserPaths - The places where the user settings file can be found
UserNames - The possible names of the user settings files

jSettings

public jSettings()
The constructor that takes the default arguments

Method Detail

modifyIni

public static String modifyIni(String section,
                               String name,
                               String value,
                               boolean system)
The method modifies an existing ini setting. It will not add a setting in case it does not exist - the point is that in the framework of the jSettings class, all possible setting get added from the default files, so there's no possible extra setting to be added. Use this method to change the settings if you would like the changes to be latter undone or written to the setting files - using directly the IniSettings.putValue() method does not facilitate that.

Parameters:
section - The full section name, including the delimiters in case of hierarchically organized sections
name - The name of the setting
value - The new value for the setting. null means the setting will be deleted from the system-wide or user-specific files and it's value therefore reversed to the default value one level up. However, this change will be effective the next time the files will be loaded. If you want it to also be effective immediately, you will have to invoke before it a modifyIni with the new argument.
system - A flag that lets the user chose wheather the modified setting will affect the system-wide settings (true) or only the current user's settings (false).
Returns:
The current value of the setting. In case the operatiion is not successful because the section does not exist at all or the setting does not exist in the specified section, then it returns null.
See Also:
IniSettings

modifyFstab

public static String modifyFstab(String section,
                                 ArrayList<String> row,
                                 String field,
                                 String value,
                                 boolean system)
The method modifies one field in a specific row of a specific section. It insures that the modfications made are kept in the memory so that they can be latter flushed to the settings files.

Parameters:
section - The name of the Section which contains the desired row
row - The index of the row in which the change need to be made
field - The name of the field in which the change is to be made
value - The new value to be written
system - A flag that lets the user chose wheather the modified setting will affect the system-wide settings (true) or only the current user's settings (false).
Returns:
The previous value in the field or null if the operation fails

modifyFstab

public static String modifyFstab(String section,
                                 ArrayList<String> row,
                                 int field,
                                 String value,
                                 boolean system)
The method modifies one field in a specific row of a specific section. It insures that the modfications made are kept in the memory so that they can be latter flushed to the settings files.

Parameters:
section - The name of the Section which contains the desired row
row - The index of the row in which the change need to be made
field - The index of the field in which the change is to be made
value - The new value to be written
system - A flag that lets the user chose wheather the modified setting will affect the system-wide settings (true) or only the current user's settings (false).
Returns:
The previous value in the field or null if the operation fails

deleteFstabRow

public static boolean deleteFstabRow(String section,
                                     ArrayList<String> row,
                                     boolean system)
The method deletes the specified row from the specified section and makes sure the action can be latter reflected in the settings files

Parameters:
section - The name of the fstab section
row - The row to be deleted
system - A flag that lets the user chose wheather the modified setting will affect the system-wide settings (true) or only the current user's settings (false).
Returns:
true if the operation succeded, false otherwise

addFstabRow

public static boolean addFstabRow(String section,
                                  ArrayList<String> row,
                                  boolean system)
The method adds a row to the specified section and makes sure the action can be latter reflected in the settings files

Parameters:
section - The name of the fstab section
row - The ArrayList containing the new values
system - A flag that lets the user chose wheather the modified setting will affect the system-wide settings (true) or only the current user's settings (false).
Returns:
true if the operation succeded, false otherwise

IniSetting

public static IniSettings IniSetting(String name)
The method returns a reference to the desired IniSettings object

Parameters:
name - The name of the IniSettings object - the section
Returns:
The IniSettings object if it exists, null if it doesn't

FstabSetting

public static FstabSettings FstabSetting(String name)
The method returns a reference to the desired FstabSetting object

Parameters:
name - The name of the FstabSettings object - the section
Returns:
The IniSettings object if it exists, null if it doesn't

IniSections

public static ArrayList<String> IniSections()
The method returns the names of all the available ini sections

Returns:
An ArrayList of the available ini sections.

FstabSections

public static ArrayList<String> FstabSections()
The method returns the names of all the available fstab sections

Returns:
An ArrayList of the available fstab sections.

IniSections

public static ArrayList<String> IniSections(String setting)
The method returns the names of all the ini sections in which a setting is found

Parameters:
setting - The sought setting name.
Returns:
An ArrayList of the ini sections that contain that setting.

flushChanges

public static void flushChanges()
Puts the changes made by the user to the settings into the settings files. The behaviour of the method is the following: the name of each setting changed through the provided methods (modifyIni and modifyFstab) will indicate in which file the change has to be effected and the system-wide flag will provide the path (the class maintains lists of paths to system- and user-wide settings file, therefore easily being able to distinguish between them).

If the file in which the setting belongs exists (e.g. setting File1:Setting1-1 will require a file called File1.ini to exist), the method looks for the existance of a declaration of that setting. If it exists, it will modify its value. If it doesn't it will add it in the appropriate section.

If the file doesn't exist, it will be created in the system- or user-path (given that the user has permission to do so) and than it will add the setting and the value to it.

If there are several files with the same name in different paths, the change will be made to the last one in order of processing which insures that the value will not be overwritten.

This approach is a bit of a brute-force, since it does not consider for example grouping settings by file and then operating them in one place etc. Possibly in the future, changes will be made, but for now the overhead is considered to be aceptable from these operations.


undoFstabMemory

public static ArrayList<String> undoFstabMemory(jSettings.FstabModification fm)
The method undos a change to the Fstab Settings described by fm if it exists.

Parameters:
fm - The jSettings.FstabModification object. One can get it through the getFstabModifications() methods.
Returns:
An ArrayList containing the added/deleted row; if the operation was the modification of a value, the ArrayList will only have one element and that would be the restored value. If the operation fails it returns null.

undoIniMemory

public static String undoIniMemory(jSettings.IniModification im)
The method undos the change described by the im object if such a change was made.

Parameters:
im - The jSettings.IniModification object. One can get it through the getIniModifications() methods.
Returns:
The restored value for setting, if the operation was not successful, returns null.

getIniModifications

public static ArrayList<jSettings.IniModification> getIniModifications(String section,
                                                                       String setting)
The method returns an ArrayList of the IniModification objects recorded for the specific section and setting.

Parameters:
section - The requested section name
setting - The requested setting name
Returns:
An ArrayList of IniModification.

getIniModifications

public static ArrayList<jSettings.IniModification> getIniModifications()
The method returns an ArrayList of all the jSettings.IniModification objects recorded.

Returns:
All the modifications made.

getFstabModifications

public static ArrayList<jSettings.FstabModification> getFstabModifications()
The method returns an ArrayList of all the jSettings.FstabModification objects recorded.

Returns:
All the modifications made.