|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.i18n.MessageManager
The MessageManager
provides methods for retrieving localized
messages and adding custom message providers.
This class should not be called directly for other purposes than registering a custom
MessageProvider
or retrieving information about available
message entries.
To access localized messages a subclass of the LocalizedBundle
class
such as LocalizedText
should be used:
LocalizedText welcome = new LocalizedText("welcome"); // Get the german translacion of the retrieved welcome text System.out.println(welcome.getText(Locale.GERMAN));
You can call getText
directly,
but if you do so, you have to ensure that the given entry key really
exists and to deal with the MessageNotFound
exception that will
be thrown if you try to access a not existing entry.
Field Summary | |
static ResourceBundle |
INTERNAL_MESSAGES
|
static String |
MESSAGE_PARSING_ERROR
|
Constructor Summary | |
MessageManager()
|
Method Summary | |
static void |
addMessageProvider(MessageProvider messageProvider)
Add a custom to the
MessageManager . |
static Map |
getEntries(String id,
Locale locale)
Returns a map containing all available message entries for the given locale. |
static String |
getText(String id,
String entry,
Object[] arguments,
Locale locale)
Iterates over all registered message providers in order to find the given entry in the requested message bundle. |
static String |
getText(String id,
String entry,
Object[] arguments,
Locale locale,
String defaultText)
Iterates over all registered message providers in order to find the given entry in the requested message bundle. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String MESSAGE_PARSING_ERROR
public static final ResourceBundle INTERNAL_MESSAGES
Constructor Detail |
public MessageManager()
Method Detail |
public static void addMessageProvider(MessageProvider messageProvider)
MessageProvider
to the
MessageManager
. It will be incorporated in later calls of
the getText
or getEntries
methods.
messageProvider
- The MessageProvider
to be added.public static String getText(String id, String entry, Object[] arguments, Locale locale) throws MessageNotFoundException
id
- The identifier that will be used to retrieve the message
bundleentry
- The desired message entryarguments
- The dynamic parts of the message that will be evaluated using
the standard java text formatting abilities.locale
- The locale in which the message will be printed
MessageNotFoundException
- Will be thrown if no message bundle can be found for the
given id or if the desired message entry is missing in the
retrieved bundlepublic static String getText(String id, String entry, Object[] arguments, Locale locale, String defaultText)
id
- The identifier that will be used to retrieve the message
bundleentry
- The desired message entryarguments
- The dynamic parts of the message that will be evaluated using
the standard java text formatting abilities.locale
- The locale in which the message will be printeddefaultText
- If no message bundle or message entry could be found for the
specified parameters, the default text will be returned.
public static Map getEntries(String id, Locale locale) throws MessageNotFoundException
String
containing the keys
of the available message entries and values of type String
containing the localized message entries.
MessageNotFoundException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |