org.apache.shale.util
Class Messages

java.lang.Object
  extended by org.apache.shale.util.Messages

public class Messages
extends Object

Utility wrapper around resource bundles that provides locale-specific message string lookups, as well as parameter replacement services.

If desired, this class can be used to define a managed bean wrapping a specified resource bundle, with a declaration like this in a faces-config.xml configuration file:

    <managed-bean>
      <managed-bean-name>messages</managed-bean-name>
      <managed-bean-class>
        org.apache.shale.util.Messages
      </managed-bean-class>
      <managed-bean-scope>application</managed-bean-scope>
      <managed-property>
        <property-name>name</property-name>
        <value>com.mycompany.mypackage.Bundle</value>
      </managed-property>
    </managed-bean>
 
$Id: Messages.java 481403 2006-12-01 21:27:54Z rahul $


Constructor Summary
Messages()
          Construct an initialized Messages wrapper.
Messages(String name)
          Construct a new Messages wrapper around the specified resource bundle name, loaded by the default class loader.
Messages(String name, ClassLoader cl)
          Construct a new Messages wrapper around the specified resource bundle name, loaded by the specified class loader.
 
Method Summary
 ClassLoader getClassLoader()
          Return the ClassLoader from which to load the specified resource bundle, or null for the thread context class loader.
 String getMessage(String key)
          Retrieve the specified message string for the default locale.
 String getMessage(String key, Locale locale)
          Retrieve the specified message string for the specified locale.
 String getMessage(String key, Locale locale, Object[] params)
          Retrieve the specified message string for the specified locale, and perform parameter substitution with the specified parameters.
 String getMessage(String key, Object[] params)
          Retrieve the specified message string for the default locale, and perform parameter substitution with the specified parameters.
 String getName()
          Return the name of the resource bundle to be retrieved.
 void setClassLoader(ClassLoader cl)
          Set the ClassLoader from which to load the specified resource bundle.
 void setName(String name)
          Set the name of the resource bunde to be retrieved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Messages

public Messages()

Construct an initialized Messages wrapper. At least the name property must be initialized before the message retrieval public methods may be successfully utilized.


Messages

public Messages(String name)

Construct a new Messages wrapper around the specified resource bundle name, loaded by the default class loader.

Parameters:
name - Name of the requested ResourceBundle

Messages

public Messages(String name,
                ClassLoader cl)

Construct a new Messages wrapper around the specified resource bundle name, loaded by the specified class loader.

Parameters:
name - Name of the requested ResourceBundle
cl - ClassLoader to use for loading this resource bundle, or null for the default (which selects the thread context class loader)
Method Detail

getClassLoader

public ClassLoader getClassLoader()

Return the ClassLoader from which to load the specified resource bundle, or null for the thread context class loader.


setClassLoader

public void setClassLoader(ClassLoader cl)

Set the ClassLoader from which to load the specified resource bundle.

Parameters:
cl - The new class loader, or null for the thread context class loader

getName

public String getName()

Return the name of the resource bundle to be retrieved.


setName

public void setName(String name)

Set the name of the resource bunde to be retrieved.

Parameters:
name - New name of the resource bundle to be retrieved

getMessage

public String getMessage(String key)

Retrieve the specified message string for the default locale. If no message can be found, return null.

Parameters:
key - Key to the message string to look up

getMessage

public String getMessage(String key,
                         Object[] params)

Retrieve the specified message string for the default locale, and perform parameter substitution with the specified parameters. If no message can be found, return null.

Parameters:
key - Key to the message string to look up
params - Parameter replacement values

getMessage

public String getMessage(String key,
                         Locale locale)

Retrieve the specified message string for the specified locale. If no message can be found, return null.

Parameters:
key - Key to the message string to look up
locale - Locale used to localize this message

getMessage

public String getMessage(String key,
                         Locale locale,
                         Object[] params)

Retrieve the specified message string for the specified locale, and perform parameter substitution with the specified parameters. If no message can be found, return null.

Parameters:
key - Key to the message string to look up
locale - Locale used to localize this message
params - Parameter replacement values


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.