org.ceryle.util
Class Localizer

java.lang.Object
  extended by org.ceryle.util.Localizer

public class Localizer
extends Object

Provides localization methods for processing messages. All methods are static.

Note that the Utilities class, and the MessageHandlerImpl class that calls its localization methods, uses a different ResourceBundle than this class, which is bound to Msg.

Since:
JDK1.3
Version:
$Id: Localizer.java,v 3.4 2007-06-15 12:09:56 altheim Exp $
Author:
Murray Altheim

Field Summary
static String[] NumParams
          The numbered String-replacement parameters "%0", "%1", through "%9".
 
Constructor Summary
Localizer()
           
 
Method Summary
static boolean characterMatches(boolean ignoreCase, char c1, char c2)
          Returns true if the character c1 matches character c2, ignoring case (as much as is provided by Java) if the boolean ignoreCase is true.
static String gsub(String src, String srch, String repl, boolean ignoreCase)
          Replace all (non-overlapping) occurrences of a string srch in string src by replacement repl.
static int indexOf(boolean ignoreCase, String source, String substring, int fromIndex)
          Returns the index within String source of the first occurrence of the specified substring, starting at the specified index.
static String localize(String messageId)
          Return a String representing the localized message, provided the unique message identifier messageId.
static String localize(String messageId, String arg1)
          Return a String representing the localized message, provided the unique message identifier messageId and one parameter arg1.
static String localize(String messageId, String arg1, String arg2)
          Return a String representing the localized message, provided the unique message identifier messageId and two parameters arg1 and arg2.
static String localize(String messageId, String arg1, String arg2, String arg3)
          Return a String representing the localized message, provided the unique message identifier messageId and three parameters arg1, arg2, and arg3.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4)
          Return a String representing the localized message, provided the unique message identifier messageId and four parameters arg1, arg2, arg3, and arg4.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4, String arg5)
          Return a String representing the localized message, provided the unique message identifier messageId and five parameters arg1, arg2, arg3, arg4, and arg5.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6)
          Return a String representing the localized message, provided the unique message identifier messageId and six parameters arg1, arg2, arg3, arg4, arg5, and arg6.
static String process(String id, Object[] args)
          Get message text from the default, localized ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NumParams

public static final String[] NumParams
The numbered String-replacement parameters "%0", "%1", through "%9".

Constructor Detail

Localizer

public Localizer()
Method Detail

localize

public static String localize(String messageId)
Return a String representing the localized message, provided the unique message identifier messageId. This provides the same functionality in a static wrapper of MessageHandler's localize method.

Parameters:
messageId - The unique message identifier.
Returns:
The localized String.
See Also:
MessageHandler.localize(String)

localize

public static String localize(String messageId,
                              String arg1)
Return a String representing the localized message, provided the unique message identifier messageId and one parameter arg1.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2)
Return a String representing the localized message, provided the unique message identifier messageId and two parameters arg1 and arg2.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
arg2 - A parameter string to be inserted at %2.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3)
Return a String representing the localized message, provided the unique message identifier messageId and three parameters arg1, arg2, and arg3.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
arg2 - A parameter string to be inserted at %2.
arg3 - A parameter string to be inserted at %3.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4)
Return a String representing the localized message, provided the unique message identifier messageId and four parameters arg1, arg2, arg3, and arg4.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
arg2 - A parameter string to be inserted at %2.
arg3 - A parameter string to be inserted at %3.
arg4 - A parameter string to be inserted at %4.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4,
                              String arg5)
Return a String representing the localized message, provided the unique message identifier messageId and five parameters arg1, arg2, arg3, arg4, and arg5.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
arg2 - A parameter string to be inserted at %2.
arg3 - A parameter string to be inserted at %3.
arg4 - A parameter string to be inserted at %4.
arg5 - A parameter string to be inserted at %5.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4,
                              String arg5,
                              String arg6)
Return a String representing the localized message, provided the unique message identifier messageId and six parameters arg1, arg2, arg3, arg4, arg5, and arg6.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter string to be inserted at %1.
arg2 - A parameter string to be inserted at %2.
arg3 - A parameter string to be inserted at %3.
arg4 - A parameter string to be inserted at %4.
arg5 - A parameter string to be inserted at %5.
arg6 - A parameter string to be inserted at %6.
Returns:
The localized String.

gsub

public static final String gsub(String src,
                                String srch,
                                String repl,
                                boolean ignoreCase)
Replace all (non-overlapping) occurrences of a string srch in string src by replacement repl. If the pattern isn't found, the string is returned unchanged.

Parameters:
src - any string.
srch - the string to search for.
repl - the replacement string.
ignoreCase - a boolean determining case sensitivity of matches.
Returns:
Returns the string with all instances of the search pattern replaced by the replacement string. If no occurrences of the search pattern are found, returns the string unchanged.

process

public static String process(String id,
                             Object[] args)
Get message text from the default, localized ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.


indexOf

public static int indexOf(boolean ignoreCase,
                          String source,
                          String substring,
                          int fromIndex)
Returns the index within String source of the first occurrence of the specified substring, starting at the specified index. If the boolean ignoreCase is false, this performs the same as the java.lang.String method of similar ilk. This method is suitable for large source strings.

Also, as with java.lang.String's indexOf() method, there is no restriction on the value of fromIndex: if it exceeds either start or end boundary, it is set to that boundary.

This is a copy of the method from org.ceryle.util.Utilities made for portability.

Parameters:
source - the string to search within.
substring - the substring to search for.
fromIndex - the index to start the search from.
Returns:
the index of the first matching character of the substring within the source string, or -1 if no match.
Throws:
NullPointerException - if source is null

characterMatches

public static boolean characterMatches(boolean ignoreCase,
                                       char c1,
                                       char c2)
Returns true if the character c1 matches character c2, ignoring case (as much as is provided by Java) if the boolean ignoreCase is true.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.