public class CmsMessages
extends java.lang.Object
java.util.ResourceBundle
and provides convenience methods to access the Strings from a template.CmsMessages
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
KEY_SHORT_SUFFIX
The suffix of a "short" localized key name.
|
static java.lang.String |
UNKNOWN_KEY_EXTENSION
Prefix / Suffix for unknown keys.
|
构造器和说明 |
---|
CmsMessages(java.lang.String bundleName)
Default constructor.
|
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
formatMessage(java.lang.String result,
java.lang.Object... args)
Helper method for formatting message parameters.
|
static java.lang.String |
formatUnknownKey(java.lang.String keyName)
Formats an unknown key.
|
CmsMessages |
getBundle()
Returns the localized message bundle wrapped in this instance.
|
java.lang.String |
getBundleName()
Returns the name of the resource bundle.
|
java.lang.String |
getDate(java.util.Date date)
Returns a formated date String from a Date value,
the format being
CmsDateTimeUtil.Format.SHORT and the locale
based on this instance. |
java.lang.String |
getDate(java.util.Date date,
CmsDateTimeUtil.Format format)
Returns a formated date String from a Date value,
the formatting based on the provided option and the locale
based on this instance.
|
java.lang.String |
getDate(long time)
Returns a formated date String from a timestamp value,
the format being
CmsDateTimeUtil.Format.SHORT and the locale
based on this instance. |
java.lang.String |
getDateTime(java.util.Date date)
Returns a formated date and time String from a Date value,
the format being
CmsDateTimeUtil.Format.SHORT and the locale
based on this instance. |
java.lang.String |
getDateTime(java.util.Date date,
CmsDateTimeUtil.Format 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.
|
java.lang.String |
getDateTime(long time)
Returns a formated date and time String from a timestamp value,
the format being
CmsDateTimeUtil.Format.SHORT and the locale
based on this instance. |
com.google.gwt.i18n.client.Dictionary |
getDictionary()
Returns the internal dictionary.
|
static boolean |
isUnknownKey(java.lang.String value)
Returns
true if the provided value matches the scheme
"??? |
java.lang.String |
key(java.lang.String keyName)
Returns the localized resource string for a given message key.
|
java.lang.String |
key(java.lang.String keyName,
boolean allowNull)
Returns the localized resource string for a given message key.
|
java.lang.String |
key(java.lang.String key,
java.lang.Object... args)
Returns the selected localized message for the initialized resource bundle and locale.
|
java.lang.String |
keyDefault(java.lang.String keyName,
java.lang.String defaultValue)
Returns the localized resource string for a given message key.
|
java.lang.String |
keyWithParams(java.lang.String keyName)
Returns the localized resource string for a given message key,
treating all values appended with "|" as replacement parameters.
|
public static final java.lang.String KEY_SHORT_SUFFIX
public static final java.lang.String UNKNOWN_KEY_EXTENSION
public CmsMessages(java.lang.String bundleName)
bundleName
- the localized bundle namepublic static java.lang.String formatMessage(java.lang.String result, java.lang.Object... args)
result
- the raw message containing placeholders like {0}args
- the parameters to insert into the placeholderspublic static java.lang.String formatUnknownKey(java.lang.String keyName)
keyName
- the key to formatisUnknownKey(String)
public static boolean isUnknownKey(java.lang.String value)
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
.
value
- the value to checkformatUnknownKey(String)
public CmsMessages getBundle()
Mainly for API compatibility with the core localization methods.
public java.lang.String getBundleName()
public java.lang.String getDate(java.util.Date date)
CmsDateTimeUtil.Format.SHORT
and the locale
based on this instance.date
- the Date object to format as Stringpublic java.lang.String getDate(java.util.Date date, CmsDateTimeUtil.Format format)
date
- the Date object to format as Stringformat
- the format to use, see CmsDateTimeUtil.Format
for possible valuespublic java.lang.String getDate(long time)
CmsDateTimeUtil.Format.SHORT
and the locale
based on this instance.time
- the time value to format as datepublic java.lang.String getDateTime(java.util.Date date)
CmsDateTimeUtil.Format.SHORT
and the locale
based on this instance.date
- the Date object to format as Stringpublic java.lang.String getDateTime(java.util.Date date, CmsDateTimeUtil.Format format)
date
- the Date object to format as Stringformat
- the format to use, see CmsDateTimeUtil.Format
for possible valuespublic java.lang.String getDateTime(long time)
CmsDateTimeUtil.Format.SHORT
and the locale
based on this instance.time
- the time value to format as datepublic com.google.gwt.i18n.client.Dictionary getDictionary()
public java.lang.String key(java.lang.String keyName)
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.
keyName
- the key for the desired stringpublic java.lang.String key(java.lang.String keyName, boolean allowNull)
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.
keyName
- the key for the desired stringallowNull
- if true, 'null' is an allowed return valuepublic java.lang.String key(java.lang.String key, java.lang.Object... args)
If the key was found in the bundle, it will be formatted using
a
using the provided parameters.MessageFormat
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.
key
- the message keyargs
- the message argumentspublic java.lang.String keyDefault(java.lang.String keyName, java.lang.String defaultValue)
If the key was not found in the bundle, the provided default value is returned.
keyName
- the key for the desired stringdefaultValue
- the default value in case the key does not exist in the bundlepublic java.lang.String keyWithParams(java.lang.String keyName)
If the key was found in the bundle, it will be formatted using
a
using the provided parameters.
The parameters have to be appended to the key separated by a "|".
For example, the keyName MessageFormat
error.message|First|Second
would use the key error.message
with the parameters
First
and Second
. This would be the same as calling
.key(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.
keyName
- the key for the desired string, optionally containing parameters appended with a "|"key(String, Object[])
,
key(String)