com.ibm.ras
Class RASMessageCatalog
- java.lang.Object
com.ibm.ras.RASMessageCatalog
Deprecated. As of WAS 6.0, recommend using java.util.logging
- public class RASMessageCatalog
- extends java.lang.Object
RASMessageCatalog
formats messages within the RAS system
according to the current locale (that is, in the
desired language). The text associated with any RAS message is kept
in a java.util.ResourceBundle
. Each message text is associated
with a "key," which is, essentially, a name for the message text.
RASMessageCatalog
formats the message text using a
java.text.MessageFormat
object. One way to define the
messages is through a PropertyResourceBundle
file, backed
up by a Properties
file. Here is a sample:
# {0} is the name of a file. # {1} is the detailed message created when the file creation error # occurred ERR_FILE_WRITER=Unable to create a FileWriter for {0}: {1} # {0} is a text string naming the missing message key. ERR_MISSING_KEY=Message key {0} was not found in any searched catalog. ERR_SOCKET=Unable to connect to the RAS Log Server.To create a message catalog, pass it the base name of the resource bundle. For example, if your base file was
com.ibm.ras.RASMsgs.properties
you would code:
RASMessageCatalog msgCat = new RASMessageCatalog("com.ibm.ras.RASMsgs");Use the
RASMessageCatalog.getMessage
methods to retrieve
the message text in the desired locale. Java will look for the proper
translation of this file according to the supplied or default locale.
For example, it might first search for
RASMsgs_en_GB.properties
, then RASMsgs_en.properties
and, finally RASMsgs.properties
.
RASMessageCatalog
provides a debug mode, which makes it easy to
determine if messages are retrieved from locale-specific resource bundles.
When debug mode is enabled through setDebug
, messages
returned from a RASMessageCatalog
are enclosed in square brackets
("[ ]").
By default, debug mode is disabled. In addition to setDebug
,
the debug mode may be altered by creating a file,
RASMessageCatalog/catalog.properties
and placing it in the root of any
directory in your Java CLASSPATH. For applets, it may also be placed in a
JAR or CAB file. To enable debug mode, this properties file must contain the
property debug=true
. The property debug=false
will
disable debug mode.
When used as part of the RAS Toolkit, it is not necessary for an
application to create a RASMessageCatalog
. If national language support is
required elsewhere, RASMessageCatalog
provides many useful
features.
Constructor Summary
Constructor and Description |
---|
RASMessageCatalog(java.util.ResourceBundle bundle)
Deprecated. Creates a
RASMessageCatalog .
|
RASMessageCatalog(java.util.ResourceBundle bundle,java.util.Locale loc)
Deprecated. Creates a
RASMessageCatalog .
|
RASMessageCatalog(java.lang.String baseName)
Deprecated. Creates a
RASMessageCatalog using the default locale.
|
RASMessageCatalog(java.lang.String baseName,java.util.Locale loc)
Deprecated. Creates a
RASMessageCatalog .
|
Method Summary
Modifier and Type | Method and Description |
---|---|
|
getChar(java.lang.String key)
Deprecated. Gets the first character of a message.
|
|
getLocale()
Deprecated. Gets the locale used by the
RASMessageCatalog .
|
|
getMessage(java.lang.String key)
Deprecated. Gets a message with no inserts from the catalog.
|
|
getMessage(java.lang.String key,java.lang.Object insert1)
Deprecated. Gets a message with one insert from the catalog.
|
|
getMessage(java.lang.String key,java.lang.Object[] inserts)
Deprecated. Gets a message with an array of inserts from the catalog.
|
|
getMessage(java.lang.String key,java.lang.Object insert1,java.lang.Object insert2)
Deprecated. Gets a message with two inserts from the catalog.
|
|
getMsg(java.lang.String key,java.lang.Object[] inserts)
Deprecated. Gets a message with an array of inserts from the catalog.
|
|
isDebug()
Deprecated. Determines if the
RASMessageCatalog is in debug mode.
|
|
setDebug(boolean flag)
Deprecated. Sets the
RASMessageCatalog debug mode.
|
|
setLocale(java.util.Locale loc)
Deprecated. Sets the locale to be used by the
RASMessageCatalog .
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail
RASMessageCatalog
- public RASMessageCatalog(java.lang.String baseName)
- throws java.util.MissingResourceException
baseName
- The base name of the ResourceBundle
which contains the messages. java.util.MissingResourceException
- This exception is thrown if the ResourceBundle
cannot be loaded. RASMessageCatalog
- public RASMessageCatalog(java.lang.String baseName,
- java.util.Locale loc)
- throws java.util.MissingResourceException
RASMessageCatalog
.
baseName
- The base name of the ResourceBundle
which contains the messages. loc
- The locale with which the messages should be
displayed. java.util.MissingResourceException
- This exception is thrown if the ResourceBundle
cannot be loaded. RASMessageCatalog
- public RASMessageCatalog(java.util.ResourceBundle bundle)
RASMessageCatalog
.
bundle
- The ResourceBundle
which contains
the messages. RASMessageCatalog
- public RASMessageCatalog(java.util.ResourceBundle bundle,
- java.util.Locale loc)
RASMessageCatalog
.
Note: Use of this constructor may cause unexpected behavior if the
locale of the ResourceBundle
is not the same as the
locale parameter.
bundle
- The ResourceBundle
which contains
the messages. loc
- The locale with which the messages should be
displayed. Method Detail
getLocale
- public java.util.Locale getLocale( )
RASMessageCatalog
.
Locale.getDefault
is returned. setLocale
- public void setLocale(java.util.Locale loc)
RASMessageCatalog
.
Note: Use of this method may cause unexpected behavior if the
RASMessageCatalog
was created with one of the
constructors that takes a ResourceBundle
as a
parameter. In this case, the RASMessageCatalog
cannot
recreate the ResourceBundle
in the new locale.
loc
- The new locale. If this locale is null
,
the current locale is not changed. isDebug
- public boolean isDebug()
RASMessageCatalog
is in debug mode.
In debug mode, messages retrieved via getMessage
or
getMsg
are enclosed in brackets, "[This is a test],"
for example. This makes it easy to identify those messages which do
not come from locale-specific message bundles.
By default, debug mode is disabled.
true
if debug mode is enabled, or false
otherwise. setDebug
- public void setDebug(boolean flag)
RASMessageCatalog
debug mode.
In debug mode, messages retrieved via getMessage
or
getMsg
are enclosed in brackets, "[This is a test],"
for example. This makes it easy to identify those messages which do
not come from locale-specific message bundles.
By default, debug mode is disabled.
flag
- true
to enable debug mode, or false
otherwise. getMessage
- public java.lang.String getMessage( java.lang.String key)
- throws java.util.MissingResourceException
key
- The key name of this message. java.util.MissingResourceException
- This exception is thrown if a message with the given key
cannot be found in the message catalog. getMessage
- public java.lang.String getMessage( java.lang.String key,
- java.lang.Object insert1)
- throws java.util.MissingResourceException
key
- The key name of this message. insert1
- An element to be inserted into the message. java.util.MissingResourceException
- This exception is thrown if a message with the given key
cannot be found in the message catalog. getMessage
- public java.lang.String getMessage( java.lang.String key,
- java.lang.Object insert1,
- java.lang.Object insert2)
- throws java.util.MissingResourceException
key
- The key name of this message. insert1
- An element to be inserted into the message. insert2
- An element to be inserted into the message. java.util.MissingResourceException
- This exception is thrown if a message with the given key
cannot be found in the message catalog. getMessage
- public java.lang.String getMessage( java.lang.String key,
- java.lang.Object[] inserts)
- throws java.util.MissingResourceException
key
- The key name of this message. inserts
- An array of elements to be inserted into the message. java.util.MissingResourceException
- This exception is thrown if a message with the given key
cannot be found in the message catalog. getMsg
- public java.lang.String getMsg( java.lang.String key,
- java.lang.Object[] inserts)
key
- The key name of this message. inserts
- An array of elements to be inserted into the message. getChar
- public char getChar(java.lang.String key)
Typically, one would define two strings in a message file. For example:
CANCEL=Cancel CANCEL_MNEMONIC=aThe first string is the label to go on a button. The second is the mnemonic character. The method
getMessage("CANCEL")
will return the button label, while getChar("CANCEL_MNEMONIC")
will return the mnemonic character.
key
- The key name of the message. java.util.MissingResourceException
- This exception is thrown if a message with the given key
cannot be found in the message catalog.
RASMessageCatalog
using the default locale.