Class CmsMultiMessages
- java.lang.Object
-
- org.opencms.i18n.CmsMessages
-
- org.opencms.i18n.CmsMultiMessages
-
- Direct Known Subclasses:
CmsWorkplaceMessages
public class CmsMultiMessages extends CmsMessages
Provides access to the localized messages for several resource bundles simultaneously.Messages are cached for faster lookup. If a localized key is contained in more then one resource bundle, it will be used only from the resource bundle where it was first found in. The resource bundle order is undefined. It is therefore recommended to ensure the uniqueness of all module keys by placing a special prefix in front of all keys of a resource bundle.
- Since:
- 6.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CmsMultiMessages.I_KeyFallbackHandler
Interface to provide fallback keys to be used when the message for a key is not found.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MULTI_BUNDLE_NAME
Constant for the multi bundle name.static java.lang.String
NULL_STRING
Null String value for caching of null message results.-
Fields inherited from class org.opencms.i18n.CmsMessages
KEY_SHORT_SUFFIX, UNKNOWN_KEY_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description CmsMultiMessages(java.util.Locale locale)
Constructor for creating a new messages object initialized with the given locale.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBundle(I_CmsMessageBundle bundle)
Adds a bundle instance to this multi message bundle.void
addMessages(java.util.List<CmsMessages> messages)
Adds a list a messages instances to this multi message bundle.void
addMessages(CmsMessages messages)
Adds a messages instance to this multi message bundle.java.util.List<CmsMessages>
getMessages()
Returns the list of all individual message objects in this multi message instance.java.lang.String
getString(java.lang.String keyName)
Directly calls the getString(String) method of the wrapped ResourceBundle.boolean
isInitialized()
Checks if the bundle was properly initialized.java.lang.String
key(java.lang.String keyName, boolean allowNull)
Returns the localized resource string for a given message key.void
setFallbackHandler(CmsMultiMessages.I_KeyFallbackHandler fallbackHandler)
Sets the key fallback handler.-
Methods inherited from class org.opencms.i18n.CmsMessages
equals, formatUnknownKey, getBundleName, getDate, getDate, getDate, getDateTime, getDateTime, getDateTime, getLocale, getResourceBundle, hashCode, isUncacheable, isUnknownKey, key, key, key, key, key, key, keyDefault, keyWithParams, keyWithParams, setBundleName, setLocale, setResourceBundle, toString
-
-
-
-
Field Detail
-
MULTI_BUNDLE_NAME
public static final java.lang.String MULTI_BUNDLE_NAME
Constant for the multi bundle name.
-
NULL_STRING
public static final java.lang.String NULL_STRING
Null String value for caching of null message results.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsMultiMessages
public CmsMultiMessages(java.util.Locale locale)
Constructor for creating a new messages object initialized with the given locale.- Parameters:
locale
- the locale to use for localization of the messages
-
-
Method Detail
-
addBundle
public void addBundle(I_CmsMessageBundle bundle)
Adds a bundle instance to this multi message bundle.The added bundle will be localized with the locale of this multi message bundle.
- Parameters:
bundle
- the bundle instance to add
-
addMessages
public void addMessages(CmsMessages messages) throws CmsIllegalArgumentException
Adds a messages instance to this multi message bundle.The messages instance should have been initialized with the same locale as this multi bundle, if not, the locale of the messages instance is automatically replaced. However, this will not work if the added messages instance is in face also of type
.CmsMultiMessages
- Parameters:
messages
- the messages instance to add- Throws:
CmsIllegalArgumentException
- if the locale of the given
does not match the locale of this multi messagesCmsMultiMessages
-
addMessages
public void addMessages(java.util.List<CmsMessages> messages)
Adds a list a messages instances to this multi message bundle.- Parameters:
messages
- the messages instance to add
-
getMessages
public java.util.List<CmsMessages> getMessages()
Returns the list of all individual message objects in this multi message instance.- Returns:
- the list of all individual message objects in this multi message instance
-
getString
public java.lang.String getString(java.lang.String keyName)
Description copied from class:CmsMessages
Directly calls the getString(String) method of the wrapped ResourceBundle.If you use this this class on a template, you should consider using the
CmsMessages.key(String)
method to get the value from the ResourceBundle because it handles the exception for you in a convenient way.- Overrides:
getString
in classCmsMessages
- Parameters:
keyName
- the key- Returns:
- the resource string for the given key
- See Also:
CmsMessages.getString(java.lang.String)
-
isInitialized
public boolean isInitialized()
Description copied from class:CmsMessages
Checks if the bundle was properly initialized.- Overrides:
isInitialized
in classCmsMessages
- Returns:
true
if bundle was initialized,false
otherwise- See Also:
CmsMessages.isInitialized()
-
key
public java.lang.String key(java.lang.String keyName, boolean allowNull)
Description copied from class:CmsMessages
Returns the localized resource string for a given message key.If the key was not found in the bundle, the return value depends on the setting of the allowNull parameter. If set to false, the return value is always a String in the format
"??? " + keyName + " ???"
. If set to true, null is returned if the key is not found. This will also be returned if the bundle was not properly initialized first.- Overrides:
key
in classCmsMessages
- Parameters:
keyName
- the key for the desired stringallowNull
- if true, 'null' is an allowed return value- Returns:
- the resource string for the given key
- See Also:
CmsMessages.key(java.lang.String, boolean)
-
setFallbackHandler
public void setFallbackHandler(CmsMultiMessages.I_KeyFallbackHandler fallbackHandler)
Sets the key fallback handler.- Parameters:
fallbackHandler
- the new key fallback handler
-
-