BEA Systems, Inc.

com.beasys.commerce.i18n.jsp
Class JspMessageBundle

java.lang.Object
  |
  +--com.beasys.commerce.i18n.MessageBundle
        |
        +--com.beasys.commerce.i18n.jsp.JspMessageBundle

public class JspMessageBundle
extends MessageBundle

Class to help with retrieving locale-specific messages from within a JSP.

It is rarely necessary to use this class directly, as two JSP tags are provided that page developers will probably find more convenient. See the documentation for <i18n:localize> and <i18n:getMessage>.

Given a JSP's and language, country and variant settings, JspMessageBundle will follow the search order from ResourceBundle to look for a properties file containing messages used by the JSP, the only difference being that it will search for the file as a resource relative to the JSP's document root. This means you'd specify the baseBundleName using "/" instead of ".". For example, "/jspPages/appPages/mainPageText" instead of "jspPages.appPages.mainPageText". Also, the properties files serving as resource bundles are relative to the documents they support or at least on the document root, not on the CLASSPATH as with traditional resource bundles. If no baseBundleName is provided, it will default to the same name as the calling page. These differences from traditional resource bundles were done for convenience in JSP programming.

For example, for a JSP /pages/something.jsp, language code "en", country code "US", JspMessageBundle will look for the properties file in the following order:

where repositoryDir is a "repository" directory - a place where common files exist - and "default locale" is "_en_US". If none of these are found, a MissingResourceException will be thrown.

A class-wide cache is kept of all bundle names, languages, countries, variant combinations so that the property file search will not be repeated each time a request is made.

See Also:
LocalizeTag, GetMessageTag

Inner Class Summary
protected static class JspMessageBundle.MessageBundleKey
          Protected internal class used as a key in the MessageBundle cache
 
Field Summary
protected  java.lang.String baseBundleName
           
protected  java.util.Locale locale
           
 
Fields inherited from class com.beasys.commerce.i18n.MessageBundle
debug, resourceBundle
 
Constructor Summary
JspMessageBundle()
           
 
Method Summary
protected static void addToCache(java.lang.String uri, java.lang.String baseBundleName, java.lang.String language, java.lang.String country, java.lang.String variant, MessageBundle bundle)
          Add a MessageBundle to the cache, keyed by its URI, language, country, and variant.
protected static JspMessageBundle findInCache(java.lang.String uri, java.lang.String baseBundleName, java.lang.String language, java.lang.String country, java.lang.String variant)
          Look for a message bundle for this URI, language, country, variant in the cache.
static MessageBundle getBundle(javax.servlet.jsp.PageContext pageContext, java.lang.String baseBundleName, java.lang.String language, java.lang.String country, java.lang.String variant)
          Return a MessageBundle for this base bundle name, request, language, country, and variant.
 java.util.Locale getLocale()
          Returns the Locale for this bundle.
protected static java.lang.String getRealURI(javax.servlet.jsp.PageContext pageContext)
          Returns the URI for a page correctly, regardless of whether it's being dynamically included in a parent page.
 
Methods inherited from class com.beasys.commerce.i18n.MessageBundle
debug, error, getBundle, getBundle, getBundle, getInstance, getKeys, getMessage, getObject, getString, getStringArray, info, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseBundleName

protected java.lang.String baseBundleName

locale

protected java.util.Locale locale
Constructor Detail

JspMessageBundle

public JspMessageBundle()
Method Detail

getBundle

public static MessageBundle getBundle(javax.servlet.jsp.PageContext pageContext,
                                      java.lang.String baseBundleName,
                                      java.lang.String language,
                                      java.lang.String country,
                                      java.lang.String variant)
                               throws java.util.MissingResourceException
Return a MessageBundle for this base bundle name, request, language, country, and variant.
Parameters:
pageContext - the JSP PageContext
baseBundleName - the base name of the message bundle - defaults to the servlet name in the page context's URI
language - the desired language of the message bundle
country - the desired country of the message bundle
variant - the desired variant of the message bundle

findInCache

protected static JspMessageBundle findInCache(java.lang.String uri,
                                              java.lang.String baseBundleName,
                                              java.lang.String language,
                                              java.lang.String country,
                                              java.lang.String variant)
Look for a message bundle for this URI, language, country, variant in the cache.

addToCache

protected static void addToCache(java.lang.String uri,
                                 java.lang.String baseBundleName,
                                 java.lang.String language,
                                 java.lang.String country,
                                 java.lang.String variant,
                                 MessageBundle bundle)
Add a MessageBundle to the cache, keyed by its URI, language, country, and variant.

getLocale

public java.util.Locale getLocale()
Returns the Locale for this bundle.
Overrides:
getLocale in class MessageBundle
Returns:
the Locale for this bundle

getRealURI

protected static java.lang.String getRealURI(javax.servlet.jsp.PageContext pageContext)
Returns the URI for a page correctly, regardless of whether it's being dynamically included in a parent page.

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved