com.zphinx.spine.message
Class SpineMessageManager

java.lang.Object
  extended by com.zphinx.spine.message.SpineMessageManager

public class SpineMessageManager
extends Object

SpineMessageManager is a minimal implementation of the apache I18N MessageManager object. It provides the base methods needed by spine and adds extra functionality to the MessageManager Object.

It also contains bug fixes for errors found in MessageManager

Version:
$1.0

Copyright ©Zphinx Software Solutions

Author:
David Ladapo

Field Summary
(package private) static String INTERNAL_MESSAGE_NOT_FOUND
           
(package private) static String MESSAGE_ENTRY_NOT_FOUND
           
(package private) static String MESSAGE_NOT_FOUND
           
(package private) static String NO_MESSAGE_ENTRIES_FOUND
           
(package private) static String RESOURCE_BUNDLE_NOT_FOUND
           
 
Method Summary
static void addMessageProvider(String providerId, org.apache.commons.i18n.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 Map getEntries(String providerId, String id, Locale locale)
          Returns a map containing all available message entries in the stated provider, for the given locale.
static String getText(String providerId, String id, String entry, Object[] arguments, Locale locale)
          Tries to find the desired entry in the named message provider.
static String getText(String providerId, String id, String entry, Object[] arguments, Locale locale, String defaultText)
          Attempts to find the requested message from the registered message provider in order to find the given entry in the requested message bundle.
static void removeMessageProvider(String providerId)
          Remove custom MessageProvider from the MessageManager.
static String searchMessages(String providerId, String id, String entry, Object[] arguments, Locale locale, String defaultText)
          This method first looks in the provider given for the occurence of the entry, then recursively searchs the other providers in the system for the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERNAL_MESSAGE_NOT_FOUND

static final String INTERNAL_MESSAGE_NOT_FOUND
See Also:
Constant Field Values

MESSAGE_NOT_FOUND

static final String MESSAGE_NOT_FOUND
See Also:
Constant Field Values

NO_MESSAGE_ENTRIES_FOUND

static final String NO_MESSAGE_ENTRIES_FOUND
See Also:
Constant Field Values

MESSAGE_ENTRY_NOT_FOUND

static final String MESSAGE_ENTRY_NOT_FOUND
See Also:
Constant Field Values

RESOURCE_BUNDLE_NOT_FOUND

static final String RESOURCE_BUNDLE_NOT_FOUND
See Also:
Constant Field Values
Method Detail

addMessageProvider

public static void addMessageProvider(String providerId,
                                      org.apache.commons.i18n.MessageProvider messageProvider)
Add a custom MessageProvider to the MessageManager. It will be incorporated in later calls of the getText or getEntriesmethods.

Parameters:
providerId - Id of the provider used for uninstallation and qualified naming.
messageProvider - The MessageProvider to be added.

removeMessageProvider

public static void removeMessageProvider(String providerId)
Remove custom MessageProvider from the MessageManager. Used for tearing down unit tests.

Parameters:
providerId - The ID of the provider to remove.

getText

public static String getText(String providerId,
                             String id,
                             String entry,
                             Object[] arguments,
                             Locale locale)
                      throws org.apache.commons.i18n.MessageNotFoundException
Tries to find the desired entry in the named message provider.

Parameters:
providerId - The name of the message provider (i.e. source) to use for the message
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:
org.apache.commons.i18n.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 bundle

getText

public static String getText(String providerId,
                             String id,
                             String entry,
                             Object[] arguments,
                             Locale locale,
                             String defaultText)
Attempts to find the requested message from the registered message provider in order to find the given entry in the requested message bundle.

Parameters:
providerId - The name of the message provider (i.e. source) to use for the message
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 org.apache.commons.i18n.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. available within all the message providers.

Parameters:
id - The key to search for in this manager
locale - The locale in which the entries are expected to be located
Returns:
A map of all the keys in all the providers registeerd with this manager
Throws:
org.apache.commons.i18n.MessageNotFoundException

getEntries

public static Map getEntries(String providerId,
                             String id,
                             Locale locale)
                      throws org.apache.commons.i18n.MessageNotFoundException
Returns a map containing all available message entries in the stated provider, 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.

Parameters:
providerId - The name of the message provider (i.e. source) to use for the message
id - The identifier that will be used to retrieve the message bundle
locale - The locale in which the message will be printed
Returns:
A map of all the entries in the MessageProvider
Throws:
org.apache.commons.i18n.MessageNotFoundException

searchMessages

public static String searchMessages(String providerId,
                                    String id,
                                    String entry,
                                    Object[] arguments,
                                    Locale locale,
                                    String defaultText)
                             throws Throwable
This method first looks in the provider given for the occurence of the entry, then recursively searchs the other providers in the system for the key. The entry key is returned if non is found.

Parameters:
providerId - The name of the message provider (i.e. source) to use for the message
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
Throws:
Throwable - if an error occurs