public class StanzaIni extends java.lang.Object implements EnvironmentReader
The INI file like other INI files in Windows allow to use the comment and empty strings to be added into. Every line beginning with ';' char is considered as comment line. The INI file allows section or key-value pair duplications. Only first encountered section or key-value pair will be meaningful in this case, the other will be ignored. This is important to know because after deletion the section or key the modified INI file is reloading and previously ignored section or key-value pair become active.
Another note is some functionality is very strange for CHUI client mode on Windows. It does not follow the description in Progress ABL command reference book. All such 'bugs' are duplicated here. It is getting the key or section list and removing the key-value pair or section.
Modifier and Type | Field and Description |
---|---|
private java.util.List<Content> |
contList
The ordered list of INI file content.
|
private java.lang.String |
envName
The name of the environment.
|
private boolean |
isChui
Flag indicating the type of the client running, either CHUI or Windows graphical UI.
|
private boolean |
isNew
The flag indicating whether we need to create new file instead of opening existed one.
|
private boolean |
isReadOnly
INI files read only property
|
private java.lang.String |
name
The name of the INI file that holds the environment variables.
|
private java.util.Map<java.lang.String,Content> |
sectMap
The map that caches the INI file sections without any comments.
|
private java.lang.String |
workingDirectory
Working directory value to search the INI file.
|
TYPE_INI, TYPE_REG
Constructor and Description |
---|
StanzaIni(java.lang.String env,
java.lang.String directory,
boolean flagNew,
boolean readOnly)
Constructs an instance of the environment with INI file as backend.
|
Modifier and Type | Method and Description |
---|---|
private void |
commitIniFile()
Writes the current environment set to the appropriate INI file in file system.
|
private boolean |
createEmptyIniFile()
Creates the empty INI file for current environment set in file system.
|
java.lang.String |
getEnvironmentName()
Get the environment's name.
|
java.lang.String |
getEnvironmentType()
Get the environment's type.
|
private java.lang.String |
getFullIniFileName()
Reconstructs full initial file name with possible path.
|
private java.lang.String |
getKeys(java.lang.String section)
Getting the comma-separated list of the keys for the given section.
|
java.lang.String |
getKeyValue(java.lang.String section,
java.lang.String key)
Getting the key value from the current environment.
|
private SectionContent |
getSection(java.lang.String name)
Getting the object that holds the section from the previously formed environment.
|
private java.lang.String |
getSections()
Getting the comma-separated list of the keys for the given section.
|
boolean |
load()
Creates application defaults implementing Progress LOAD statement.
|
private boolean |
loadIniFile()
Reads the current environment set from appropriate INI file in file system.
|
private java.io.BufferedReader |
openReader(java.lang.String fileName)
Open an INI file reader.
|
private void |
reloadIniFile()
Reloads the INI file replacing the given internal maps with the new ones from changed INI
file taken from file system.
|
private void |
removeKey(java.lang.String section,
java.lang.String key)
Removing the given key-value pair from the current environment in a given section.
|
private void |
removeSection(java.lang.String section)
Removing the given section with all key-value pairs from the current environment.
|
void |
setKeyValue(java.lang.String section,
java.lang.String key,
java.lang.String value)
Adds, modifies and deletes keys in current environment.
|
void |
unload()
Unloads specifies environment from the current one.
|
private java.lang.String name
private java.lang.String envName
private java.lang.String workingDirectory
private boolean isNew
private boolean isChui
private boolean isReadOnly
private java.util.List<Content> contList
private java.util.Map<java.lang.String,Content> sectMap
public StanzaIni(java.lang.String env, java.lang.String directory, boolean flagNew, boolean readOnly)
env
- The environment to create or load. The name without extension of the initialization
file.directory
- The directory path for existing initialization file or place to create
initialization file.flagNew
- If true
- the new file will be created overwriting the possibly
existed one.readOnly
- If true
INI files are loaded from server jar files otherwise from
client file system.public boolean load()
load
in interface EnvironmentReader
true
if loaded false otherwisepublic void setKeyValue(java.lang.String section, java.lang.String key, java.lang.String value)
The other possible cases are("" means the parameter is null or empty string if the difference is not important): key == "" deletes the given section with all it's content from the INI file. value == "" removes the key-value pair from the given section of the current INI file.
setKeyValue
in interface EnvironmentReader
section
- The name of the section containing the key to modify.key
- The name of the key key to modify or default key if not specified.value
- The new value of the key under modification.public java.lang.String getKeyValue(java.lang.String section, java.lang.String key)
The other possible cases are("" means the parameter is null or empty string if the difference is not important): section == "" gets the comma separated list of all sections for the current INI file. key == "" gets the comma separated list of all keys for the given section for the current INI file.
getKeyValue
in interface EnvironmentReader
section
- The name of the section containing the key to get.key
- The name of the key to get or default key if not specified.public void unload()
unload
in interface EnvironmentReader
public java.lang.String getEnvironmentName()
getEnvironmentName
in interface EnvironmentReader
public java.lang.String getEnvironmentType()
getEnvironmentType
in interface EnvironmentReader
private void removeSection(java.lang.String section)
section
- The name of the whole section to delete.private void removeKey(java.lang.String section, java.lang.String key)
section
- The name of the section to delete the key-value pair.key
- The name of the key to delete with its value.private java.lang.String getSections()
private java.lang.String getKeys(java.lang.String section)
section
- The name of the section to analyze.private SectionContent getSection(java.lang.String name)
name
- The name of the section to look for.private java.lang.String getFullIniFileName()
private java.io.BufferedReader openReader(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- INI File name.java.io.FileNotFoundException
- if file not foundprivate boolean loadIniFile()
true
if loaded false otherwise.private boolean createEmptyIniFile()
private void commitIniFile()
private void reloadIniFile()