Class WebappXMLResources

  extended by org.apache.commons.resources.impl.ResourcesBase
      extended by org.apache.commons.resources.impl.CollectionResourcesBase
          extended by org.apache.commons.resources.impl.WebappXMLResources
All Implemented Interfaces:
Serializable, Resources

public class WebappXMLResources
extends CollectionResourcesBase

Concrete implementation of Resources that wraps a family (one per Locale of XML documents that share a base context-relative path for servlet context resources, and have name suffixes reflecting the Locale for which the document's messages apply. Resources are looked up in a hierarchy of properties files in a manner identical to that performed by java.util.ResourceBundle.getBundle()..

The base resource path passed to our constructor must contain the context-relative base name of the properties file family. For example, if the base path is passed as http://localhost/foo/Bar, the resources for the en_US Locale would be stored under URL http://localhost/foo/Bar_en_US.xml, and the default resources would be stored in http://localhost/foo/Bar.xml.

See Also:
Serialized Form

Constructor Summary
WebappXMLResources(String name, String base, javax.servlet.ServletContext servletContext)
          Create a new Resources instance with the specified logical name and base resource URL.
Method Summary
protected  Map getLocaleMap(String baseUrl, Locale locale)
          Return a Map containing the name-value mappings for the specified base URL and requested Locale, if there are any.
Methods inherited from class org.apache.commons.resources.impl.CollectionResourcesBase
destroy, getDefaultLocale, getKeys, getLocaleList, getLocaleMap, getLocaleSuffix, getObject, setDefaultLocale
Methods inherited from class org.apache.commons.resources.impl.ResourcesBase
getBufferSize, getBytes, getInputStream, getName, getReader, getString, init, isReturnNull, setBufferSize, setReturnNull
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public WebappXMLResources(String name,
                          String base,
                          javax.servlet.ServletContext servletContext)

Create a new Resources instance with the specified logical name and base resource URL.

name - Logical name of the new instance
base - Base URL of the family of properties files that contain the resource keys and values
servletContext - the ServletContext instance to use for resolving resource references
Method Detail


protected Map getLocaleMap(String baseUrl,
                           Locale locale)

Return a Map containing the name-value mappings for the specified base URL and requested Locale, if there are any. If there are no defined mappings for the specified Locale, return an empty Map instead.

Concrete subclasses must override this method to perform the appropriate lookup. A typical implementation will construct an absolute URL based on the specified base URL and Locale, retrieve the specified resource file (if any), and parse it into a Map structure.

Caching of previously retrieved Maps (if any) should be performed by callers of this method. Therefore, this method should always attempt to retrieve the specified resource and load it appropriately.

Specified by:
getLocaleMap in class CollectionResourcesBase
baseUrl - Base URL of the resource files for this Resources instance
locale - Locale for which name-value mappings are requested
A name-value Map for the specified URL and locale.

Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.