|
Griffon 1.2.0 | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgriffon.util.ConfigUtils
public final class ConfigUtils
Utility class for reading configuration properties.
Field Summary | |
---|---|
private static String |
GROOVY_SUFFIX
|
private static Logger |
LOG
|
private static String |
PROPERTIES_SUFFIX
|
Constructor Summary | |
private ConfigUtils()
|
Method Summary | |
---|---|
static ConfigReader
|
createConfigReader()
Creates a new ConfigReader instance configured with default conditional blocks. |
static Object
|
getConfigValue(Map config, String key)
Returns the value for the specified key. |
static Object
|
getConfigValue(Map config, String key, Object defaultValue)
Returns the value for the specified key with an optional default value if no match is found. |
static boolean
|
getConfigValueAsBoolean(Map config, String key)
Returns the value for the specified key coerced to a boolean. |
static boolean
|
getConfigValueAsBoolean(Map config, String key, boolean defaultValue)
Returns the value for the specified key with an optional default value if no match is found. |
static int
|
getConfigValueAsInt(Map config, String key)
Returns the value for the specified key coerced to an int. |
static int
|
getConfigValueAsInt(Map config, String key, int defaultValue)
Returns the value for the specified key with an optional default value if no match is found. |
static String
|
getConfigValueAsString(Map config, String key)
Returns the value for the specified key converted to a String. |
static String
|
getConfigValueAsString(Map config, String key, String defaultValue)
Returns the value for the specified key with an optional default value if no match is found. |
static String
|
getFilenameExtension(String path)
Extract the filename extension from the given path, e.g. |
static boolean
|
isValueDefined(Map config, String key)
Returns true if there's a on-null value for the specified key. |
static Class
|
loadClass(String className)
|
static ConfigObject
|
loadConfig(String configFileName)
Loads configuration settings defined in a Groovy script and a properties file as fallback. |
static ConfigObject
|
loadConfig(Class configClass)
Loads configuration settings defined in a Groovy script and a properties file as fallback. |
static ConfigObject
|
loadConfig(Class configClass, String configFileName)
Loads configuration settings defined in a Groovy script and a properties file as fallback. |
static ConfigObject
|
loadConfig(ConfigReader configReader, Class configClass, String configFileName)
Loads configuration settings defined in a Groovy script and a properties file as fallback. |
private static ConfigObject
|
loadConfigFile(ConfigReader configReader, String configFileName)
|
static ConfigObject
|
loadConfigWithI18n(String baseConfigFileName)
Loads configuration settings defined in a Groovy script and a properties file. |
static ConfigObject
|
loadConfigWithI18n(Class baseConfigClass)
Loads configuration settings defined in a Groovy script and a properties file. |
static ConfigObject
|
loadConfigWithI18n(Class baseConfigClass, String baseConfigFileName)
Loads configuration settings defined in a Groovy script and a properties file. |
static ConfigObject
|
loadConfigWithI18n(Locale locale, ConfigReader configReader, Class baseConfigClass, String baseConfigFileName)
Loads configuration settings defined in a Groovy script and a properties file. |
static Map
|
merge(Map defaults, Map overrides)
Merges two maps using ConfigObject.merge(). |
static Class
|
safeLoadClass(String className)
|
static String
|
stripFilenameExtension(String path)
Strip the filename extension from the given path, e.g. |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Field Detail |
---|
private static final String GROOVY_SUFFIX
private static final Logger LOG
private static final String PROPERTIES_SUFFIX
Constructor Detail |
---|
private ConfigUtils()
Method Detail |
---|
public static ConfigReader createConfigReader()
public static Object getConfigValue(Map config, String key)
config
- the configuration object to be searched uponkey
- the key to be searched
public static Object getConfigValue(Map config, String key, Object defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found
public static boolean getConfigValueAsBoolean(Map config, String key)
config
- the configuration object to be searched uponkey
- the key to be searched
public static boolean getConfigValueAsBoolean(Map config, String key, boolean defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found
public static int getConfigValueAsInt(Map config, String key)
config
- the configuration object to be searched uponkey
- the key to be searched
public static int getConfigValueAsInt(Map config, String key, int defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found
public static String getConfigValueAsString(Map config, String key)
config
- the configuration object to be searched uponkey
- the key to be searched
public static String getConfigValueAsString(Map config, String key, String defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found
public static String getFilenameExtension(String path)
path
- the file path (may be null
)null
if none
public static boolean isValueDefined(Map config, String key)
config
- the configuration object to be searched uponkey
- the key to be searched
public static Class loadClass(String className)
public static ConfigObject loadConfig(String configFileName)
configFileName
- the configuration file
public static ConfigObject loadConfig(Class configClass)
configClass
- the script's class, may be null
public static ConfigObject loadConfig(Class configClass, String configFileName)
configClass
- the script's class, may be nullconfigFileName
- the alternate configuration file
public static ConfigObject loadConfig(ConfigReader configReader, Class configClass, String configFileName)
configReader
- a ConfigReader instance already configuredconfigClass
- the script's class, may be nullconfigFileName
- the alternate configuration file
private static ConfigObject loadConfigFile(ConfigReader configReader, String configFileName)
public static ConfigObject loadConfigWithI18n(String baseConfigFileName)
The name of the script matches the name of the file.
The following suffixes will be used besides the base names for script and file
baseConfigFileName
- the configuration file
public static ConfigObject loadConfigWithI18n(Class baseConfigClass)
The alternate properties file matches the simple name of the script.
The following suffixes will be used besides the base names for script and file
baseConfigClass
- the script's class
public static ConfigObject loadConfigWithI18n(Class baseConfigClass, String baseConfigFileName)
The following suffixes will be used besides the base names for script and file
baseConfigClass
- the script's class, may be nullbaseConfigFileName
- the alternate configuration file
public static ConfigObject loadConfigWithI18n(Locale locale, ConfigReader configReader, Class baseConfigClass, String baseConfigFileName)
The following suffixes will be used besides the base names for script and file
locale
- the locale to useconfigReader
- a ConfigReader instance already configuredbaseConfigClass
- the script's class, may be nullbaseConfigFileName
- the alternate configuration file
public static Map merge(Map defaults, Map overrides)
defaults
- configuration values available by defaultoverrides
- configuration values that override defaults
public static Class safeLoadClass(String className)
public static String stripFilenameExtension(String path)
path
- the file path (may be null
)null
if none
Groovy Documentation