com.metamatrix.common.properties
Class TextManager

java.lang.Object
  extended by com.metamatrix.common.properties.PropertyManager
      extended by com.metamatrix.common.properties.TextManager
All Implemented Interfaces:
LogCommonConstants
Direct Known Subclasses:
ObjectPropertyManager, UiTextManager

public class TextManager
extends PropertyManager

In addition to the feautures provided by PropertyManager, TextManager adds support for language translation from simple words to entire strings of text. Messages that would normally be hardcoded as strings can be replaced with simple calls to one of TextManager's getText methods, which use keys to lookup locale-specific text in one or more registered resource bundles. The text within bundles may contain indexed placeholders in the form described by MessageFormat, which is basically index numbers (relative to zero) surrounded by curly braces. All but one of the getText methods take additional arguments that will be dynamically inserted into the text so that the nth parameter will be inserted into the placeholder with an index of n.

Example:

Resource Bundle (com/metamatrix/common/logmessages.properties)

MSG.001.001.0001 = {0} \"{1}\" not found in {2}

Code

CommonPlugin.Util.getString("MSG.001.001.0001", "File", "java.exe", "directory /bin")

Resulting value

File "java.exe" not found in directory /bin

Each of the getText methods simply returns the key surrounded by angle brackets ('<' and '>') if no translation can be found in any of the registered namespaces. This provides an application with the ability to use getText methods everywhere that text may need to be translated. For single words, the single-parameter getText(String) method can be used to pass the word itself as the key. If no translation is found, the word is simply returned (without angle brackets).

TextManager is a singleton with a default registered namespace. Subclasses my remove this namespace and/or provide additional namespaces.

Since:
2.1

Field Summary
static java.lang.String[] DEFAULT_NAMESPACES
          The default namespace searched by TextManager.
static TextManager INSTANCE
           
 
Fields inherited from interface com.metamatrix.common.util.LogCommonConstants
CTX_BUFFER_MGR, CTX_CONFIG, CTX_CONTROLLER, CTX_DBIDGEN, CTX_DISTRIB_CACHE, CTX_EXTENSION_SOURCE, CTX_EXTENSION_SOURCE_JDBC, CTX_LOGGING, CTX_LOGON, CTX_MESSAGE_BUS, CTX_POOLING, CTX_PROXY, CTX_SERVICE, CTX_STANDARD_ERR, CTX_STANDARD_OUT, CTX_STORAGE_MGR, CTX_TXN_LOG, CTX_XA_TXN, TYPE_DEBUG, TYPE_ERROR, TYPE_EXCEPTION, TYPE_INFO, TYPE_TRACE, TYPE_WARNING
 
Constructor Summary
protected TextManager()
          Creates an instance of TextManager with a default registered resource bundle used by other Toolbox classes.
protected TextManager(java.util.List namespaces)
          Creates an instance of TextManager that will retrieve property values from the specified list of namespaces.
protected TextManager(java.lang.String namespace)
          Creates an instance of TextManager that will retrieve property values from the specified namespace.
protected TextManager(java.lang.String[] namespaces)
          Creates an instance of TextManager that will retrieve property values from the specified list of namespaces.
protected TextManager(java.lang.String namespace, java.util.Map propertyMap)
          Creates an instance of TextManager that will retrieve property values from the specified namespace.
 
Method Summary
 java.lang.String getText(java.lang.String key)
          Convenience method that calls getText(String, Object) with no substitution parameters.
 java.lang.String getText(java.lang.String key, boolean parameter)
          Convenience method that wraps the specified parameter in a Boolean object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, byte parameter)
          Convenience method that wraps the specified parameter in a Byte object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, char parameter)
          Convenience method that wraps the specified parameter in a Character object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, double parameter)
          Convenience method that wraps the specified parameter in a Double object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, float parameter)
          Convenience method that wraps the specified parameter in a Float object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, int parameter)
          Convenience method that wraps the specified parameter in a Integer object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, java.util.List parameters)
          Retrieves the text identified by the specified key, replacing indexed placeholders with values from the specified list of parameters so that the nth parameter will be inserted into the placeholder with an index of n.
 java.lang.String getText(java.lang.String key, long parameter)
          Convenience method that wraps the specified parameter in a Long object before calling getText(String, Object).
 java.lang.String getText(java.lang.String key, java.lang.Object parameter)
          Convenience method that adds the specified parameter to a list before calling getText(String, List).
 java.lang.String getText(java.lang.String key, java.lang.Object[] parameters)
          Gets text substituting values from the given array into the proper place.
 java.lang.String getText(java.lang.String key, java.lang.Object parameter1, java.lang.Object parameter2)
          Convenience method that adds the specified parameters to a list before calling getText(String, List).
 java.lang.String getText(java.lang.String key, java.lang.Object parameter1, java.lang.Object parameter2, java.lang.Object parameter3)
          Convenience method that adds the specified parameters to a list before calling getText(String, List).
 java.lang.String getText(java.lang.String key, short parameter)
          Convenience method that wraps the specified parameter in a Short object before calling getText(String, Object).
 java.lang.String translate(java.lang.String key)
          Retrieves the text identified by the specified key, or if not found, returns the key itself.
 
