org.springframework.web.servlet.view
Class XmlViewResolver

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.XmlViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver

public class XmlViewResolver
extends AbstractCachingViewResolver

Implementation of ViewResolver that uses bean definitions in an XML file, specified by location (URL or relative path, according to the ApplicationContext implementation). The file will typically be located in the WEB-INF directory.

This ViewResolver does not support internationalization. Consider ResourceBundleViewResolver if you need to apply different view resources per locale.

Extends AbstractCachingViewResolver for decent performance.

Since:
18.06.2003
Author:
Juergen Hoeller
See Also:
ResourceLoader.getResource(java.lang.String), ResourceBundleViewResolver

Field Summary
static java.lang.String DEFAULT_LOCATION
          Default if no other location is supplied
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
XmlViewResolver()
           
 
Method Summary
protected  java.lang.String getCacheKey(java.lang.String viewName, java.util.Locale locale)
          This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.
protected  void initApplicationContext()
          Pre-initialize the factory from the XML file.
protected  BeanFactory initFactory()
          Initialize the BeanFactory from the XML file.
protected  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
 void setLocation(Resource location)
          Set the location of the XML file that defines the view beans.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
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, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCATION

public static final java.lang.String DEFAULT_LOCATION
Default if no other location is supplied

See Also:
Constant Field Values
Constructor Detail

XmlViewResolver

public XmlViewResolver()
Method Detail

setLocation

public void setLocation(Resource location)
Set the location of the XML file that defines the view beans.

The default is "/WEB-INF/views.xml".

Parameters:
location - the location of the XML file.

initApplicationContext

protected void initApplicationContext()
                               throws BeansException
Pre-initialize the factory from the XML file. Only effective if caching is enabled.

Overrides:
initApplicationContext in class ApplicationObjectSupport
Throws:
BeansException - if thrown by application context methods

getCacheKey

protected java.lang.String getCacheKey(java.lang.String viewName,
                                       java.util.Locale locale)
This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.

Overrides:
getCacheKey in class AbstractCachingViewResolver

loadView

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

initFactory

protected BeanFactory initFactory()
                           throws BeansException
Initialize the BeanFactory from the XML file. Synchronized because of access by parallel threads.

Throws:
BeansException - in case of initialization errors


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