Package org.dspace.servicemanager.config
Class DSpaceConfigurationService
- java.lang.Object
-
- org.dspace.servicemanager.config.DSpaceConfigurationService
-
- All Implemented Interfaces:
ConfigurationService
public final class DSpaceConfigurationService extends Object implements ConfigurationService
The central DSpace configuration service. Uses Apache Commons Configuration to provide the ability to reload Property files.- Author:
- Tim Donohue (rewrote to use Apache Commons Config, Aaron Zeckoski, Kevin Van de Velde, Mark Diggory
-
-
Field Summary
Fields Modifier and Type Field Description static char
CONFIG_LIST_DELIMITER
static String
DEFAULT_CONFIG_DEFINITION_FILE
static String
DEFAULT_CONFIG_DIR
static String
DOT_CONFIG
static String
DSPACE
static String
DSPACE_CONFIG_DEFINITION_PATH
static String
DSPACE_CONFIG_PATH
static String
DSPACE_HOME
static String
DSPACE_SERVER_ID
static String
EXT_CONFIG
-
Constructor Summary
Constructors Constructor Description DSpaceConfigurationService()
Initializes a ConfigurationService based on default values.DSpaceConfigurationService(String providedHome)
Initializes a ConfigurationService based on the provided home directory for DSpace
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addPropertyValue(String name, Object value)
Add a value to a configuration property.void
clear()
Clears all the configuration settings.void
clearConfig(String key)
Clears a single configurationString[]
getArrayProperty(String name)
Returns property value as an array.String[]
getArrayProperty(String name, String[] defaultValue)
Returns property value as an array.boolean
getBooleanProperty(String name)
Returns property value as a boolean value.boolean
getBooleanProperty(String name, boolean defaultValue)
Returns property value as a boolean value.protected String
getCatalina()
This simply attempts to find the servlet container home for tomcat.org.apache.commons.configuration2.Configuration
getConfiguration()
Returns all loaded properties as a Configuration object.protected String
getDSpaceHome(String providedHome)
This attempts to find the DSpace home directory, based on system properties, and the providedHome (if not null).int
getIntProperty(String name)
Returns property value as an int value.int
getIntProperty(String name, int defaultValue)
Returns property value as an int value.long
getLongProperty(String name)
Returns property value as a long value.long
getLongProperty(String name, long defaultValue)
Returns property value as a long value.Properties
getProperties()
Returns all loaded properties as a Properties object.String
getProperty(String name)
Returns property value as a String.String
getProperty(String name, String defaultValue)
Returns property value as a String.<T> T
getPropertyAsType(String name, Class<T> type)
Get a configuration property (setting) from the system as a specified type.<T> T
getPropertyAsType(String name, T defaultValue)
Get a configuration property (setting) from the system, or return a default value if none is found.<T> T
getPropertyAsType(String name, T defaultValue, boolean setDefaultIfNotFound)
Get a configuration property (setting) from the system, or return (and possibly store) a default value if none is found.List<String>
getPropertyKeys()
Returns all Property keys.List<String>
getPropertyKeys(String prefix)
Returns all Property keys that begin with a given prefix.Object
getPropertyValue(String name)
Returns property value as an Object.boolean
hasProperty(String name)
Determine if a given property key exists within the currently loaded configurationprotected boolean
isValidDSpaceHome(String path)
Returns whether a given path seems to have the required DSpace configurations in order to make it a valid DSpace home directoryboolean
loadConfig(String key, Object value)
Loads (i.e.String[]
loadConfiguration(Map<String,Object> properties)
Load (i.e.void
reloadConfig()
Reload all configurations from the DSpace configuration definition.boolean
setProperty(String name, Object value)
Set a configuration property (setting) in the system.String
toString()
-
-
-
Field Detail
-
DSPACE
public static final String DSPACE
- See Also:
- Constant Field Values
-
EXT_CONFIG
public static final String EXT_CONFIG
- See Also:
- Constant Field Values
-
DOT_CONFIG
public static final String DOT_CONFIG
- See Also:
- Constant Field Values
-
DSPACE_HOME
public static final String DSPACE_HOME
- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_DIR
public static final String DEFAULT_CONFIG_DIR
- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_DEFINITION_FILE
public static final String DEFAULT_CONFIG_DEFINITION_FILE
- See Also:
- Constant Field Values
-
DSPACE_CONFIG_DEFINITION_PATH
public static final String DSPACE_CONFIG_DEFINITION_PATH
-
DSPACE_CONFIG_PATH
public static final String DSPACE_CONFIG_PATH
-
DSPACE_SERVER_ID
public static final String DSPACE_SERVER_ID
- See Also:
- Constant Field Values
-
CONFIG_LIST_DELIMITER
public static final char CONFIG_LIST_DELIMITER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DSpaceConfigurationService
public DSpaceConfigurationService()
Initializes a ConfigurationService based on default values. The DSpace Home directory is determined based on system properties / searching.See loadInitialConfig() for more details
-
DSpaceConfigurationService
public DSpaceConfigurationService(String providedHome)
Initializes a ConfigurationService based on the provided home directory for DSpace- Parameters:
providedHome
- provided home directory
-
-
Method Detail
-
getProperties
public Properties getProperties()
Returns all loaded properties as a Properties object.- Specified by:
getProperties
in interfaceConfigurationService
- Returns:
- all the configuration properties in a properties object (name to value)
- See Also:
ConfigurationService.getProperties()
-
getPropertyKeys
public List<String> getPropertyKeys()
Returns all Property keys.- Specified by:
getPropertyKeys
in interfaceConfigurationService
- Returns:
- all the configuration keys as a List
- See Also:
ConfigurationService.getPropertyKeys()
-
getPropertyKeys
public List<String> getPropertyKeys(String prefix)
Returns all Property keys that begin with a given prefix.- Specified by:
getPropertyKeys
in interfaceConfigurationService
- Parameters:
prefix
- prefix of key- Returns:
- all the configuration keys as a List
- See Also:
ConfigurationService.getPropertyKeys(java.lang.String)
-
getConfiguration
public org.apache.commons.configuration2.Configuration getConfiguration()
Returns all loaded properties as a Configuration object.- Specified by:
getConfiguration
in interfaceConfigurationService
- Returns:
- Configuration object representing the system configuration
- See Also:
ConfigurationService.getConfiguration()
-
getPropertyValue
public Object getPropertyValue(String name)
Returns property value as an Object. If property is not found, null is returned.- Specified by:
getPropertyValue
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the property value OR null if none is found
- See Also:
ConfigurationService.getPropertyValue(java.lang.String)
-
getProperty
public String getProperty(String name)
Returns property value as a String. If property is not found, null is returned.- Specified by:
getProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the property value OR null if none is found
- See Also:
ConfigurationService.getProperty(java.lang.String)
-
getProperty
public String getProperty(String name, String defaultValue)
Returns property value as a String. If property is not found, default value is returned.- Specified by:
getProperty
in interfaceConfigurationService
- Parameters:
name
- the property namedefaultValue
- default value if property not found- Returns:
- the property value OR default value if not found
- See Also:
ConfigurationService.getProperty(java.lang.String, java.lang.String)
-
getArrayProperty
public String[] getArrayProperty(String name)
Returns property value as an array. If property is not found, an empty array is returned.- Specified by:
getArrayProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the String Array value
- See Also:
ConfigurationService.getArrayProperty(java.lang.String)
-
getArrayProperty
public String[] getArrayProperty(String name, String[] defaultValue)
Returns property value as an array. If property is not found, default value is returned.- Specified by:
getArrayProperty
in interfaceConfigurationService
- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the String Array value or default value if not found
- See Also:
ConfigurationService.getArrayProperty(java.lang.String, java.lang.String[])
-
getBooleanProperty
public boolean getBooleanProperty(String name)
Returns property value as a boolean value. If property is not found, false is returned.- Specified by:
getBooleanProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the boolean property value (true/false)
- See Also:
ConfigurationService.getBooleanProperty(java.lang.String)
-
getBooleanProperty
public boolean getBooleanProperty(String name, boolean defaultValue)
Returns property value as a boolean value. If property is not found, default value is returned.- Specified by:
getBooleanProperty
in interfaceConfigurationService
- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the boolean property value (true/false) or default value if not found
- See Also:
ConfigurationService.getBooleanProperty(java.lang.String, boolean)
-
getIntProperty
public int getIntProperty(String name)
Returns property value as an int value. If property is not found, 0 is returned.If you wish to avoid the 0 return value, you can use hasProperty() to first determine whether the property exits. Or, use getIntProperty(name,defaultValue).
- Specified by:
getIntProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the integer property value
- See Also:
ConfigurationService.getIntProperty(java.lang.String)
-
getIntProperty
public int getIntProperty(String name, int defaultValue)
Returns property value as an int value. If property is not found, default value is returned.- Specified by:
getIntProperty
in interfaceConfigurationService
- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the integer property value or default value if not found
- See Also:
ConfigurationService.getIntProperty(java.lang.String, int)
-
getLongProperty
public long getLongProperty(String name)
Returns property value as a long value. If property is not found, 0 is returned.If you wish to avoid the 0 return value, you can use hasProperty() to first determine whether the property exits. Or, use getLongProperty(name,defaultValue).
- Specified by:
getLongProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- the long property value
- See Also:
ConfigurationService.getLongProperty(java.lang.String)
-
getLongProperty
public long getLongProperty(String name, long defaultValue)
Returns property value as a long value. If property is not found, default value is returned.- Specified by:
getLongProperty
in interfaceConfigurationService
- Parameters:
name
- the property namedefaultValue
- the default value if property not found- Returns:
- the long property value or default value if not found
- See Also:
ConfigurationService.getLongProperty(java.lang.String, long)
-
getPropertyAsType
public <T> T getPropertyAsType(String name, Class<T> type)
Description copied from interface:ConfigurationService
Get a configuration property (setting) from the system as a specified type.- Specified by:
getPropertyAsType
in interfaceConfigurationService
- Type Parameters:
T
- class type- Parameters:
name
- the property nametype
- the type to return the property as- Returns:
- the property value OR null if none is found
-
getPropertyAsType
public <T> T getPropertyAsType(String name, T defaultValue)
Description copied from interface:ConfigurationService
Get a configuration property (setting) from the system, or return a default value if none is found.- Specified by:
getPropertyAsType
in interfaceConfigurationService
- Type Parameters:
T
- class type- Parameters:
name
- the property namedefaultValue
- the value to return if this name is not found- Returns:
- the property value OR null if none is found
-
getPropertyAsType
public <T> T getPropertyAsType(String name, T defaultValue, boolean setDefaultIfNotFound)
Description copied from interface:ConfigurationService
Get a configuration property (setting) from the system, or return (and possibly store) a default value if none is found.- Specified by:
getPropertyAsType
in interfaceConfigurationService
- Type Parameters:
T
- class type- Parameters:
name
- the property namedefaultValue
- the value to return if this name is not foundsetDefaultIfNotFound
- if this is true and the config value is not found then the default value will be set in the configuration store assuming it is not null. Otherwise the default value is just returned but not set.- Returns:
- the property value OR null if none is found
-
hasProperty
public boolean hasProperty(String name)
Determine if a given property key exists within the currently loaded configuration- Specified by:
hasProperty
in interfaceConfigurationService
- Parameters:
name
- the property name- Returns:
- true if property exists, false if not
- See Also:
ConfigurationService.hasProperty(java.lang.String)
-
addPropertyValue
public boolean addPropertyValue(String name, Object value)
Description copied from interface:ConfigurationService
Add a value to a configuration property.- Specified by:
addPropertyValue
in interfaceConfigurationService
- Parameters:
name
- the property name. May not be null.value
- the property value. May not be null.- Returns:
- true if a new property was created.
-
setProperty
public boolean setProperty(String name, Object value)
Description copied from interface:ConfigurationService
Set a configuration property (setting) in the system. Type is not important here since conversion happens automatically when properties are requested.- Specified by:
setProperty
in interfaceConfigurationService
- Parameters:
name
- the property namevalue
- the property value (set this to null to clear out the property)- Returns:
- true if the property is new or changed from the existing value, false if it is the same
-
loadConfiguration
public String[] loadConfiguration(Map<String,Object> properties)
Load (i.e. Add) a series of properties into the configuration. Checks to see if the settings exist or are changed and only loads changes.This only adds/updates configurations, if you wish to first clear all existing configurations, see clear() method.
- Parameters:
properties
- a map of key to value settings- Returns:
- the list of changed configuration keys
-
loadConfig
public boolean loadConfig(String key, Object value)
Loads (i.e. Adds) a single additional config setting into the system.- Parameters:
key
- configuration key to addvalue
- configuration value to add- Returns:
- true if the config is new or changed
-
clear
public void clear()
Clears all the configuration settings.
-
clearConfig
public void clearConfig(String key)
Clears a single configuration- Parameters:
key
- key of the configuration
-
reloadConfig
public void reloadConfig()
Reload all configurations from the DSpace configuration definition.This method invalidates the current Configuration object, and uses the initialized ConfigurationBuilder to reload all configurations.
- Specified by:
reloadConfig
in interfaceConfigurationService
-
getDSpaceHome
protected String getDSpaceHome(String providedHome)
This attempts to find the DSpace home directory, based on system properties, and the providedHome (if not null).The initial value of
dspace.dir
will be:- the value of the system property
dspace.dir
if defined; - else the value of
providedHome
if not null; - else the servlet container's home + "/dspace/" if defined (see
getCatalina()
); - else the user's home directory if defined;
- else "/".
- Parameters:
providedHome
- provided home directory (may be null)- Returns:
- full path to DSpace home
- the value of the system property
-
isValidDSpaceHome
protected boolean isValidDSpaceHome(String path)
Returns whether a given path seems to have the required DSpace configurations in order to make it a valid DSpace home directory- Parameters:
path
- path to validate- Returns:
- true if path seems valid, false otherwise
-
getCatalina
protected String getCatalina()
This simply attempts to find the servlet container home for tomcat.- Returns:
- the path to the servlet container home OR null if it cannot be found
-
-