public class Environment
extends java.lang.Object
Reads and keeps in memory properties from .cnf initialization files.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PROFILES_DIR |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getEnvVar(java.lang.String sVarName)
Get value for an environment variable.
|
static java.lang.String |
getEnvVar(java.lang.String sVarName,
java.lang.String sDefault)
Get value for an environment variable.
|
static java.util.Properties |
getProfile(java.lang.String sProfile)
Get a Properties collection from a .CNF file
Property files must be in the directory pointed by a operating system environment variable names
KNOWGATE_PROFILES.
|
static boolean |
getProfileBool(java.lang.String sProfile,
java.lang.String sVarName,
boolean bDefault)
Get the value of a property that represents a boolean type.
|
static java.lang.String |
getProfilePath(java.lang.String sProfile,
java.lang.String sVarName)
Get a property from a .CNF file representing a file path.
|
static java.util.Set |
getProfilesSet()
Get a Set with all loaded profiles names
|
static java.lang.String |
getProfileVar(java.lang.String sProfile,
java.lang.String sVarName)
Get a single property from a .CNF file.
|
static java.lang.String |
getProfileVar(java.lang.String sProfile,
java.lang.String sVarName,
java.lang.String sDefault)
Get a single property from a .CNF file.
|
static java.util.Set |
getProfileVarSet(java.lang.String sProfile)
Get names of all properties in a profile
|
static java.lang.String |
getTempDir()
Get temporary directory
|
static java.util.Properties |
loadProfile(java.lang.String sProfile)
Load a Profile from a resource bundle
The loaded Profile is cached in memory and will be returned in
future calls to getProfile()
If profile had been already loaded, then it is overwritten.
|
static java.util.Properties |
loadProfile(java.lang.String sProfile,
java.lang.String sPath)
Load a Profile from a Properties file
The loaded Profile is cached in memory and will be returned in
future calls to getProfile()
If profile had been already loaded, then it is overwritten.
|
static void |
refresh()
Refresh in-memory cached properties by re-reading then from disk files.
|
static java.lang.String |
resolveEnvironmentVariables(java.lang.String sInput)
Replace values of environment variables at given string
Change all substrings of the form %[A-Z]% to the corresponding environment variables values
For example, in Windows %ProgramFiles% typically maps to "C:\Program Files" Variable matching is case sensitive |
static void |
setProfileVar(java.lang.String sProfile,
java.lang.String sVarName,
java.lang.String sVarValue)
Set value for a profile property
Value is change in memory cache but not saved to disk.
|
static void |
updateSystemTime(long lTime)
Update system time
This is an alpha testing method, do not use in production environments.
|
public static java.lang.String getEnvVar(java.lang.String sVarName) throws java.lang.IllegalArgumentException
Get value for an environment variable.
This is not a Pure Java method since it uses the Runtime obeject for calling OS specific shell commands.sVarName
- Name of the variable to be readed.java.lang.IllegalArgumentException
- If there is a Malformed \\uxxxx encoding or any other type of intrinsic error at the environment variables valuespublic static java.lang.String getEnvVar(java.lang.String sVarName, java.lang.String sDefault) throws java.lang.IllegalArgumentException
Get value for an environment variable.
This is not a Pure Java method since it uses the Runtime object for calling OS specific shell commands.sVarName
- Name of the variable to be readed.java.lang.IllegalArgumentException
public static java.lang.String getTempDir() throws java.lang.IllegalArgumentException
Get temporary directory
java.lang.IllegalArgumentException
public static java.util.Properties getProfile(java.lang.String sProfile)
Get a Properties collection from a .CNF file
Property files must be in the directory pointed by a operating system environment variable names KNOWGATE_PROFILES. If KNOWGATE_PROFILES environment variable is not found, the files will be seeked by default on C:\WINNT\ or C:\WINDOWS\ on Window Systems and /etc/ on UNIX systems.sProfile
- Properties file to read (for example "hipergate.cnf")public static java.util.Properties loadProfile(java.lang.String sProfile, java.lang.String sPath)
Load a Profile from a Properties file
The loaded Profile is cached in memory and will be returned in future calls to getProfile()
If profile had been already loaded, then it is overwritten.
sProfile
- Profile name, for example "hipergate"sPath
- Full path to properties file, fo example "/etc/knowgate/hipergate.cnf"public static java.util.Properties loadProfile(java.lang.String sProfile)
Load a Profile from a resource bundle
The loaded Profile is cached in memory and will be returned in future calls to getProfile()
If profile had been already loaded, then it is overwritten.
sProfile
- Profile name, for example "hipergate"public static java.util.Set getProfilesSet()
public static java.lang.String getProfileVar(java.lang.String sProfile, java.lang.String sVarName)
Get a single property from a .CNF file.
Properties are readed once from disk and then cached in memory. If .CNF file is changed, refresh() method must be called for refreshing in-memory cached values.
sProfile
- .CNF file namesVarName
- Property Namepublic static java.util.Set getProfileVarSet(java.lang.String sProfile)
sProfile
- Profile Namepublic static java.lang.String getProfilePath(java.lang.String sProfile, java.lang.String sVarName)
Get a property from a .CNF file representing a file path.
This method is equivalent to getProfileVar except that a file separator is always appended to the end of the readed value.
sProfile
- .CNF file namesVarName
- Property Namepublic static boolean getProfileBool(java.lang.String sProfile, java.lang.String sVarName, boolean bDefault)
Get the value of a property that represents a boolean type.
sProfile
- .CNF file namesVarName
- Property NamebDefault
- Default Valuepublic static java.lang.String getProfileVar(java.lang.String sProfile, java.lang.String sVarName, java.lang.String sDefault)
Get a single property from a .CNF file.
sProfile
- .CNF file namesVarName
- Property NamesDefault
- Default Valuepublic static void setProfileVar(java.lang.String sProfile, java.lang.String sVarName, java.lang.String sVarValue)
Set value for a profile property
Value is change in memory cache but not saved to disk.sProfile
- Profile NamesVarName
- Property NamesVarValue
- Prioperty Valuepublic static void refresh()
Refresh in-memory cached properties by re-reading then from disk files.
public static java.lang.String resolveEnvironmentVariables(java.lang.String sInput) throws java.lang.IllegalArgumentException
Replace values of environment variables at given string
Change all substrings of the form %[A-Z]% to the corresponding environment variables valuessInput
- Stringjava.lang.IllegalArgumentException
- If there is a Malformed \\uxxxx encoding or any other type of intrinsic error at the environment variables valuespublic static void updateSystemTime(long lTime)
Update system time
This is an alpha testing method, do not use in production environments.
lTime
- New System Date