org.apache.muse.util.messages
Class Messages

java.lang.Object
  extended by org.apache.muse.util.messages.Messages

public class Messages
extends Object

Messages is a wrapper for a java.util.ResourceBundle that provides a search-and-replace mechanism for filling in message context. Users can create properties files with messages that include XXX placeholders and then fill in the values of these placeholders at runtime. This allows for as much message externalization as possible while still making it easy to provide runtime-specific information.

Author:
Dan Jemiolo (danj)
See Also:
MessagesFactory, ResourceBundle

Constructor Summary
Messages(String bundleName)
          Creates a new message collection using the given resource bundle.
Messages(String bundleName, ClassLoader loader)
          Creates a new message collection using the given resource bundle and classloader.
 
Method Summary
 String get(String name)
           
 String get(String name, boolean includeID)
           
 String get(String name, Object[] filler)
          Retrieves the value specified and replaces any placeholders (XXX values) with the values in the given array.
 String get(String name, Object[] filler, boolean includeID)
          Retrieves the value specified and replaces any placeholders (XXX values) with the values in the given array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Messages

public Messages(String bundleName)
Creates a new message collection using the given resource bundle. The bundle (properties file) may contain XXX placeholders that indicate where values will be substituted at runtime.

Parameters:
bundleName - The qualified name of the resource bundle to parse.

Messages

public Messages(String bundleName,
                ClassLoader loader)
Creates a new message collection using the given resource bundle and classloader. The bundle (properties file) may contain XXX placeholders that indicate where values will be substituted at runtime. This constructor is used by dependent bundles so that their resources can be found by the resource bundle.

Parameters:
bundleName - The qualified name of the resource bundle to parse.
loader - The class loader that has the bundle file in its classpath.
Method Detail

get

public String get(String name)
Parameters:
name - The name of the property/message to lookup.
Returns:
The message value, with a prefix that identifies the message name.

get

public String get(String name,
                  boolean includeID)
Parameters:
name - The name of the property/message to lookup.
includeID - True if you want the message to include [ID = "MessageName"] for debugging purposes.
Returns:
The message value, with a prefix that identifies the message name.

get

public String get(String name,
                  Object[] filler)
Retrieves the value specified and replaces any placeholders (XXX values) with the values in the given array. The filler values are serialized using Object.toString().

If the number of filler values is less than the number of placeholders, the placeholders will be left in the string. If the number of filler values is greater, the leftover values will simply not be used.

Parameters:
name - The name of the property/message to lookup.
filler - The values to substitute for the placeholders (if any).
Returns:
The message value, with the given filler values substituted for the placeholders and a prefix that identifies the message name.

get

public String get(String name,
                  Object[] filler,
                  boolean includeID)
Retrieves the value specified and replaces any placeholders (XXX values) with the values in the given array. The filler values are serialized using Object.toString().

If the number of filler values is less than the number of placeholders, the placeholders will be left in the string. If the number of filler values is greater, the leftover values will simply not be used.

Parameters:
name - The name of the property/message to lookup.
filler - The values to substitute for the placeholders (if any).
includeID - True if you want the message to include [ID = "MessageName"] for debugging purposes.
Returns:
The message value, with the given filler values substituted for the placeholders and a prefix that identifies the message name.


Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.