Class FWImagePropertyProvider
java.lang.Object
net.simplace.core.property.FWImagePropertyProvider
Provider for properties. It centralizes access
to properties throughout the whole application. In
addition to making direct access to property files
obsolete it also caches whole sets of properties (i.e.
property files) by keeping them in memory. A property
set is loaded into memory when any of the properties
contained in it is being accessed for the first time.
Works with Java .properties files on the classpath. Changed values are written to a cache file in
~/tmp/properties, which is read instead of the original file afterwards. The original values stay
available (see getOriginalProperty(String, String, String)).
- Author:
- Andreas Enders
-
Method Summary
Modifier and TypeMethodDescriptionbooleanflushProperty(String aPropertySet, String aKey) Resets one property to its value in the original file (the cache file is updated).booleanflushPropertySet(String aPropertySet) Flush a property set, i.e.static FWImagePropertyProviderstatic StringgetJavaRuntimeVariable(String aKey) Returns a Java system property with forward slashes.getOriginalProperty(String aPropertySet, String aKey, String aDefault) Get the value of a property in a specific set.getOriginalPropertyNames(String aPropertySet) getOriginalPropertySet(String aPropertySetName) Get a specific property set, by replacing the System variables in the values.getProperties(String aPropertySet) Can cause data corruption in property resource manager, so better use getPropertyNames(...) to get an enumeration of property names and then iterate over this enumeration and invoke getProperty(...) for each name.getPropertiesAsString(String aPropertyset) getProperty(String aPropertySet, String aKey) Get the value of a property in a specific set.getProperty(String aPropertySet, String aKey, String aDefault) Get the value of a property in a specific set.getPropertyNames(String aPropertySet) getPropertySetURL(String aPropertySet) Get the value of for the given property or if the Returns an environment variable, or else the Java system property with this name.static StringGets the value for a given registry key.replaceSystemVariables(String aPropertyValue) Replaces one system variable in a property value:%{registry key}(registry),%NAME%(environment),${name}(Java runtime) or$NAME$(environment).booleansetProperty(String aPropertySet, String aKey, String aValue) Set the value for a specified key within a specified property set and make those settings persistent, so the next time the application is started the set value is still available.booleansetProperty(String aPropertySet, String aKey, String aValue, boolean aNewValue) Set the value for a specified key within a specified property set and make those settings persistent, so the next time the application is started the set value is still available.booleansetPropertyToOriginalFile(String aPropertySet, String aKey, String aValue) Set the value for a specified key within a specified property set original location and make those settings persistent.No restarting of application is required.static booleansetSystemEnvironmentVariable(String aKey, String aValue) Deprecated.has no effect
-
Method Details
-
getInstance
- Returns:
- Singleton instance of PropertyProvider.
-
flushPropertySet
Flush a property set, i.e. delete it from memory and also reset the entries in the cache file. This allows runtime modifications of property files using external tools, because it forces the resource manager to re-read the properties from the original file. Returnstrueif flushing is successful andfalseif flushing fails.- Parameters:
aPropertySet- name of the property set- Returns:
trueif successful (also if there was no cache file)
-
flushProperty
-
getProperty
Get the value of a property in a specific set. If the set doesn't contain a value for the given property return the specified default value.- Parameters:
aPropertySet- name of the property setaKey- the property keyaDefault- value returned if the property is missing- Returns:
- the property value with system variables replaced, or the default
-
getProperty
Get the value of a property in a specific set. If the set doesn't contain a value for the given property or if the set doesn't exist anyway returnnull(a warning is logged).- Parameters:
aPropertySet- name of the property setaKey- the property key- Returns:
- the property value with system variables replaced, or
null
-
getOriginalProperty
Get the value of a property in a specific set. If the set doesn't contain a value for the given property return the specified default value. The value is read from the original file, not from the cache file.- Parameters:
aPropertySet- name of the property setaKey- the property keyaDefault- value returned if the property is missing- Returns:
- the original property value with system variables replaced, or the default
-
getOriginalPropertySet
Get a specific property set, by replacing the System variables in the values. Mostly used in the clients to cache the whole property set.- Parameters:
aPropertySetName- name of the property set- Returns:
- a copy of the original property set with system variables replaced, or
nullif not found
-
getSystemEnvironmentVariable
-
getSystemRegistryVariable
Gets the value for a given registry key. A registry key is composed of a registry root key and path. If the registry key is not present or can not be found (non-Windows systems)nullis returned. Windows registry values are stored by root key and path. The parameterregistryKeycontains the following format:ROOT_KEY\PATH\VALUEfor a specific value orROOT_KEY\PATH\to return the default value. ExampleregistryKeyvalues:HKEY_CURRENT_USER\Environment\JAVA_HOMEHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Search\SearchAssistantHKEY_CLASSES_ROOT\Shell\shell\open\command\Supported root key values are:HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_DYN_DATA HKEY_LOCAL_MACHINE HKEY_PERFORMANCE_DATA HKEY_USERSCallinggetSystemRegistryVariable("HKEY_CLASSES_ROOT\Shell\shell\open\command\")would return%SystemRoot%\Explorer.exe /idlist,%I,%Lon a typical Windows installation.- Parameters:
aKey- the registry keyROOT_KEY\PATH\VALUE- Returns:
- the registry value, or
null
-
getJavaRuntimeVariable
-
setSystemEnvironmentVariable
Deprecated.has no effectNot supported: a Java process cannot change its own environment variables (runningsetin a shell only affected that child process). A warning is logged.- Parameters:
aKey- the variable nameaValue- the value- Returns:
- always
false
-
setProperty
Set the value for a specified key within a specified property set and make those settings persistent, so the next time the application is started the set value is still available. This is essential for adding user settings capabilities to applications. The key given as a parameter to this method must exist in the (original) property set. No new keys can be added. If the key does not exist the method will returnfalselike in any other case of an error.- Parameters:
aPropertySet- name of the property setaKey- the property key (must exist)aValue- the new value;nullremoves the property- Returns:
trueif the cache file was written
-
setProperty
Set the value for a specified key within a specified property set and make those settings persistent, so the next time the application is started the set value is still available. This is essential for adding user settings capabilities to applications. The key given as a parameter to this method must exist in the (original) property set. No new keys can be added. If the key does not exist the method will returnfalselike in any other case of an error. The property set is written to its cache file; line breaks are stored as\n.- Parameters:
aPropertySet- name of the property setaKey- the property keyaValue- the new value;nullremoves the propertyaNewValue-trueto allow adding a new key- Returns:
trueif the cache file was written
-
setPropertyToOriginalFile
Set the value for a specified key within a specified property set original location and make those settings persistent.No restarting of application is required. This is essential for adding user settings capabilities to applications. The key given as a parameter to this method must exist in the (original) property set. No new keys can be added. If the key does not exist the method will returnfalselike in any other case of an error. Cannot be used if the original file is in a jar-file. The file is rewritten line by line, only the line of the key is changed.- Parameters:
aPropertySet- name of the property setaKey- the property key (must exist)aValue- the new value- Returns:
trueif the original file was written
-
getProperties
Can cause data corruption in property resource manager, so better use getPropertyNames(...) to get an enumeration of property names and then iterate over this enumeration and invoke getProperty(...) for each name.- Parameters:
aPropertySet- name of the property set- Returns:
- the complete Properties object (from the cache file if present), or
nullif not found
-
getPropertyNames
- Parameters:
aPropertySet- name of the property set- Returns:
- an Enumeration of the property names contained in the specified property set, or
nullif the property set can't be found
-
getOriginalPropertyNames
- Parameters:
aPropertySet- name of the property set- Returns:
- an Enumeration of the property names contained in the original file, or
nullif the property set can't be found
-
getPropertySetURL
-
getEnvVars
- Returns:
- the environment-variables.
-
replaceSystemVariables
Replaces one system variable in a property value:%{registry key}(registry),%NAME%(environment),${name}(Java runtime) or$NAME$(environment). Only the first kind found is replaced.- Parameters:
aPropertyValue- the property value- Returns:
- the value with the variable replaced, or the unchanged value on errors (logged)
-
getPropertiesAsString
-