com.opencms.flex.util
Class CmsMessages

java.lang.Object
  |
  +--com.opencms.flex.util.CmsMessages

public final class CmsMessages
extends Object

Reads localized resource Strings from a java.util.ResourceBundle and provides convenience methods to access the Strings from a template.

This class is to be used from JSP templates. Because of that, throwing of exceptions related to the access of the resource bundle are suppressed so that a template always execute. The class provides an isInitialized() method that can be checked to see if the instance was properly initialized.

Since:
5.0 beta 2
Version:
$Revision: 1.6 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com)

Constructor Summary
CmsMessages(String baseName, Locale locale)
          Constructor for the messages with an initialized java.util.Locale.
CmsMessages(String baseName, String language)
          Constructor for the messages with a language string.
CmsMessages(String baseName, String language, String country)
          Constructor for the messages with language and country code strings.
CmsMessages(String baseName, String language, String country, String variant)
          Constructor for the messages with language, country code and variant strings.
 
Method Summary
 String getDate(Date date)
          Returns a formatted date.
 String getDate(Date date, int style)
          Returns a formatted date.
 String getDate(long timestamp)
          Returns a formatted date.
 String getDateTime(Date date)
          Returns a formatted date with a time.
 String getDateTime(Date date, int style)
          Returns a formatted date with a time.
 String getDateTime(long timestamp)
          Returns a formatted date with a time.
 String getString(String keyName)
          Directly calls the getString(String) method of the wrapped ResourceBundle.
 boolean isInitialized()
          Checks if the bundle was properly initialized.
 String key(String keyName)
          Gets the localized resource string for a given message key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsMessages

public CmsMessages(String baseName,
                   Locale locale)
Constructor for the messages with an initialized java.util.Locale.

Parameters:
baseName - the base ResourceBundle name

CmsMessages

public CmsMessages(String baseName,
                   String language)
Constructor for the messages with a language string.

The language is a 2 letter language ISO code, e.g. "EN".

The Locale for the messages will be created like this:
new Locale(language, "", "").

Parameters:
baseName - the base ResourceBundle name
language - ISO language indentificator for the locale of the bundle

CmsMessages

public CmsMessages(String baseName,
                   String language,
                   String country)
Constructor for the messages with language and country code strings.

The language is a 2 letter language ISO code, e.g. "EN". The country is a 2 letter country ISO code, e.g. "us".

The Locale for the messages will be created like this:
new Locale(language, country, "").

Parameters:
baseName - the base ResourceBundle name
language - ISO language indentificator for the locale of the bundle
country - ISO 2 letter country code for the locale of the bundle

CmsMessages

public CmsMessages(String baseName,
                   String language,
                   String country,
                   String variant)
Constructor for the messages with language, country code and variant strings.

The language is a 2 letter language ISO code, e.g. "EN". The country is a 2 letter country ISO code, e.g. "us". The variant is a vendor or browser-specific code, e.g. "POSIX".

The Locale for the messages will be created like this:
new Locale(language, country, variant).

Parameters:
baseName - the base ResourceBundle name
language - language indentificator for the locale of the bundle
country - 2 letter country code for the locale of the bundle
variant - a vendor or browser-specific variant code
Method Detail

isInitialized

public boolean isInitialized()
Checks if the bundle was properly initialized.

Returns:
true if bundle was initialized, false otherwise

key

public String key(String keyName)
Gets the localized resource string for a given message key.

If the key was not found in the bundle, the return value is "??? " + keyName + " ???". This will also be returned if the bundle was not properly initialized first.

Parameters:
keyName - the key for the desired string
Returns:
the resource string for the given key

getString

public String getString(String keyName)
                 throws MissingResourceException
Directly calls the getString(String) method of the wrapped ResourceBundle.

If you use this this class on a template, you should consider using the key(String) method to get the value from the ResourceBundle because it handles the exception for you in a convenient way.

Parameters:
keyName - the key
Returns:
the resource string for the given key
Throws:
MissingResourceException - in case the key is not found of the bundle is not initialized

getDate

public String getDate(long timestamp)
Returns a formatted date.

Parameters:
timestamp - the date timestamp to format
Returns:
a formatted date

getDate

public String getDate(Date date)
Returns a formatted date.

Parameters:
date - the date to format
Returns:
a formatted date

getDate

public String getDate(Date date,
                      int style)
Returns a formatted date.

Parameters:
date - the date to format
style - the style to format the date with
Returns:
a formatted date
See Also:
DateFormat

getDateTime

public String getDateTime(long timestamp)
Returns a formatted date with a time.

Parameters:
timestamp - the date timestamp to format
Returns:
a formatted date with a time

getDateTime

public String getDateTime(Date date)
Returns a formatted date with a time.

Parameters:
date - the date to format
Returns:
a formatted date with a time

getDateTime

public String getDateTime(Date date,
                          int style)
Returns a formatted date with a time.

Parameters:
date - the date to format
style - the style to format the date with
Returns:
a formatted date with a time
See Also:
DateFormat