ccs.utils
Class MsgHelper

java.lang.Object
  extended by ccs.utils.MsgHelper

public class MsgHelper
extends java.lang.Object

Helps your app provide I18N'ed messages and other strings. Your app should contain terse key strings with no embedded whitespace; we use a convention similar to the unix convention for error constants. The first letter or bigraph of the string indicates which type of message this is:

The remaining prefix letters are reserved for future expansion. The main identifier which follows the prefix should start with a capital; in this way there is no ambiguity between a two-letter prefix and a main identifier that happens to start with an "M" or a "G".

For applications which will (or might) run as InternalTasks inside CPCC or as plug-ins inside CPC, you have an extra responsibility: since many such apps may be running simultaneously inside the same message namespaces, you must disambiguate these strings by prepending at least your usual base package name to the names. You must further ensure that there are no name clashes within this disambiguated namespace which you control; you might care to do this by extending the prepended package names, but this is up to you.

For example, if your app's main class is org.myhouse.myapp.App and it runs as an InternalTask, then one of its error message defns might be org.myhouse.EBroken=Application has died horribly, please reboot.

Within these disambiguated namespaces, all prefix letters are available for you to use as you like, although it's best to stick to the standard scheme unless you have a good reason not to.

As a special case, the fully-qualified name of any throwable, used as a key string (without any prefix letter/s), should be a human-readable description of that throwable.


Field Summary
static int ARGH
          Constant for msgBox: display the severe, no-entry icon.
static int GUESS
          Constant for msgBox: use your initiative to work out the right icon.
static int LOSE
          Constant for msgBox: display the ordinary, exclamation mark icon.
 
Constructor Summary
MsgHelper()
           
 
Method Summary
static void addBundle(java.lang.String bundleName)
          add a bundle to be used by translateMessage methods.
static boolean hasTranslation(java.lang.String msg)
          Whether an internationalised version of the message exists.
static void msgBox(java.awt.Component frame, java.lang.Throwable th)
          Display a message box announcing the supplied throwable, and always guessing the correct icon.
static void msgBox(java.awt.Component frame, java.lang.Throwable th, int iconCode)
          Display a message box announcing the supplied throwable.
static java.lang.String multixlat(java.lang.String msg)
          Translate a message which contains multiple space-separated I18N keys - it tokenises the string and calls xlat for each.
static java.lang.String translate(java.lang.String msg)
          Alias for translateMessage(String).
static java.lang.String translateMessage(java.lang.String msg)
          Returns an internationalised version of the supplied message.
static java.lang.String translateMessage(java.lang.Throwable th)
          returns an internationalised version of this throwable's message string.
static java.lang.String translateName(java.lang.Throwable th)
          returns a helpful, internationalised description of what this throwable is about.
static java.lang.String xlat(java.lang.String msg)
          Even briefer alias for translateMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOSE

public static final int LOSE
Constant for msgBox: display the ordinary, exclamation mark icon.

See Also:
Constant Field Values

GUESS

public static final int GUESS
Constant for msgBox: use your initiative to work out the right icon.

See Also:
Constant Field Values

ARGH

public static final int ARGH
Constant for msgBox: display the severe, no-entry icon.

See Also:
Constant Field Values
Constructor Detail

MsgHelper

public MsgHelper()
Method Detail

translateName

public static java.lang.String translateName(java.lang.Throwable th)
returns a helpful, internationalised description of what this throwable is about. This never returns null.


translateMessage

public static java.lang.String translateMessage(java.lang.Throwable th)
returns an internationalised version of this throwable's message string. This ought to be a cryptic code in the C / Unix tradition (e.g. EBig for file too big). Kernel codes begin with EK, not just E. If the message is null, it changes it to ENotTelling and goes from there. If there is no such key in the message bundle, it returns the original message, with a warning.


translateMessage

public static java.lang.String translateMessage(java.lang.String msg)
Returns an internationalised version of the supplied message. If the message contains a space character, then everything before the space will be taken as the I18N key (and translated), and everything including and after it will be added unchanged. This allows installation-specific information to be added easily. (E.g. for error messages). Otherwise, the entire message will be used as the key. If the message is null, it changes it to ENotTelling and goes from there. If there is no such key in the message bundle, it returns the original message, optionally with a warning.


hasTranslation

public static boolean hasTranslation(java.lang.String msg)
Whether an internationalised version of the message exists.


xlat

public static java.lang.String xlat(java.lang.String msg)
Even briefer alias for translateMessage.


multixlat

public static java.lang.String multixlat(java.lang.String msg)
Translate a message which contains multiple space-separated I18N keys - it tokenises the string and calls xlat for each. This is heavier and slower than the alternatives. It won't work well if the debugging property ccs.utils.showBrokenI18N is set.


translate

public static java.lang.String translate(java.lang.String msg)
Alias for translateMessage(String). Use the alias for brevity wherever this does not cause loss of clarity.


addBundle

public static void addBundle(java.lang.String bundleName)
add a bundle to be used by translateMessage methods.

Parameters:
bundleName - The bundle base name. The bundle for the default locale (if present) will be selected. Bundle naming / resolution follows the same rules as for classes: for details, see java.util.ResourceBundle.

msgBox

public static void msgBox(java.awt.Component frame,
                          java.lang.Throwable th)
Display a message box announcing the supplied throwable, and always guessing the correct icon.

Parameters:
frame - The frame (if any) the message box should depend from.
th - The Throwable to present.

msgBox

public static void msgBox(java.awt.Component frame,
                          java.lang.Throwable th,
                          int iconCode)
Display a message box announcing the supplied throwable.

Parameters:
frame - The frame (if any) the message box should depend from.
th - The Throwable to present.
iconCode - which icon to display - a constant from this class.