org.apache.commons.i18n
Class MessageManager

java.lang.Object
  extended byorg.apache.commons.i18n.MessageManager

public class MessageManager
extends Object

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 LocalizedBundleclass such as LocalizedText should be used:

LocalizedText welcome = new LocalizedText("welcome"); // Using the default locale System.out.println(welcome.getText()); // Using some other locale 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.


Constructor Summary
MessageManager()
           
 
Method Summary
static void addMessageProvider(MessageProvider messageProvider)
          Add a custom MessageProvider 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
 

Constructor Detail

MessageManager

public MessageManager()
Method Detail

addMessageProvider

public static void addMessageProvider(MessageProvider messageProvider)
Add a custom MessageProvider to the MessageManager. It will be incorporated in later calls of the getText or getEntriesmethods.

Parameters:
messageProvider - The MessageProvider to be added.

getText

public static String getText(String id,
                             String entry,
                             Object[] arguments,
                             Locale locale)
                      throws MessageNotFoundException
Iterates over all registered message providers in order to find the given entry in the requested message bundle.

Parameters:
id - The identifier that will be used to retrieve the message bundle
entry - The desired message entry
arguments - 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
Returns:
The localized text
Throws:
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 bundle

getText

public 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.

Parameters:
id - The identifier that will be used to retrieve the message bundle
entry - The desired message entry
arguments - 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
defaultText - If no message bundle or message entry could be found for the specified parameters, the default text will be returned.
Returns:
The localized text or the default text if the message could not be found

getEntries

public static Map getEntries(String id,
                             Locale locale)
                      throws MessageNotFoundException
Returns a map containing all available message entries for the given locale. The map contains keys of type Stringcontaining the keys of the available message entries and values of type String containing the localized message entries.

Throws:
MessageNotFoundException


Copyright © 2004-2005 The Apache Software Foundation. All Rights Reserved.