Class SettingBundle

  • All Implemented Interfaces:
    SilverpeasBundle

    public class SettingBundle
    extends Object
    implements SilverpeasBundle
    A bundle settings used to configure some features in Silverpeas or the behaviour of an application. Each setting in the bundle is defined as a key-value pair.

    It uses a java.util.ResourceBundle behind the scene to access the settings defined under a fully qualified name (the resource bundle base name), so the lifecycle of the bundle is then managed by the java.util.ResourceBundle implementation (with expiration time, cache handling, ...). The java.util.ResourceBundle is loaded on demand, when a property is asked. So, by default, if no such bundle exists or if the property isn't defined in the bundle then a java.util.MissingResourceException exception is thrown. In the case a default value is specified (whatever its value), no java.util.MissingResourceException exception is thrown when the property doesn't exist.

    Author:
    miguel
    See Also:
    ResourceBundle
    • Method Detail

      • exists

        public boolean exists()
        Is this bundle exists?
        Specified by:
        exists in interface SilverpeasBundle
        Returns:
        true if this bundle exists, false otherwise.
      • containsKey

        public boolean containsKey​(String key)
        Description copied from interface: SilverpeasBundle
        Is this bundle contains the specified data
        Specified by:
        containsKey in interface SilverpeasBundle
        Parameters:
        key - the name of the data.
        Returns:
        true if this bundle has a data with the specified key, false otherwise.
      • getBaseBundleName

        public String getBaseBundleName()
        Description copied from interface: SilverpeasBundle
        What is the fully qualified name of this bundle.
        Specified by:
        getBaseBundleName in interface SilverpeasBundle
        Returns:
        the base bundle name (that is to say without the hierarchy path name that is handled by org.silverpeas.core.util.ResourceLocator).
      • getString

        public String getString​(String key,
                                String defaultValue)
        Gets the value as a String of the data identified by the specified key. If the data isn't valued or if it doesn't exist, then the default value is returned.

        If you expect the data can be not defined in this bundle, then use this method instead of org.silverpeas.core.util.SettingBundle#getString method and use the default value to test afterward the data is or not defined.

        Parameters:
        key - the unique name of the data in this bundle.
        defaultValue - the default value to use if the setting isn't valued or if it isn't defined in the bundle.
        Returns:
        the value of the data as a string of characters.
        Throws:
        MissingResourceException - if the bundle doesn't exist.
      • getList

        public String[] getList​(String key)
        Gets the value as an array of String instances of the data identified by the specified key. The value of the property in the bundle is considered to be a text encoding a list of comma-separated items. These items will be the elements of the returned array. Any blank items are skipped.
        Parameters:
        key - the unique name of the data in this bundle.
        Returns:
        an array with the items of the list that values the given property key.
      • getList

        public String[] getList​(String key,
                                String separator)
        Gets the value as an array of String instances of the data identified by the specified key. The value of the property in the bundle is considered to be a text encoding a list of items separated from each other by the given separator. These items will be the elements of the returned array. Any blank items are skipped.
        Parameters:
        key - the unique name of the data in this bundle.
        separator - the separator used to separate each item of property value.
        Returns:
        an array with the items of the list that values the given property key.
      • getList

        public String[] getList​(String key,
                                String[] defaultValue)
        Gets the value as an array of String instances of the data identified by the specified key. The value of the property in the bundle is considered to be a text encoding a list of comma-separated items. These items will be the elements of the returned array. Any blank items are skipped.

        If you expect the data can be not defined in this bundle, then use this method instead of org.silverpeas.core.util.SettingBundle#getList method and use the default value to test afterward the data is or not defined.

        Parameters:
        key - the unique name of the data in this bundle.
        defaultValue - the default value to use if the setting isn't valued or if it isn't defined in the bundle.
        Returns:
        an array with the items of the list that values the given property key.
      • getList

        public String[] getList​(String key,
                                String[] defaultValue,
                                String separator)
        Gets the value as an array of String instances of the data identified by the specified key. The value of the property in the bundle is considered to be a text encoding a list of items separated from each other by the given separator. These items will be the elements of the returned array. Any blank items are skipped.

        If you expect the data can be not defined in this bundle, then use this method instead of org.silverpeas.core.util.SettingBundle#getList method and use the default value to test afterward the data is or not defined.

        Parameters:
        key - the unique name of the data in this bundle.
        defaultValue - the default value to use if the setting isn't valued or if it isn't defined in the bundle.
        separator - the separator used to separate each item of property value.
        Returns:
        an array with the items of the list that values the given property key.
      • getBoolean

        public boolean getBoolean​(String key)
      • getBoolean

        public boolean getBoolean​(String key,
                                  boolean defaultValue)
      • getLong

        public long getLong​(String key)
      • getLong

        public long getLong​(String key,
                            long defaultValue)
      • getFloat

        public float getFloat​(String key)
      • getFloat

        public float getFloat​(String key,
                              float defaultValue)
      • getInteger

        public int getInteger​(String key)
      • getInteger

        public int getInteger​(String key,
                              int defaultValue)
      • asProperties

        public Properties asProperties()
        Gets this setting bundle as a simply Properties instance. This can be useful when a Properties is expected in some codes.
        Returns:
        a Properties representation of this setting bundle.