org.opencms.i18n
Class CmsMultiMessages

java.lang.Object
  extended byorg.opencms.i18n.CmsMessages
      extended byorg.opencms.i18n.CmsMultiMessages
Direct Known Subclasses:
CmsWorkplaceMessages

public class CmsMultiMessages
extends CmsMessages

Provides access to the localized messages for several resource bundles simultaneously.

Messages are cached for faster lookup. If a localized key is contained in more then one resource bundle, it will be used only from the resource bundle where it was first found in. The resource bundle order is undefined. It is therefore recommended to ensure the uniqueness of all module keys by placing a special prefix in front of all keys of a resource bundle.

Since:
6.0.0
Version:
$Revision: 1.10 $
Author:
Alexnader Kandzior, Michael Moossen

Field Summary
static String NULL_STRING
          Null String value for caching of null message results.
 
Fields inherited from class org.opencms.i18n.CmsMessages
KEY_SHORT_SUFFIX, m_baseName, m_locale, m_resourceBundle, UNKNOWN_KEY_EXTENSION
 
Constructor Summary
CmsMultiMessages(CmsMessages[] messages)
          Constructor for creating a new messages object initialized with the provided array of bundles.
CmsMultiMessages(CmsMessages message1, CmsMessages message2)
          Constructor for creating a new messages object initialized with the provided bundles.
CmsMultiMessages(List messages)
          Constructor for creating a new messages object initialized with the provided list of bundles.
 
Method Summary
 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, boolean allowNull)
          Returns the localized resource string for a given message key.
 
Methods inherited from class org.opencms.i18n.CmsMessages
formatUnknownKey, getBundle, getDate, getDate, getDate, getDateTime, getDateTime, getDateTime, getLocale, isUnknownKey, key, key, key, keyWithParams, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_STRING

public static final String NULL_STRING
Null String value for caching of null message results.

See Also:
Constant Field Values
Constructor Detail

CmsMultiMessages

public CmsMultiMessages(CmsMessages message1,
                        CmsMessages message2)
Constructor for creating a new messages object initialized with the provided bundles.

Parameters:
message1 - a message
message2 - a message

CmsMultiMessages

public CmsMultiMessages(CmsMessages[] messages)
Constructor for creating a new messages object initialized with the provided array of bundles.

Parameters:
messages - array of CmsMessages, should not be null or empty

CmsMultiMessages

public CmsMultiMessages(List messages)
                 throws CmsIllegalArgumentException
Constructor for creating a new messages object initialized with the provided list of bundles.

Parameters:
messages - list of CmsMessages, should not be null or empty
Throws:
CmsIllegalArgumentException - if the given List is null or empty
Method Detail

getString

public String getString(String keyName)
Description copied from class: CmsMessages
Directly calls the getString(String) method of the wrapped ResourceBundle.

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

Overrides:
getString in class CmsMessages
Parameters:
keyName - the key
Returns:
the resource string for the given key
See Also:
CmsMessages.getString(java.lang.String)

isInitialized

public boolean isInitialized()
Description copied from class: CmsMessages
Checks if the bundle was properly initialized.

Overrides:
isInitialized in class CmsMessages
Returns:
true if bundle was initialized, false otherwise
See Also:
CmsMessages.isInitialized()

key

public String key(String keyName,
                  boolean allowNull)
Description copied from class: CmsMessages
Returns the localized resource string for a given message key.

If the key was not found in the bundle, the return value depends on the setting of the allowNull parameter. If set to false, the return value is always a String in the format "??? " + keyName + " ???". If set to true, null is returned if the key is not found. This will also be returned if the bundle was not properly initialized first.

Overrides:
key in class CmsMessages
Parameters:
keyName - the key for the desired string
allowNull - if true, 'null' is an allowed return value
Returns:
the resource string for the given key
See Also:
CmsMessages.key(java.lang.String, boolean)