Class 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
    • 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

      • 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 interface ConfigurationService
        Parameters:
        name - the property name
        Returns:
        the integer property value
        See Also:
        ConfigurationService.getIntProperty(java.lang.String)
      • 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 interface ConfigurationService
        Parameters:
        name - the property name
        Returns:
        the long property value
        See Also:
        ConfigurationService.getLongProperty(java.lang.String)
      • 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 interface ConfigurationService
        Type Parameters:
        T - class type
        Parameters:
        name - the property name
        type - 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 interface ConfigurationService
        Type Parameters:
        T - class type
        Parameters:
        name - the property name
        defaultValue - 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 interface ConfigurationService
        Type Parameters:
        T - class type
        Parameters:
        name - the property name
        defaultValue - the value to return if this name is not found
        setDefaultIfNotFound - 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
      • addPropertyValue

        public boolean addPropertyValue​(String name,
                                        Object value)
        Description copied from interface: ConfigurationService
        Add a value to a configuration property.
        Specified by:
        addPropertyValue in interface ConfigurationService
        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 interface ConfigurationService
        Parameters:
        name - the property name
        value - 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 add
        value - 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 interface ConfigurationService
      • 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:

        1. the value of the system property dspace.dir if defined;
        2. else the value of providedHome if not null;
        3. else the servlet container's home + "/dspace/" if defined (see getCatalina());
        4. else the user's home directory if defined;
        5. else "/".
        Parameters:
        providedHome - provided home directory (may be null)
        Returns:
        full path to DSpace home
      • 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