org.springframework.web.servlet.view
Class ResourceBundleViewResolver

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractCachingViewResolver
              extended byorg.springframework.web.servlet.view.ResourceBundleViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver

public class ResourceBundleViewResolver
extends AbstractCachingViewResolver

Implementation of ViewResolver that uses bean definitions in a ResourceBundle, specified by the bundle basename. The bundle is typically defined in a properties file, located in the classpath.

This ViewResolver supports internationalization, using the default support of java.util.PropertyResourceBundle.

Extends AbstractCachingViewResolver for decent performance.

Author:
Rod Johnson, Juergen Hoeller
See Also:
ResourceBundle.getBundle(java.lang.String), PropertyResourceBundle

Field Summary
static java.lang.String DEFAULT_BASENAME
          Default if no other basename is supplied
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
ResourceBundleViewResolver()
           
 
Method Summary
protected  BeanFactory initFactory(java.util.Locale locale)
          Initialize the BeanFactory from the ResourceBundle, for the given locale.
protected  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
 void setBasename(java.lang.String basename)
          Set the basename, as defined in the java.util.ResourceBundle documentation.
 void setDefaultParentView(java.lang.String defaultParentView)
          Set the default parent for views defined in the ResourceBundle.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
getCacheKey, isCache, resolveViewName, setCache
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, requiredContextClass
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BASENAME

public static final java.lang.String DEFAULT_BASENAME
Default if no other basename is supplied

See Also:
Constant Field Values
Constructor Detail

ResourceBundleViewResolver

public ResourceBundleViewResolver()
Method Detail

setBasename

public void setBasename(java.lang.String basename)
Set the basename, as defined in the java.util.ResourceBundle documentation. ResourceBundle supports different suffixes. For example, a base name of "views" might map to ResourceBundle files "views", "views_en_au" and "views_de".

The default is "views".

Parameters:
basename - the ResourceBundle base name
See Also:
ResourceBundle

setDefaultParentView

public void setDefaultParentView(java.lang.String defaultParentView)
Set the default parent for views defined in the ResourceBundle. This avoids repeated "yyy1.parent=xxx", "yyy2.parent=xxx" definitions in the bundle, especially if all defined views share the same parent. The parent will typically define the view class and common attributes. Concrete views might simply consist of an URL definition then: a la "yyy1.url=/my.jsp", "yyy2.url=/your.jsp".

Parameters:
defaultParentView - the default parent view

loadView

protected View loadView(java.lang.String viewName,
                        java.util.Locale locale)
                 throws java.util.MissingResourceException,
                        BeansException
Description copied from class: AbstractCachingViewResolver
Subclasses must implement this method. There need be no concern for efficiency, as this class will cache views. Not all subclasses may support internationalization: A subclass that doesn't can simply ignore the locale parameter.

Specified by:
loadView in class AbstractCachingViewResolver
Parameters:
viewName - the name of the view to retrieve
locale - the Locale to retrieve the view for
Returns:
the View instance
Throws:
java.util.MissingResourceException
BeansException

initFactory

protected BeanFactory initFactory(java.util.Locale locale)
                           throws java.util.MissingResourceException,
                                  BeansException
Initialize the BeanFactory from the ResourceBundle, for the given locale. Synchronized because of access by parallel threads.

Throws:
java.util.MissingResourceException
BeansException


Copyright (C) 2003-2004 The Spring Framework Project.