Class SettingBundle
- java.lang.Object
-
- org.silverpeas.core.util.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 thejava.util.ResourceBundle
implementation (with expiration time, cache handling, ...). Thejava.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 ajava.util.MissingResourceException
exception is thrown. In the case a default value is specified (whatever its value), nojava.util.MissingResourceException
exception is thrown when the property doesn't exist.- Author:
- miguel
- See Also:
ResourceBundle
-
-
Field Summary
Fields Modifier and Type Field Description static String
GENERAL_BUNDLE_NAME
-
Constructor Summary
Constructors Modifier Constructor Description protected
SettingBundle(String name, Function<String,ResourceBundle> loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Properties
asProperties()
Gets this setting bundle as a simplyProperties
instance.ResourceBundle
asResourceBundle()
Gets this setting bundle as a simplyResourceBundle
instance.boolean
containsKey(String key)
Is this bundle contains the specified databoolean
exists()
Is this bundle exists?String
getBaseBundleName()
What is the fully qualified name of this bundle.boolean
getBoolean(String key)
boolean
getBoolean(String key, boolean defaultValue)
float
getFloat(String key)
float
getFloat(String key, float defaultValue)
int
getInteger(String key)
int
getInteger(String key, int defaultValue)
String[]
getList(String key)
Gets the value as an array of String instances of the data identified by the specified key.String[]
getList(String key, String separator)
Gets the value as an array of String instances of the data identified by the specified key.String[]
getList(String key, String[] defaultValue)
Gets the value as an array of String instances of the data identified by the specified key.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.long
getLong(String key)
long
getLong(String key, long defaultValue)
String
getString(String key)
If you expect the data can be not defined in this bundle, then useorg.silverpeas.core.util.SettingBundle#getString
method instead of this.String
getString(String key, String defaultValue)
Gets the value as a String of the data identified by the specified key.Set<String>
keySet()
Gets a set of all keys defined in this bundle.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.util.SilverpeasBundle
getStringList, getStringList
-
-
-
-
Field Detail
-
GENERAL_BUNDLE_NAME
public static final String GENERAL_BUNDLE_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SettingBundle
protected SettingBundle(String name, Function<String,ResourceBundle> loader)
-
-
Method Detail
-
exists
public boolean exists()
Is this bundle exists?- Specified by:
exists
in interfaceSilverpeasBundle
- Returns:
- true if this bundle exists, false otherwise.
-
keySet
public Set<String> keySet()
Description copied from interface:SilverpeasBundle
Gets a set of all keys defined in this bundle.- Specified by:
keySet
in interfaceSilverpeasBundle
- Returns:
- a set of keys.
-
containsKey
public boolean containsKey(String key)
Description copied from interface:SilverpeasBundle
Is this bundle contains the specified data- Specified by:
containsKey
in interfaceSilverpeasBundle
- 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 interfaceSilverpeasBundle
- 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)
If you expect the data can be not defined in this bundle, then useorg.silverpeas.core.util.SettingBundle#getString
method instead of this.- Specified by:
getString
in interfaceSilverpeasBundle
- Parameters:
key
- the unique name of the data in this bundle.- Returns:
- the value of the data as a string of characters.
- See Also:
SilverpeasBundle.getString(String)
,getString(String, String)
-
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)
-
asResourceBundle
public ResourceBundle asResourceBundle()
Gets this setting bundle as a simplyResourceBundle
instance. This can be useful when aResourceBundle
is expected in some codes.- Returns:
- a
ResourceBundle
representation of this setting bundle.
-
asProperties
public Properties asProperties()
Gets this setting bundle as a simplyProperties
instance. This can be useful when aProperties
is expected in some codes.- Returns:
- a
Properties
representation of this setting bundle.
-
-