Methods inherited from class com.metamatrix.common.properties.PropertyManager
addNamespace, addNamespace, addNamespaces, addNamespaces, clearNamespaces, constructPropertyManager, evaluateValue, get, getLoadedNamespaces, getNamespaces, initializeNamespaces, isNamespaceLoaded, isNamespaceRegistered, load, load, load, reload, reload, removeNamespace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAMESPACES

public static final java.lang.String[] DEFAULT_NAMESPACES
The default namespace searched by TextManager.

Since:
2.1

INSTANCE

public static TextManager INSTANCE
Constructor Detail

TextManager

protected TextManager()
Creates an instance of TextManager with a default registered resource bundle used by other Toolbox classes.

Since:
2.1

TextManager

protected TextManager(java.lang.String namespace)
Creates an instance of TextManager that will retrieve property values from the specified namespace.

Parameters:
namespace - The namespace identifier
Since:
3.1

TextManager

protected TextManager(java.lang.String[] namespaces)
Creates an instance of TextManager that will retrieve property values from the specified list of namespaces. The namespaces will be searched in ascending order, starting with the first namespace registered.

Parameters:
namespaces - The list of namespace identifiers
Since:
3.1

TextManager

protected TextManager(java.util.List namespaces)
Creates an instance of TextManager that will retrieve property values from the specified list of namespaces. The namespaces will be searched in ascending order, starting with the first namespace registered.

Parameters:
namespaces - The list of namespace identifiers
Since:
3.1

TextManager

protected TextManager(java.lang.String namespace,
                      java.util.Map propertyMap)
Creates an instance of TextManager that will retrieve property values from the specified namespace. Properties from the resource bundle identified by the namespace will be loaded into the specified property map.

Parameters:
namespace - The namespace identifier
propertyMap - The map into which the property values are loaded
Since:
3.1
Method Detail

getText

public java.lang.String getText(java.lang.String key)
Convenience method that calls getText(String, Object) with no substitution parameters.

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                boolean parameter)
Convenience method that wraps the specified parameter in a Boolean object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                byte parameter)
Convenience method that wraps the specified parameter in a Byte object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                char parameter)
Convenience method that wraps the specified parameter in a Character object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                short parameter)
Convenience method that wraps the specified parameter in a Short object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                int parameter)
Convenience method that wraps the specified parameter in a Integer object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                long parameter)
Convenience method that wraps the specified parameter in a Long object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                float parameter)
Convenience method that wraps the specified parameter in a Float object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                double parameter)
Convenience method that wraps the specified parameter in a Double object before calling getText(String, Object).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.Object parameter)
Convenience method that adds the specified parameter to a list before calling getText(String, List).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.Object parameter1,
                                java.lang.Object parameter2)
Convenience method that adds the specified parameters to a list before calling getText(String, List).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.Object parameter1,
                                java.lang.Object parameter2,
                                java.lang.Object parameter3)
Convenience method that adds the specified parameters to a list before calling getText(String, List).

Since:
2.1

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.Object[] parameters)
Gets text substituting values from the given array into the proper place.

Parameters:
key - the property key
parameters - the data placed into the text
Returns:
the locale-specific text
Since:
3.1

getText

public java.lang.String getText(java.lang.String key,
                                java.util.List parameters)
Retrieves the text identified by the specified key, replacing indexed placeholders with values from the specified list of parameters so that the nth parameter will be inserted into the placeholder with an index of n.

Parameters:
key - The key identifying the text
parameters - The list of parameters used to replace placeholders in text
Returns:
The text
Since:
2.1

translate

public java.lang.String translate(java.lang.String key)
Retrieves the text identified by the specified key, or if not found, returns the key itself. This method is intended for single word translations.

Parameters:
key - The key identifying the text
Returns:
The text, or the key if not found
Since:
3.1


Copyright © 2009. All Rights Reserved.