Class CmsMessages
- Direct Known Subclasses:
- CmsMultiMessages,- CmsXmlMessages
java.util.ResourceBundle
 and provides convenience methods to access the Strings from a template.
 This class is frequently used from JSP templates. Because of that, throwing of
 exceptions related to the access of the resource bundle are suppressed
 so that a template always execute. The class provides an isInitialized() method
 that can be checked to see if the instance was properly initialized.
- Since:
- 6.0.0
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedEmpty constructor for subclassing.CmsMessages(String bundleName, String language) Constructor for the messages with a language string.CmsMessages(String bundleName, String language, String country) Constructor for the messages with language and country code strings.CmsMessages(String bundleName, String language, String country, String variant) Constructor for the messages with language, country code and variant strings.CmsMessages(String bundleName, Locale locale) Constructor for the messages with an initializedjava.util.Locale.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanstatic StringformatUnknownKey(String keyName) Formats an unknown key.protected StringReturns the name of the resource bundle this object was initialized with.getDate(long time) Returns a formated date String from a timestamp value, the format beingDateFormat.SHORTand the locale based on this instance.Returns a formated date String from a Date value, the format beingDateFormat.SHORTand the locale based on this instance.Returns a formated date String from a Date value, the formatting based on the provided option and the locale based on this instance.getDateTime(long time) Returns a formated date and time String from a timestamp value, the format beingDateFormat.SHORTand the locale based on this instance.getDateTime(Date date) Returns a formated date and time String from a Date value, the format beingDateFormat.SHORTand the locale based on this instance.getDateTime(Date date, int format) Returns a formated date and time String from a Date value, the formatting based on the provided option and the locale based on this instance.Returns the locale to use for looking up this messages.Returns the resource bundle this message object was initialized with.Directly calls the getString(String) method of the wrapped ResourceBundle.inthashCode()booleanChecks if the bundle was properly initialized.booleanIndicates that users of this CmsMessages instance should not cache message from it.static booleanisUnknownKey(String value) Returnstrueif the provided value matches the scheme"??? " + keyName + " ???", that is the value appears to be an unknown key.Returns the localized resource string for a given message key.Returns the localized resource string for a given message key.Returns the selected localized message for the initialized resource bundle and locale.Returns the selected localized message for the initialized resource bundle and locale.Returns the selected localized message for the initialized resource bundle and locale.Returns the selected localized message for the initialized resource bundle and locale.Returns the selected localized message for the initialized resource bundle and locale.keyDefault(String keyName, String defaultValue) Returns the localized resource string for a given message key.keyWithParams(String keyName) Returns the localized resource string for a given message key, treating all values appended with "|" as replacement parameters.keyWithParams(String keyName, Function<String, String> unknownKeyFormatter) Returns the localized resource string for a given message key, treating all values appended with "|" as replacement parameters.protected voidsetBundleName(String bundleName) Sets the bundleName.protected voidSets the locale.protected voidsetResourceBundle(ResourceBundle resourceBundle) Sets the resource bundle.toString()
- 
Field Details- 
KEY_SHORT_SUFFIXThe suffix of a "short" localized key name.- See Also:
 
- 
UNKNOWN_KEY_EXTENSIONPrefix / Suffix for unknown keys.- See Also:
 
 
- 
- 
Constructor Details- 
CmsMessagesConstructor for the messages with an initializedjava.util.Locale.- Parameters:
- bundleName- the base ResourceBundle name
- locale- the m_locale to use, eg. "de", "en" etc.
 
- 
CmsMessagesConstructor for the messages with a language string.The languageis a 2 letter language ISO code, e.g."EN".The Locale for the messages will be created like this: 
 new Locale(language, "", "").- Parameters:
- bundleName- the base ResourceBundle name
- language- ISO language indentificator for the m_locale of the bundle
 
- 
CmsMessagesConstructor for the messages with language and country code strings.The languageis a 2 letter language ISO code, e.g."EN". Thecountryis a 2 letter country ISO code, e.g."us".The Locale for the messages will be created like this: 
 new Locale(language, country, "").- Parameters:
- bundleName- the base ResourceBundle name
- language- ISO language indentificator for the m_locale of the bundle
- country- ISO 2 letter country code for the m_locale of the bundle
 
- 
CmsMessagesConstructor for the messages with language, country code and variant strings.The languageis a 2 letter language ISO code, e.g."EN". Thecountryis a 2 letter country ISO code, e.g."us". Thevariantis a vendor or browser-specific code, e.g."POSIX".The Locale for the messages will be created like this: 
 new Locale(language, country, variant).- Parameters:
- bundleName- the base ResourceBundle name
- language- language indentificator for the m_locale of the bundle
- country- 2 letter country code for the m_locale of the bundle
- variant- a vendor or browser-specific variant code
 
- 
CmsMessagesprotected CmsMessages()Empty constructor for subclassing.
 
- 
- 
Method Details- 
formatUnknownKeyFormats an unknown key.- Parameters:
- keyName- the key to format
- Returns:
- the formatted unknown key
- See Also:
 
- 
isUnknownKeyReturnstrueif the provided value matches the scheme"??? " + keyName + " ???", that is the value appears to be an unknown key.Also returns trueif the given value isnull.- Parameters:
- value- the value to check
- Returns:
- true if the value is matches the scheme for unknown keys
- See Also:
 
- 
equals
- 
getDateReturns a formated date String from a Date value, the format beingDateFormat.SHORTand the locale based on this instance.- Parameters:
- date- the Date object to format as String
- Returns:
- the formatted date
 
- 
getDateReturns a formated date String from a Date value, the formatting based on the provided option and the locale based on this instance.- Parameters:
- date- the Date object to format as String
- format- the format to use, see- CmsMessagesfor possible values
- Returns:
- the formatted date
 
- 
getDateReturns a formated date String from a timestamp value, the format beingDateFormat.SHORTand the locale based on this instance.- Parameters:
- time- the time value to format as date
- Returns:
- the formatted date
 
- 
getDateTimeReturns a formated date and time String from a Date value, the format beingDateFormat.SHORTand the locale based on this instance.- Parameters:
- date- the Date object to format as String
- Returns:
- the formatted date and time
 
- 
getDateTimeReturns a formated date and time String from a Date value, the formatting based on the provided option and the locale based on this instance.- Parameters:
- date- the Date object to format as String
- format- the format to use, see- CmsMessagesfor possible values
- Returns:
- the formatted date and time
 
- 
getDateTimeReturns a formated date and time String from a timestamp value, the format beingDateFormat.SHORTand the locale based on this instance.- Parameters:
- time- the time value to format as date
- Returns:
- the formatted date and time
 
- 
getLocaleReturns the locale to use for looking up this messages.- Returns:
- the locale to use for looking up this messages
 
- 
getResourceBundleReturns the resource bundle this message object was initialized with.- Returns:
- the resource bundle this message object was initialized with or null if initialization was not successful
 
- 
getStringDirectly calls the getString(String) method of the wrapped ResourceBundle.If you use this this class on a template, you should consider using the key(String)method to get the value from the ResourceBundle because it handles the exception for you in a convenient way.- Parameters:
- keyName- the key
- Returns:
- the resource string for the given key
- Throws:
- CmsMessageException- in case the key is not found or the bundle is not initialized
 
- 
hashCode
- 
isInitializedChecks if the bundle was properly initialized.- Returns:
- trueif bundle was initialized,- falseotherwise
 
- 
isUncacheableIndicates that users of this CmsMessages instance should not cache message from it.- Returns:
- true if messages from this CmsMessages instance should not be cached
 
- 
keyReturns the localized resource string for a given message key.If the key was not found in the bundle, the return value is "??? " + keyName + " ???". This will also be returned if the bundle was not properly initialized first.- Parameters:
- keyName- the key for the desired string
- Returns:
- the resource string for the given key
 
- 
keyReturns 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.- Parameters:
- keyName- the key for the desired string
- allowNull- if true, 'null' is an allowed return value
- Returns:
- the resource string for the given key
 
- 
keyReturns the selected localized message for the initialized resource bundle and locale.Convenience method for messages with one argument. - Parameters:
- key- the message key
- arg0- the message argument
- Returns:
- the selected localized message for the initialized resource bundle and locale
 
- 
keyReturns the selected localized message for the initialized resource bundle and locale.Convenience method for messages with two arguments. - Parameters:
- key- the message key
- arg0- the first message argument
- arg1- the second message argument
- Returns:
- the selected localized message for the initialized resource bundle and locale
 
- 
keyReturns the selected localized message for the initialized resource bundle and locale.Convenience method for messages with three arguments. - Parameters:
- key- the message key
- arg0- the first message argument
- arg1- the second message argument
- arg2- the third message argument
- Returns:
- the selected localized message for the initialized resource bundle and locale
 
- 
keyReturns the selected localized message for the initialized resource bundle and locale.If the key was found in the bundle, it will be formatted using a MessageFormatIf the key was not found in the bundle, the return value is "??? " + keyName + " ???". This will also be returned if the bundle was not properly initialized first.- Parameters:
- key- the message key
- args- the message arguments
- Returns:
- the selected localized message for the initialized resource bundle and locale
 
- 
keyReturns the selected localized message for the initialized resource bundle and locale.If the key was found in the bundle, it will be formatted using a MessageFormatIf the key was not found in the bundle, the return value will be the result of passing the key to the unknownKeyFormatter function. - Parameters:
- key- the message key
- args- the message arguments
- unknownKeyFormatter- the function for formatting unknown keys
- Returns:
- the selected localized message for the initialized resource bundle and locale
 
- 
keyDefaultReturns the localized resource string for a given message key.If the key was not found in the bundle, the provided default value is returned. - Parameters:
- keyName- the key for the desired string
- defaultValue- the default value in case the key does not exist in the bundle
- Returns:
- the resource string for the given key it it exists, or the given default if not
 
- 
keyWithParamsReturns the localized resource string for a given message key, treating all values appended with "|" as replacement parameters.If the key was found in the bundle, it will be formatted using a MessageFormaterror.message|First|Secondwould use the keyerror.messagewith the parametersFirstandSecond. This would be the same as callingkey(String, Object[])If no parameters are appended with "|", this is the same as calling key(String)If the key was not found in the bundle, the return value is "??? " + keyName + " ???". This will also be returned if the bundle was not properly initialized first.- Parameters:
- keyName- the key for the desired string, optinally containing parameters appended with a "|"
- Returns:
- the resource string for the given key
- See Also:
 
- 
keyWithParamsReturns the localized resource string for a given message key, treating all values appended with "|" as replacement parameters.If the key was found in the bundle, it will be formatted using a MessageFormaterror.message|First|Secondwould use the keyerror.messagewith the parametersFirstandSecond. This would be the same as callingkey(String, Object[])If no parameters are appended with "|", this is the same as calling key(String)If the key was not found in the bundle, the function from the unknownKeyFormatter parameter is used to generate the return value. - Parameters:
- keyName- the key for the desired string, optinally containing parameters appended with a "|"
- unknownKeyFormatter- the function to use to generate the returned result for unknown keys
- Returns:
- the resource string for the given key
- See Also:
 
- 
toString
- 
getBundleNameReturns the name of the resource bundle this object was initialized with.- Returns:
- the name of the resource bundle this object was initialized with
 
- 
setBundleNameSets the bundleName.- Parameters:
- bundleName- the bundleName to set
 
- 
setLocaleSets the locale.- Parameters:
- locale- the locale to set
 
- 
setResourceBundleSets the resource bundle.- Parameters:
- resourceBundle- the resource bundle to set
 
 
-