Class Messages
- java.lang.Object
-
- org.pentaho.reporting.libraries.base.util.ResourceBundleSupport
-
- org.pentaho.reporting.libraries.base.util.Messages
-
public class Messages extends ResourceBundleSupport
A helper class for a simplified resource-bundle access. This class simply ignores all resource-bundle related errors and prints place-holder strings if a localization key cannot be found.- Author:
- David Kincade
-
-
Constructor Summary
Constructors Constructor Description Messages(java.lang.String baseName)
Creates a new Messages-collection.Messages(java.util.Locale locale, java.lang.String baseName)
Creates a new Messages-collection.Messages(java.util.Locale locale, java.util.ResourceBundle resourceBundle)
Creates a new Messages-collection.Messages(java.util.Locale locale, java.util.ResourceBundle resourceBundle, java.lang.String baseName)
Creates a new Messages-collection.Messages(java.util.ResourceBundle resourceBundle)
Creates a new Messages-collection.Messages(java.util.ResourceBundle resourceBundle, java.lang.String baseName)
Creates a new Messages-collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
formatErrorMessage(java.lang.String key, java.lang.String msg)
Get a formatted error message.java.lang.String
getErrorString(java.lang.String key)
Get a formatted error message from the resource-bundle.java.lang.String
getErrorString(java.lang.String key, java.lang.String param1)
Get a parametrized formatted error message from the resource-bundle.java.lang.String
getErrorString(java.lang.String key, java.lang.String param1, java.lang.String param2)
Get a parametrized formatted error message from the resource-bundle.java.lang.String
getErrorString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3)
Get a parametrized formatted error message from the resource-bundle.java.lang.String
getString(java.lang.String key)
Gets a string for the given key from this resource bundle or one of its parents.java.lang.String
getString(java.lang.String key, java.lang.String param1)
Formats the message stored in the resource bundle (using a MessageFormat).java.lang.String
getString(java.lang.String key, java.lang.String param1, java.lang.String param2)
Formats the message stored in the resource bundle (using a MessageFormat).java.lang.String
getString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3)
Formats the message stored in the resource bundle (using a MessageFormat).java.lang.String
getString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3, java.lang.String param4)
Formats the message stored in the resource bundle (using a MessageFormat).-
Methods inherited from class org.pentaho.reporting.libraries.base.util.ResourceBundleSupport
createMenu, formatMessage, formatMessage, formatMessage, getIcon, getIcon, getKeyStroke, getKeyStroke, getLocale, getMnemonic, getOptionalKeyStroke, getOptionalKeyStroke, getOptionalMnemonic, getResourceURL
-
-
-
-
Constructor Detail
-
Messages
public Messages(java.util.Locale locale, java.lang.String baseName)
Creates a new Messages-collection. The locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
locale
- the locale.baseName
- the baseName of the resource-bundle.- See Also:
ResourceBundle.getBundle(String, Locale)
-
Messages
public Messages(java.util.Locale locale, java.util.ResourceBundle resourceBundle, java.lang.String baseName)
Creates a new Messages-collection. The locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
locale
- the locale.baseName
- the baseName of the resource-bundle.resourceBundle
- a predefined resource-bundle.
-
Messages
public Messages(java.util.Locale locale, java.util.ResourceBundle resourceBundle)
Creates a new Messages-collection. The locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
locale
- the locale.resourceBundle
- a predefined resource-bundle.
-
Messages
public Messages(java.lang.String baseName)
Creates a new Messages-collection. The default locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
baseName
- the baseName of the resource-bundle.
-
Messages
public Messages(java.util.ResourceBundle resourceBundle, java.lang.String baseName)
Creates a new Messages-collection. The default locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
baseName
- the baseName of the resource-bundle.resourceBundle
- a predefined resource-bundle.
-
Messages
public Messages(java.util.ResourceBundle resourceBundle)
Creates a new Messages-collection. The default locale and baseName will be used to create the resource-bundle that backs up this implementation.- Parameters:
resourceBundle
- a predefined resource-bundle.
-
-
Method Detail
-
getString
public java.lang.String getString(java.lang.String key)
Gets a string for the given key from this resource bundle or one of its parents. If the key is a link, the link is resolved and the referenced string is returned instead. If the given key cannot be resolved, no exception will be thrown and a generic placeholder is used instead.- Overrides:
getString
in classResourceBundleSupport
- Parameters:
key
- the key for the desired string- Returns:
- the string for the given key
- Throws:
java.lang.NullPointerException
- ifkey
isnull
java.util.MissingResourceException
- if no object for the given key can be found
-
getString
public java.lang.String getString(java.lang.String key, java.lang.String param1)
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparam1
- the parameter for the message- Returns:
- the formated string
-
getString
public java.lang.String getString(java.lang.String key, java.lang.String param1, java.lang.String param2)
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparam1
- the parameter for the messageparam2
- the parameter for the message- Returns:
- the formated string
-
getString
public java.lang.String getString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3)
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparam1
- the parameter for the messageparam2
- the parameter for the messageparam3
- the parameter for the message- Returns:
- the formated string
-
getString
public java.lang.String getString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3, java.lang.String param4)
Formats the message stored in the resource bundle (using a MessageFormat).- Parameters:
key
- the resourcebundle keyparam1
- the parameter for the messageparam2
- the parameter for the messageparam3
- the parameter for the messageparam4
- the parameter for the message- Returns:
- the formated string
-
formatErrorMessage
public java.lang.String formatErrorMessage(java.lang.String key, java.lang.String msg)
Get a formatted error message. The message consists of two parts. The first part is the error numeric Id associated with the key used to identify the message in the resource file. For instance, suppose the error key is MyClass.ERROR_0068_TEST_ERROR. The first part of the error msg would be "0068". The second part of the returned string is simply themsg
parameter. Currently the format is: error key - error msg For instance: "0068 - A test error message." Currently the format is: error key - error msg For instance: "0069 - You were punched by the donkey."- Parameters:
key
- String containing the key that was used to obtain themsg
parameter from the resource file.msg
- String containing the message that was obtained from the resource file using thekey
parameter.- Returns:
- String containing the formatted error message.
-
getErrorString
public java.lang.String getErrorString(java.lang.String key)
Get a formatted error message from the resource-bundle. The message consists of two parts. The first part is the error numeric Id associated with the key used to identify the message in the resource file. For instance, suppose the error key is MyClass.ERROR_0069_DONKEY_PUNCH. The first part of the error msg would be "0069". The second part of the returned string is simply themsg
parameter. Currently the format is: error key - error msg For instance: "0069 - You were punched by the donkey."- Parameters:
key
- String containing the key that was used to obtain themsg
parameter from the resource file.- Returns:
- String containing the formatted error message.
-
getErrorString
public java.lang.String getErrorString(java.lang.String key, java.lang.String param1)
Get a parametrized formatted error message from the resource-bundle. The message consists of two parts. The first part is the error numeric Id associated with the key used to identify the message in the resource file. For instance, suppose the error key is MyClass.ERROR_0069_DONKEY_PUNCH. The first part of the error msg would be "0069". The second part of the returned string is simply themsg
parameter. Currently the format is: error key - error msg For instance: "0069 - You were punched by the donkey."- Parameters:
key
- String containing the key that was used to obtain themsg
parameter from the resource file.param1
- the parameter for the message- Returns:
- String containing the formatted error message.
-
getErrorString
public java.lang.String getErrorString(java.lang.String key, java.lang.String param1, java.lang.String param2)
Get a parametrized formatted error message from the resource-bundle. The message consists of two parts. The first part is the error numeric Id associated with the key used to identify the message in the resource file. For instance, suppose the error key is MyClass.ERROR_0069_DONKEY_PUNCH. The first part of the error msg would be "0069". The second part of the returned string is simply themsg
parameter. Currently the format is: error key - error msg For instance: "0069 - You were punched by the donkey."- Parameters:
key
- String containing the key that was used to obtain themsg
parameter from the resource file.param1
- the parameter for the messageparam2
- the parameter for the message- Returns:
- String containing the formatted error message.
-
getErrorString
public java.lang.String getErrorString(java.lang.String key, java.lang.String param1, java.lang.String param2, java.lang.String param3)
Get a parametrized formatted error message from the resource-bundle. The message consists of two parts. The first part is the error numeric Id associated with the key used to identify the message in the resource file. For instance, suppose the error key is MyClass.ERROR_0069_DONKEY_PUNCH. The first part of the error msg would be "0069". The second part of the returned string is simply themsg
parameter. Currently the format is: error key - error msg For instance: "0069 - You were punched by the donkey."- Parameters:
key
- String containing the key that was used to obtain themsg
parameter from the resource file.param1
- the parameter for the messageparam2
- the parameter for the messageparam3
- the parameter for the message- Returns:
- String containing the formatted error message.
-
-