|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.metamatrix.common.properties.PropertyManager
com.metamatrix.common.properties.TextManager
public class TextManager
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.
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 |
---|
public static final java.lang.String[] DEFAULT_NAMESPACES
public static TextManager INSTANCE
Constructor Detail |
---|
protected TextManager()
protected TextManager(java.lang.String namespace)
namespace
- The namespace identifierprotected TextManager(java.lang.String[] namespaces)
namespaces
- The list of namespace identifiersprotected TextManager(java.util.List namespaces)
namespaces
- The list of namespace identifiersprotected TextManager(java.lang.String namespace, java.util.Map propertyMap)
namespace
- The namespace identifierpropertyMap
- The map into which the property values are loadedMethod Detail |
---|
public java.lang.String getText(java.lang.String key)
getText(String, Object)
with no substitution parameters.
public java.lang.String getText(java.lang.String key, boolean parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, byte parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, char parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, short parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, int parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, long parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, float parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, double parameter)
getText(String, Object)
.
public java.lang.String getText(java.lang.String key, java.lang.Object parameter)
getText(String, List)
.
public java.lang.String getText(java.lang.String key, java.lang.Object parameter1, java.lang.Object parameter2)
getText(String, List)
.
public java.lang.String getText(java.lang.String key, java.lang.Object parameter1, java.lang.Object parameter2, java.lang.Object parameter3)
getText(String, List)
.
public java.lang.String getText(java.lang.String key, java.lang.Object[] parameters)
key
- the property keyparameters
- the data placed into the text
public java.lang.String getText(java.lang.String key, java.util.List parameters)
key
- The key identifying the textparameters
- The list of parameters used to replace placeholders in text
public java.lang.String translate(java.lang.String key)
key
- The key identifying the text
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |