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, DisposableBean, Ordered, ViewResolver

public class ResourceBundleViewResolver
extends AbstractCachingViewResolver
implements Ordered, DisposableBean

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 class path. The default bundle basename is "views".

This ViewResolver supports localized view definitions, using the default support of java.util.PropertyResourceBundle.

Note: This ViewResolver implements the Ordered interface to allow for flexible participation in ViewResolver chaining. For example, some special views could be defined via this ViewResolver (giving it 0 as "order" value), while all remaining views could be resolved by a UrlBasedViewResolver.

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

Field Summary
static 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
 void destroy()
          Invoked by a BeanFactory on destruction of a singleton.
 int getOrder()
          Return the order value of this object, higher value meaning greater in terms of sorting.
protected  BeanFactory initFactory(Locale locale)
          Initialize the BeanFactory from the ResourceBundle, for the given locale.
protected  View loadView(String viewName, Locale locale)
          Subclasses must implement this method.
 void setBasename(String basename)
          Set the basename, as defined in the java.util.ResourceBundle documentation.
 void setBasenames(String[] basenames)
          Set multiple ResourceBundle basenames.
 void setDefaultParentView(String defaultParentView)
          Set the default parent for views defined in the ResourceBundle.
 void setOrder(int order)
           
 
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
createView, getCacheKey, isCache, removeFromCache, resolveViewName, setCache
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, 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 String DEFAULT_BASENAME
Default if no other basename is supplied

See Also:
Constant Field Values
Constructor Detail

ResourceBundleViewResolver

public ResourceBundleViewResolver()
Method Detail

setOrder

public void setOrder(int order)

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, higher value meaning greater in terms of sorting. Normally starting with 0 or 1, Integer.MAX_VALUE indicating greatest. Same order values will result in arbitrary positions for the affected objects.

Higher value can be interpreted as lower priority, consequently the first object has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Specified by:
getOrder in interface Ordered
Returns:
the order value

setBasename

public void setBasename(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 basename
See Also:
setBasenames(java.lang.String[]), ResourceBundle

setBasenames

public void setBasenames(String[] basenames)
Set multiple ResourceBundle basenames.

Parameters:
basenames - multiple ResourceBundle basenames
See Also:
setBasename(java.lang.String)

setDefaultParentView

public void setDefaultParentView(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".

View definitions that define their own parent or carry their own class can still override this. Strictly speaking, the rule that a default parent setting does not apply to a bean definition that carries a class is there for backwards compatiblity reasons. It still matches the typical use case.

Parameters:
defaultParentView - the default parent view

loadView

protected View loadView(String viewName,
                        Locale locale)
                 throws 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.

This method is not supposed to fully initialize the view (for example, ApplicationContextAware methods haven't been called yet). Clients should only be using resolveViewName, which does fully initialize the view objects found.

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, or null if not found (optional, to allow for ViewResolver chaining)
Throws:
MissingResourceException
BeansException
See Also:
AbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)

initFactory

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

Throws:
MissingResourceException
BeansException

destroy

public void destroy()
             throws BeansException
Description copied from interface: DisposableBean
Invoked by a BeanFactory on destruction of a singleton.

Specified by:
destroy in interface DisposableBean
Throws:
BeansException


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