|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.view.AbstractCachingViewResolver org.springframework.web.servlet.view.ResourceBundleViewResolver
public class ResourceBundleViewResolver
ViewResolver
implementation
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 PropertyResourceBundle
.
For example, the basename "views" will be resolved as class path resources
"views_de_AT.properties", "views_de.properties", "views.properties" -
for a given Locale "de_AT".
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
.
ResourceBundle.getBundle(java.lang.String)
,
PropertyResourceBundle
,
UrlBasedViewResolver
Field Summary | |
---|---|
static String |
DEFAULT_BASENAME
The default basename if no other basename is supplied. |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Fields inherited from interface org.springframework.core.Ordered |
---|
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
Constructor Summary | |
---|---|
ResourceBundleViewResolver()
|
Method Summary | |
---|---|
void |
destroy()
Close the bundle View factories on context shutdown. |
protected ResourceBundle |
getBundle(String basename,
Locale locale)
Obtain the resource bundle for the given basename and Locale . |
protected ClassLoader |
getBundleClassLoader()
Return the ClassLoader to load resource bundles with. |
int |
getOrder()
Return the order value of this object, with a higher value meaning greater in terms of sorting. |
protected void |
initApplicationContext()
Subclasses can override this for custom initialization behavior. |
protected BeanFactory |
initFactory(Locale locale)
Initialize the View BeanFactory from the ResourceBundle ,
for the given locale . |
protected View |
loadView(String viewName,
Locale locale)
Subclasses must implement this method, building a View object for the specified view. |
void |
setBasename(String basename)
Set the basename, as defined in the ResourceBundle
documentation. |
void |
setBasenames(String[] basenames)
Set multiple ResourceBundle basenames. |
void |
setBundleClassLoader(ClassLoader classLoader)
Set the ClassLoader to load resource bundles with. |
void |
setDefaultParentView(String defaultParentView)
Set the default parent for views defined in the ResourceBundle . |
void |
setLocalesToInitialize(Locale[] localesToInitialize)
Specify Locales to initialize eagerly, rather than lazily when actually accessed. |
void |
setOrder(int order)
|
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver |
---|
clearCache, createView, getCacheKey, isCache, removeFromCache, resolveViewName, setCache |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_BASENAME
Constructor Detail |
---|
public ResourceBundleViewResolver()
Method Detail |
---|
public void setOrder(int order)
public int getOrder()
Ordered
Normally starting with 0 or 1, with Ordered.LOWEST_PRECEDENCE
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).
Note that order values below 0 are reserved for framework purposes. Application-specified values should always be 0 or greater, with only framework components (internal or third-party) supposed to use lower values.
Ordered.LOWEST_PRECEDENCE
public void setBasename(String basename)
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".
public void setBasenames(String[] basenames)
ResourceBundle
basenames.
setBasename(java.lang.String)
public void setBundleClassLoader(ClassLoader classLoader)
ClassLoader
to load resource bundles with.
Default is the thread context ClassLoader
.
protected ClassLoader getBundleClassLoader()
ClassLoader
to load resource bundles with.
Default is the specified bundle ClassLoader
,
usually the thread context ClassLoader
.
public void setDefaultParentView(String defaultParentView)
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.
public void setLocalesToInitialize(Locale[] localesToInitialize)
Allows for pre-initialization of common Locales, eagerly checking the view configuration for those Locales.
protected void initApplicationContext() throws BeansException
ApplicationObjectSupport
setApplicationContext
after setting the context instance.
Note: Does not get called on reinitialization of the context but rather just on first initialization of this object's context reference.
initApplicationContext
in class ApplicationObjectSupport
ApplicationContextException
- in case of initialization errors
BeansException
- if thrown by ApplicationContext methodsApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected View loadView(String viewName, Locale locale) throws Exception
AbstractCachingViewResolver
Subclasses are not forced to support internationalization: A subclass that does not may simply ignore the locale parameter.
loadView
in class AbstractCachingViewResolver
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for
null
if not found
(optional, to allow for ViewResolver chaining)
Exception
- if the view couldn't be resolvedAbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)
protected BeanFactory initFactory(Locale locale) throws BeansException
BeanFactory
from the ResourceBundle
,
for the given locale
.
Synchronized because of access by parallel threads.
locale
- the target Locale
BeansException
- in case of initialization errorsprotected ResourceBundle getBundle(String basename, Locale locale) throws MissingResourceException
Locale
.
basename
- the basename to look forlocale
- the Locale
to look for
ResourceBundle
MissingResourceException
- if no matching bundle could be foundResourceBundle.getBundle(String, java.util.Locale, ClassLoader)
public void destroy() throws BeansException
destroy
in interface DisposableBean
BeansException
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |