org.zkoss.mesg
Class Messages

java.lang.Object
  extended by org.zkoss.mesg.Messages
All Implemented Interfaces:
MessageConst

public class Messages
extends java.lang.Object
implements MessageConst

The message manager. This class manages how an message is retrieved based on the message code and the locale.

Note: unlike MessageFormat's default behavior, all null objects are treated as an empty string rather than "null".

Author:
tomyeh

Nested Class Summary
static interface Messages.Formatter
          The formatter used by get(int, Object[], Locale) to format the specified object.
 
Nested classes/interfaces inherited from interface org.zkoss.mesg.MessageConst
MessageConst.Aide, MessageConst.BundleInfo
 
Field Summary
 
Fields inherited from interface org.zkoss.mesg.MessageConst
NULL_CODE
 
Constructor Summary
protected Messages()
           
 
Method Summary
static java.lang.String get(int code)
          Gets a message based on the specified code without formating arguments.
static java.lang.String get(int code, java.lang.Object fmtArg)
          Gets a message based on the locale of current user with ONE format-argument.
static java.lang.String get(int code, java.lang.Object[] fmtArgs)
          Gets a message based on the locale of current user.
static java.lang.String get(int code, java.lang.Object[] fmtArgs, java.util.Locale locale)
          Gets a message based on the specified code.
static Messages.Formatter getFormatter()
          Returns the formatter used by get(int, Object[], Locale), or null if not set.
static int getType(int code)
          Gets the message type of the specified code.
static void setFormatter(Messages.Formatter fmt)
          Sets the formatter used by get(int, Object[], Locale).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Messages

protected Messages()
Method Detail

get

public static final java.lang.String get(int code)
Gets a message based on the specified code without formating arguments.

Equivalent to get(code, null).


get

public static final java.lang.String get(int code,
                                         java.lang.Object fmtArg)
Gets a message based on the locale of current user with ONE format-argument.


get

public static final java.lang.String get(int code,
                                         java.lang.Object[] fmtArgs)
Gets a message based on the locale of current user.

Equivalent to get(code, fmtArgs, current_locale). The current_locale argument depends on the implementation.


get

public static java.lang.String get(int code,
                                   java.lang.Object[] fmtArgs,
                                   java.util.Locale locale)
Gets a message based on the specified code. If not found, returns an error message to denote it.

If fmtArgs is not null, MessageFormats.format(java.lang.String, java.lang.Object[], java.util.Locale) is called to format the message. However, unlike MessageFormat's default behavior, all null objects are treated as an empty string rather than "null".

It also recognizes Objects.UNKNOWN.

Parameters:
code - the code
fmtArgs - the argument lists to format the message
locale - the locale of the message to load
Returns:
the message; never be null

getFormatter

public static Messages.Formatter getFormatter()
Returns the formatter used by get(int, Object[], Locale), or null if not set.


setFormatter

public static void setFormatter(Messages.Formatter fmt)
Sets the formatter used by get(int, Object[], Locale).

Default: null.


getType

public static final int getType(int code)
Gets the message type of the specified code.



Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo