public class SimpleMessageHandler extends Object implements MessageHandler
MessageBundle
. Uses the default Java i18n API.
It works by searching the localized message bundle information at runtime (via annotations). If the
localized message (with this internationalization handler) cannot be found with the information of the
given type, it keeps looking in the super classes (and interfaces) until the localized message is found.
Enjoy Java i18n and l10n!Modifier | Constructor and Description |
---|---|
protected |
SimpleMessageHandler(Locale locale,
Boolean throwsException)
Protected constructor for the default internationalization message handler.
|
Modifier and Type | Method and Description |
---|---|
static MessageHandler |
getDefaultMessageHandler()
Gets the message handler for the current environment with default locale.
|
Locale |
getLocale()
Gets the locale for the messages.
|
String |
getMessage(Class<?> type,
Locale locale,
String key,
Object[] parametersValues)
Gets a localized message with the given key and parameters values of the defined type.
|
String |
getMessage(Object type,
Locale locale,
String key,
Object[] parametersValues)
Gets a message with the given key and parameters values of the defined type.
|
static MessageHandler |
getMessageHandler(Locale locale)
Gets the message handler for the current environment.
|
static MessageHandler |
getMessageHandler(Locale locale,
Boolean throwsException)
Gets the message handler for the current environment.
|
Boolean |
getThrowsException()
Gets if the message handler should raise an exception when the message is not found.
|
void |
setThrowsException(Boolean throwsException)
Sets if the message handler should raise an exception when the message is not found.
|
protected SimpleMessageHandler(Locale locale, Boolean throwsException)
locale
- Locale for the new instance.throwsException
- If the message handler should raise an exception when the message is not found. If false,
the message key is returned when the message cannot be found.public Boolean getThrowsException()
public void setThrowsException(Boolean throwsException)
throwsException
- If the message handler should raise an exception when the message is not found. If false,
the message key is returned when the message cannot be found.public Locale getLocale()
public static MessageHandler getMessageHandler(Locale locale, Boolean throwsException)
locale
- Locale for the message handler to use.throwsException
- If the message handler should raise an exception when the message is not found. If false,
the message key is returned when the message cannot be found.public static MessageHandler getMessageHandler(Locale locale)
locale
- Locale for the message handler to use.public static MessageHandler getDefaultMessageHandler()
public String getMessage(Class<?> type, Locale locale, String key, Object[] parametersValues) throws MessageNotFoundException, org.dejava.component.exception.localized.unchecked.InvalidParameterException
type
- Type of the message. Must be annotated with MessageBundle
.locale
- Locale for the message. If no locale is provided, the message handler locale is used.key
- Key for the localized message in the bundle.parametersValues
- Parameter values for the message.MessageNotFoundException
- If the localized message cannot be found.org.dejava.component.exception.localized.unchecked.InvalidParameterException
- If any of the parameters values are not valid.public String getMessage(Object type, Locale locale, String key, Object[] parametersValues) throws MessageNotFoundException, org.dejava.component.exception.localized.unchecked.InvalidParameterException
MessageHandler
getMessage
in interface MessageHandler
type
- Type of the message (containing the bundle information).locale
- Locale for the message.key
- Key for the message in the bundle.parametersValues
- Parameter values for the message.MessageNotFoundException
- If the message cannot be found.org.dejava.component.exception.localized.unchecked.InvalidParameterException
- If any of the parameters values are not valid.MessageHandler.getMessage(java.lang.Object,
java.util.Locale, java.lang.String, java.lang.Object[])
Copyright © 2013. All Rights Reserved.