3. Defaults and Rules

One of the strongest features of jSettings is the use of default settings and of validation rules. Briefly, the programmer gets to define for each ini setting and for each fstab field a default value that the program uses in case one is not specified in the user files. Also, the programmer gets to define a regular expression against which all later values of the setting/field are checked and only loaded if they pass validation.

Since each setting/field will have a default value and a rule and since they both have to be loaded at the same time, before any external file, I have decided to couple them together both in this tutorial and in the files from which they are loaded. The intention is that these files would be provided together with the program and will not be edited by users, who in turn can alter the values of settings in ini and fstab files.

It is probably worth mentioning again that the default files should contain all the settings that a program will use together with their default values and validation rules. Further ini and fstab files will only modify the default values if the user wants it. Which means, that in a normal case, straight after deployment (installation) a program will only have a defaults.zip file (the name is decided by the programer) and no ini or fstab files (or empty ones just to prompt the user or files with commented values).

The validation rules are Java regular expressions (regex) - you can learn more about them at the Java API reference.

The structure of the default settings files logically follows that of the settings themselves (and of the user files too). There are several files which define the highest level of the settings structure, each of them containing several levels of sections. Each section contains its own settings and the structure is as follows:

Name Default Rule
setting1 value1 [a-zA-Z]*
setting2 2 [0-9]*

As in other cases with jSettings, values are separated by blanks. In case the setting name or the default value should contain a blank characer, the whole thing can be enclosed in brackets (or in other markers, as explained in the Advanced Topics ).


Previous Home Next
2. Settings Types Table Of Contents 4. Settings Files

Valid XHTML 1.0 Transitional