|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.util.Bundlizer
public class Bundlizer
A class that handles String replacement using ResourceBundles.
The first parameter id may be an ID reference from the localized ListResourceBundle, or if not recognized as such, will be treated simply as a message String. Following the initial id, there are additional methods available with one to four additional passed parameters, each returning the localized result.
public String message( String id ) public String message( String id, String arg1 ) public String message( String id, String arg1, String arg2 ) public String message( String id, String arg1, String arg2, String arg3 ) public String message( String id, String arg1, String arg2, String arg3, String arg4 )
In use, it's simply a matter of passing a reference to a ResourceBundle ID (e.g., "MessageId.M147" below) plus any arguments:
String s = bndlizer.get(MessageId.M147,arg1,arg2);
setBundle(String).
| Field Summary | |
|---|---|
static String |
defaultBundleName
A reference to the class baseName for the default ResourceBundle. |
protected Hashtable |
m_bundles
|
static String[] |
NParams
The numbered String-replacement parameters "%0" through "%4". |
| Constructor Summary | |
|---|---|
Bundlizer()
Default constructor. |
|
| Method Summary | |
|---|---|
boolean |
addBundle(String baseName,
Locale locale)
Adds a named ResourceBundle for the given Locale to the registry by reference to its baseName. |
ResourceBundle |
getDefaultBundle()
Returns the default ResourceBundle for the default locale. |
String |
localize(String id)
Return a localized message given a message id and no arguments. |
String |
localize(String id,
String arg1)
Return a localized message given a message id and one argument. |
String |
localize(String id,
String arg1,
String arg2)
Return a localized message given a message id and two arguments. |
String |
localize(String id,
String arg1,
String arg2,
String arg3)
Return a localized message given a message id and three arguments. |
String |
localize(String id,
String arg1,
String arg2,
String arg3,
String arg4)
Return a localized message given a message id and four arguments. |
String |
processMessage(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. |
String |
processMessage(String id,
Object[] args,
ResourceBundle bundle)
Get message text from the supplied ResourceBundle using id as
key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text. |
boolean |
removeBundle(String baseName)
Removes the ResourceBundle from the registry by its baseName. |
void |
setBundle(String baseName)
Sets the ResourceBundle to be used by its baseName. |
static String |
sub(String src,
String srch,
String repl)
Replace the first occurrence of a string srch in string
src by replacement repl. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static String defaultBundleName
public static final String[] NParams
protected Hashtable m_bundles
| Constructor Detail |
|---|
public Bundlizer()
| Method Detail |
|---|
public ResourceBundle getDefaultBundle()
public void setBundle(String baseName)
addBundle(String,Locale).
If no ResourceBundle matches the provided baseName, the default remains in place.
public boolean addBundle(String baseName,
Locale locale)
public boolean removeBundle(String baseName)
public String localize(String id)
id - the MessageId within the ListResourceBundle Messages.
public String localize(String id,
String arg1)
id - the MessageId within the ListResourceBundle Messages.arg1 - argument substituting %1 in the message string.
public String localize(String id,
String arg1,
String arg2)
id - the MessageId within the ListResourceBundle Messages.arg1 - argument substituting %1 in the message string.arg2 - argument substituting %2 in the message string.
public String localize(String id,
String arg1,
String arg2,
String arg3)
id - the MessageId within the ListResourceBundle Messages.arg1 - argument substituting %1 in the message string.arg2 - argument substituting %2 in the message string.arg3 - argument substituting %3 in the message string.
public String localize(String id,
String arg1,
String arg2,
String arg3,
String arg4)
id - the MessageId within the ListResourceBundle Messages.arg1 - argument substituting %1 in the message string.arg2 - argument substituting %2 in the message string.arg3 - argument substituting %3 in the message string.arg4 - argument substituting %4 in the message string.
public String processMessage(String id,
Object[] args)
id as key, then substitute arguments into
(%1, %2, %3, etc.) placeholders in text. This uses the default
ResourceBundle unless one has been set.
public String processMessage(String id,
Object[] args,
ResourceBundle bundle)
id as
key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.
public static final String sub(String src,
String srch,
String repl)
srch in string
src by replacement repl.
If the pattern isn't found, the string is returned unchanged.
src - the source string.srch - the string to search for.repl - the replacement string.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||