|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.i18n.MessageManager
public class 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 MessageNotFoundException
exception that will
be thrown if you try to access a not existing entry.
Constructor Summary | |
---|---|
MessageManager()
|
Method Summary | |
---|---|
static void |
addMessageProvider(java.lang.String providerId,
MessageProvider messageProvider)
Add a custom to the
MessageManager . |
static java.util.Map |
getEntries(java.lang.String id,
java.util.Locale locale)
Returns a map containing all available message entries for the given locale. |
static java.util.Map |
getEntries(java.lang.String providerId,
java.lang.String id,
java.util.Locale locale)
Returns a map containing all available message entries for the given locale. |
static java.lang.String |
getText(java.lang.String id,
java.lang.String entry,
java.lang.Object[] arguments,
java.util.Locale locale)
Iterates over all registered message providers in order to find the given entry in the requested message bundle. |
static java.lang.String |
getText(java.lang.String id,
java.lang.String entry,
java.lang.Object[] arguments,
java.util.Locale locale,
java.lang.String defaultText)
Iterates over all registered message providers in order to find the given entry in the requested message bundle. |
static java.lang.String |
getText(java.lang.String providerId,
java.lang.String id,
java.lang.String entry,
java.lang.Object[] arguments,
java.util.Locale locale)
Tries to find the desired entry in the named message provider. |
static java.lang.String |
getText(java.lang.String providerId,
java.lang.String id,
java.lang.String entry,
java.lang.Object[] arguments,
java.util.Locale locale,
java.lang.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 |
Constructor Detail |
---|
public MessageManager()
Method Detail |
---|
public static void addMessageProvider(java.lang.String providerId, MessageProvider messageProvider)
MessageProvider
to the
MessageManager
. It will be incorporated in later calls of
the getText
or getEntries
methods.
providerId
- Id of the provider used for uninstallation and
qualified naming.messageProvider
- The MessageProvider
to be added.public static java.lang.String getText(java.lang.String id, java.lang.String entry, java.lang.Object[] arguments, java.util.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 java.lang.String getText(java.lang.String id, java.lang.String entry, java.lang.Object[] arguments, java.util.Locale locale, java.lang.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 java.lang.String getText(java.lang.String providerId, java.lang.String id, java.lang.String entry, java.lang.Object[] arguments, java.util.Locale locale) throws MessageNotFoundException
providerId
- The name of the message provider (i.e. source) to use for the messageid
- 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 the requested message provider cannot be found or
no message bundle can be found for the given id or if the desired
message entry is missing in the retrieved bundlepublic static java.lang.String getText(java.lang.String providerId, java.lang.String id, java.lang.String entry, java.lang.Object[] arguments, java.util.Locale locale, java.lang.String defaultText)
providerId
- The name of the message provider (i.e. source) to use for the messageid
- 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 java.util.Map getEntries(java.lang.String id, java.util.Locale locale) throws MessageNotFoundException
String
containing the keys
of the available message entries and values of type String
containing the localized message entries.
MessageNotFoundException
public static java.util.Map getEntries(java.lang.String providerId, java.lang.String id, java.util.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 |