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.ResourceBundlebehind 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.ResourceBundleimplementation (with expiration time, cache handling, ...). Thejava.util.ResourceBundleis 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.MissingResourceExceptionexception is thrown. In the case a default value is specified (whatever its value), nojava.util.MissingResourceExceptionexception is thrown when the property doesn't exist.- Author:
- miguel
- See Also:
ResourceBundle
-
-
Field Summary
Fields Modifier and Type Field Description static StringGENERAL_BUNDLE_NAME
-
Constructor Summary
Constructors Modifier Constructor Description protectedSettingBundle(String name, Function<String,ResourceBundle> loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PropertiesasProperties()Gets this setting bundle as a simplyPropertiesinstance.ResourceBundleasResourceBundle()Gets this setting bundle as a simplyResourceBundleinstance.booleancontainsKey(String key)Is this bundle contains the specified databooleanexists()Is this bundle exists?StringgetBaseBundleName()What is the fully qualified name of this bundle.booleangetBoolean(String key)booleangetBoolean(String key, boolean defaultValue)floatgetFloat(String key)floatgetFloat(String key, float defaultValue)intgetInteger(String key)intgetInteger(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.longgetLong(String key)longgetLong(String key, long defaultValue)StringgetString(String key)If you expect the data can be not defined in this bundle, then useorg.silverpeas.core.util.SettingBundle#getStringmethod instead of this.StringgetString(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:
existsin interfaceSilverpeasBundle- Returns:
- true if this bundle exists, false otherwise.
-
keySet
public Set<String> keySet()
Description copied from interface:SilverpeasBundleGets a set of all keys defined in this bundle.- Specified by:
keySetin interfaceSilverpeasBundle- Returns:
- a set of keys.
-
containsKey
public boolean containsKey(String key)
Description copied from interface:SilverpeasBundleIs this bundle contains the specified data- Specified by:
containsKeyin 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:SilverpeasBundleWhat is the fully qualified name of this bundle.- Specified by:
getBaseBundleNamein 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#getStringmethod instead of this.- Specified by:
getStringin 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#getStringmethod 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#getListmethod 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#getListmethod 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 simplyResourceBundleinstance. This can be useful when aResourceBundleis expected in some codes.- Returns:
- a
ResourceBundlerepresentation of this setting bundle.
-
asProperties
public Properties asProperties()
Gets this setting bundle as a simplyPropertiesinstance. This can be useful when aPropertiesis expected in some codes.- Returns:
- a
Propertiesrepresentation of this setting bundle.
-
-