|
Flying Saucer Project Release ${app.version} | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xhtmlrenderer.util.Configuration
public class Configuration
Stores runtime configuration information for application parameters that may
vary on restarting. This implements the Singleton pattern, but through static
methods. That is, the first time Configuration is used, the properties are
loaded into the Singleton instance. Subsequent calls to valueFor() retrieve
values from the Singleton. To look up a property, use
valueFor(String)
.
Properties may be overridden using a second properties file, or individually using System properties specified on the command line. To override using a second properties file, specify the System property xr-conf. This should be the location of the second file relative to the CLASSPATH, or else a file path, e.g.
java -Dxr-conf=resources/conf/myprops.conf
You can also place your override properties file in your user home directory, in
${user.home}/.flyingsaucer/local.xhtmlrenderer.conf
To override a property using the System properties, just re-define the property on the command line. e.g.
java -Dxr.property-name=new_value
The order in which these will be read is: default properties (bundled with the core, in the jar; override configuration properties; properties file in user.home; and system properties.
You can override as many properties as you like.
Note that overrides are driven by the property names in the default configuration file. Specifying a property name not in that file will have no effect--the property will not be loaded or available for lookup. Configuration is NOT used to control logging levels or output; see LogStartupConfig.
There are convenience converstion method for all the primitive types, in
methods like valueAsInt(String, int)
. A default must always be provided for these
methods. The default is returned if the value is not found, or if the
conversion from String fails. If the value is not present, or the conversion
fails, a warning message is written to the log.
Method Summary | |
---|---|
static boolean |
hasValue(java.lang.String key)
|
static boolean |
isFalse(java.lang.String key,
boolean defaultVal)
Returns true if the value is not "true" (ignores case), or the default provided value if not found or if the value is not a valid boolean (true or false, ignores case). |
static boolean |
isTrue(java.lang.String key,
boolean defaultVal)
Returns true if the value is "true" (ignores case), or the default provided value if not found or if the value is not a valid boolean (true or false, ignores case). |
static java.util.Iterator |
keysByPrefix(java.lang.String prefix)
Returns all configuration keys that start with prefix. |
static void |
main(java.lang.String[] args)
Command-line execution for testing. |
static void |
setConfigLogger(java.util.logging.Logger logger)
Sets the logger which we use for Configuration-related logging. |
static int |
valueAsByte(java.lang.String key,
byte defaultVal)
Returns the value for key in the Configuration as a byte, or the default provided value if not found or if the value is not a valid byte. |
static double |
valueAsDouble(java.lang.String key,
double defaultVal)
Returns the value for key in the Configuration as a double, or the default provided value if not found or if the value is not a valid double. |
static float |
valueAsFloat(java.lang.String key,
float defaultVal)
Returns the value for key in the Configuration as a float, or the default provided value if not found or if the value is not a valid float. |
static int |
valueAsInt(java.lang.String key,
int defaultVal)
Returns the value for key in the Configuration as an integer, or a default value if not found or if the value is not a valid integer. |
static long |
valueAsLong(java.lang.String key,
long defaultVal)
Returns the value for key in the Configurationas a long, or the default provided value if not found or if the value is not a valid long. |
static int |
valueAsShort(java.lang.String key,
short defaultVal)
Returns the value for key in the Configuration as a short, or the default provided value if not found or if the value is not a valid short. |
static java.lang.String |
valueFor(java.lang.String key)
Returns the value for key in the Configuration. |
static java.lang.String |
valueFor(java.lang.String key,
java.lang.String defaultVal)
Returns the value for key in the Configuration, or the default provided value if not found. |
static java.lang.Object |
valueFromClassConstant(java.lang.String key,
java.lang.Object defaultValue)
Given a property, resolves the value to a public constant field on some class, where the field is of type Object. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void setConfigLogger(java.util.logging.Logger logger)
logger
- Logger used for Configuration-related messagespublic static java.lang.String valueFor(java.lang.String key)
key
- Name of the property.
public static boolean hasValue(java.lang.String key)
public static int valueAsByte(java.lang.String key, byte defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static int valueAsShort(java.lang.String key, short defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static int valueAsInt(java.lang.String key, int defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static long valueAsLong(java.lang.String key, long defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static float valueAsFloat(java.lang.String key, float defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static double valueAsDouble(java.lang.String key, double defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static java.lang.String valueFor(java.lang.String key, java.lang.String defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static java.util.Iterator keysByPrefix(java.lang.String prefix)
prefix
- Prefix to filter on. No regex.
public static void main(java.lang.String[] args)
args
- Ignoredpublic static boolean isTrue(java.lang.String key, boolean defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static boolean isFalse(java.lang.String key, boolean defaultVal)
key
- Name of the property.defaultVal
- PARAM
public static java.lang.Object valueFromClassConstant(java.lang.String key, java.lang.Object defaultValue)
key
- Name of the propertydefaultValue
- Returned in case of error.
|
Flying Saucer Project Release ${app.version} | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |