| java.lang.Object org.opencms.i18n.CmsMessages
All known Subclasses: org.opencms.i18n.CmsMultiMessages, org.opencms.xml.CmsXmlMessages,
CmsMessages | public class CmsMessages (Code) | | Reads localized resource Strings from a 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
CmsMessages.isInitialized() method
that can be checked to see if the instance was properly initialized.
author: Alexander Kandzior version: $Revision: 1.25 $ since: 6.0.0 |
Constructor Summary | |
public | CmsMessages(String bundleName, Locale locale) Constructor for the messages with an initialized java.util.Locale .
Parameters: bundleName - the base ResourceBundle name Parameters: locale - the m_locale to use, eg. | public | CmsMessages(String bundleName, String language) Constructor for the messages with a language string.
The language is a 2 letter language ISO code, e.g. | public | CmsMessages(String bundleName, String language, String country) Constructor for the messages with language and country code strings.
The language is a 2 letter language ISO code, e.g. | public | CmsMessages(String bundleName, String language, String country, String variant) Constructor for the messages with language, country code and variant strings.
The language is a 2 letter language ISO code, e.g. | protected | CmsMessages() |
Method Summary | |
public boolean | equals(Object obj) | public static String | formatUnknownKey(String keyName) | protected String | getBundleName() | public String | getDate(Date date) | public String | getDate(Date date, int format) | public String | getDate(long time) | public String | getDateTime(Date date) | public String | getDateTime(Date date, int format) | public String | getDateTime(long time) | public Locale | getLocale() | public ResourceBundle | getResourceBundle() | public String | getString(String keyName) 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. | public int | hashCode() | public boolean | isInitialized() Checks if the bundle was properly initialized. | public static boolean | isUnknownKey(String value) | public String | key(String keyName) Returns the localized resource string for a given message key.
If the key was not found in the bundle, the return value is
"??? " + keyName + " ???" . | public String | key(String keyName, boolean allowNull) 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. | public String | key(String key, Object arg0) | public String | key(String key, Object arg0, Object arg1) | public String | key(String key, Object arg0, Object arg1, Object arg2) | public String | key(String key, Object[] args) Returns 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
MessageFormat using the provided parameters.
If the key was not found in the bundle, the return value is
"??? " + keyName + " ???" . | public String | keyDefault(String keyName, String defaultValue) | public String | keyWithParams(String keyName) Returns 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
MessageFormat using the provided parameters.
The parameters have to be appended to the key separated by a "|".
For example, the keyName error.message|First|Second
would use the key error.message with the parameters
First and Second . | protected void | setBundleName(String bundleName) | protected void | setLocale(Locale locale) | protected void | setResourceBundle(ResourceBundle resourceBundle) | public String | toString() |
KEY_SHORT_SUFFIX | final public static String KEY_SHORT_SUFFIX(Code) | | The suffix of a "short" localized key name.
|
UNKNOWN_KEY_EXTENSION | final public static String UNKNOWN_KEY_EXTENSION(Code) | | Prefix / Suffix for unknown keys.
|
CmsMessages | public CmsMessages(String bundleName, Locale locale)(Code) | | Constructor for the messages with an initialized java.util.Locale .
Parameters: bundleName - the base ResourceBundle name Parameters: locale - the m_locale to use, eg. "de", "en" etc. |
CmsMessages | public CmsMessages(String bundleName, String language)(Code) | | Constructor for the messages with a language string.
The language is 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 Parameters: language - ISO language indentificator for the m_locale of the bundle |
CmsMessages | public CmsMessages(String bundleName, String language, String country)(Code) | | Constructor for the messages with language and country code strings.
The language is a 2 letter language ISO code, e.g. "EN" .
The country is 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 Parameters: language - ISO language indentificator for the m_locale of the bundle Parameters: country - ISO 2 letter country code for the m_locale of the bundle |
CmsMessages | public CmsMessages(String bundleName, String language, String country, String variant)(Code) | | Constructor for the messages with language, country code and variant strings.
The language is a 2 letter language ISO code, e.g. "EN" .
The country is a 2 letter country ISO code, e.g. "us" .
The variant is 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 Parameters: language - language indentificator for the m_locale of the bundle Parameters: country - 2 letter country code for the m_locale of the bundle Parameters: variant - a vendor or browser-specific variant code |
CmsMessages | protected CmsMessages()(Code) | | Empty constructor for subclassing.
|
getBundleName | protected String getBundleName()(Code) | | Returns the name of the resource bundle this object was initialized with.
the name of the resource bundle this object was initialized with |
getDate | public String getDate(Date date)(Code) | | Returns a formated date String from a Date value,
the format being
DateFormat.SHORT and the locale
based on this instance.
Parameters: date - the Date object to format as String the formatted date |
getDate | public String getDate(Date date, int format)(Code) | | Returns 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 Parameters: format - the format to use, see CmsMessages for possible values the formatted date |
getDate | public String getDate(long time)(Code) | | Returns a formated date String from a timestamp value,
the format being
DateFormat.SHORT and the locale
based on this instance.
Parameters: time - the time value to format as date the formatted date |
getDateTime | public String getDateTime(Date date)(Code) | | Returns a formated date and time String from a Date value,
the format being
DateFormat.SHORT and the locale
based on this instance.
Parameters: date - the Date object to format as String the formatted date and time |
getDateTime | public String getDateTime(Date date, int format)(Code) | | 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.
Parameters: date - the Date object to format as String Parameters: format - the format to use, see CmsMessages for possible values the formatted date and time |
getDateTime | public String getDateTime(long time)(Code) | | Returns a formated date and time String from a timestamp value,
the format being
DateFormat.SHORT and the locale
based on this instance.
Parameters: time - the time value to format as date the formatted date and time |
getLocale | public Locale getLocale()(Code) | | Returns the locale to use for looking up this messages.
the locale to use for looking up this messages |
getResourceBundle | public ResourceBundle getResourceBundle()(Code) | | Returns the resource bundle this message object was initialized with.
the resource bundle this message object was initialized with or null if initialization was not successful |
getString | public String getString(String keyName) throws CmsMessageException(Code) | | 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.
Parameters: keyName - the key the resource string for the given key throws: CmsMessageException - in case the key is not found or the bundle is not initialized |
isInitialized | public boolean isInitialized()(Code) | | Checks if the bundle was properly initialized.
true if bundle was initialized, false otherwise |
isUnknownKey | public static boolean isUnknownKey(String value)(Code) | | Returns true if the provided value matches the scheme
"??? " + keyName + " ???" , that is the value appears to be an unknown key.
Also returns true if the given value is null .
Parameters: value - the value to check true if the value is matches the scheme for unknown keys See Also: CmsMessages.formatUnknownKey(String) |
key | public String key(String keyName)(Code) | | Returns 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 the resource string for the given key |
key | public String key(String keyName, boolean allowNull)(Code) | | 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.
Parameters: keyName - the key for the desired string Parameters: allowNull - if true, 'null' is an allowed return value the resource string for the given key |
key | public String key(String key, Object arg0)(Code) | | Returns the selected localized message for the initialized resource bundle and locale.
Convenience method for messages with one argument.
Parameters: key - the message key Parameters: arg0 - the message argument the selected localized message for the initialized resource bundle and locale |
key | public String key(String key, Object arg0, Object arg1)(Code) | | Returns the selected localized message for the initialized resource bundle and locale.
Convenience method for messages with two arguments.
Parameters: key - the message key Parameters: arg0 - the first message argument Parameters: arg1 - the second message argument the selected localized message for the initialized resource bundle and locale |
key | public String key(String key, Object arg0, Object arg1, Object arg2)(Code) | | Returns the selected localized message for the initialized resource bundle and locale.
Convenience method for messages with three arguments.
Parameters: key - the message key Parameters: arg0 - the first message argument Parameters: arg1 - the second message argument Parameters: arg2 - the third message argument the selected localized message for the initialized resource bundle and locale |
key | public String key(String key, Object[] args)(Code) | | Returns 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
MessageFormat using the provided parameters.
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: key - the message key Parameters: args - the message arguments the selected localized message for the initialized resource bundle and locale |
keyDefault | public String keyDefault(String keyName, String defaultValue)(Code) | | Returns 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 Parameters: defaultValue - the default value in case the key does not exist in the bundle the resource string for the given key it it exists, or the given default if not |
keyWithParams | public String keyWithParams(String keyName)(Code) | | Returns 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
MessageFormat using the provided parameters.
The parameters have to be appended to the key separated by a "|".
For example, the keyName error.message|First|Second
would use the key error.message with the parameters
First and Second . This would be the same as calling
CmsMessages.key(StringObject[]) .
If no parameters are appended with "|", this is the same as calling
CmsMessages.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 "|" the resource string for the given key See Also: CmsMessages.key(String,Object[]) See Also: CmsMessages.key(String) |
setBundleName | protected void setBundleName(String bundleName)(Code) | | Sets the bundleName.
Parameters: bundleName - the bundleName to set |
setLocale | protected void setLocale(Locale locale)(Code) | | Sets the locale.
Parameters: locale - the locale to set |
setResourceBundle | protected void setResourceBundle(ResourceBundle resourceBundle)(Code) | | Sets the resource bundle.
Parameters: resourceBundle - the resource bundle to set |
|
|