The Spring Framework

## org.springframework.web.servlet.view
Class XmlViewResolver

    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.XmlViewResolver

All Implemented Interfaces:
  DisposableBean, ApplicationContextAware, Ordered, ServletContextAware, ViewResolver

    public class XmlViewResolver

extends AbstractCachingViewResolver
implements Ordered, DisposableBean

Implementation of ViewResolver that uses bean definitions in an XML file, specified by resource location. The file will typically be located in the WEB-INF directory; default is "/WEB-INF/views.xml".

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

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.

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

Field Summary
`static String` `DEFAULT_LOCATION` Default if no other location 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
`XmlViewResolver()`

Method Summary
`void` `destroy()` Close the view bean factory on context shutdown.
`protected Object` `getCacheKey(String viewName, Locale locale)` This implementation returns just the view name, as XmlViewResolver doesn't support localized resolution.
`int` `getOrder()` Return the order value of this object, with a higher value meaning greater in terms of sorting.
`protected void` `initApplicationContext()` Pre-initialize the factory from the XML file.
`protected BeanFactory` `initFactory()` Initialize the view bean factory from the XML file.
`protected View` `loadView(String viewName, Locale locale)` Subclasses must implement this method, building a View object for the specified view.
`void` `setLocation(Resource location)` Set the location of the XML file that defines the view beans.
`void` `setOrder(int order)`

Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
`clearCache, createView, isCache, removeFromCache, resolveViewName, setCache`

Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
`getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, 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

### DEFAULT_LOCATION

    public static final String DEFAULT_LOCATION

  Default if no other location is supplied

  See Also:
    Constant Field Values

Constructor Detail

### XmlViewResolver

    public XmlViewResolver()

Method Detail

### setOrder

    public void setOrder(int order)

### getOrder

    public int getOrder()

  Description copied from interface: `Ordered`
  Return the order value of this object, with a higher value meaning greater in terms of sorting.

  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.

  Specified by:
    `getOrder` in interface `Ordered`
  Returns:
    the order value
  See Also:
    `Ordered.LOWEST_PRECEDENCE`

### 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:
    `ApplicationContextException` - in case of initialization errors
    `BeansException` - if thrown by ApplicationContext methods
  See Also:
    `ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)`

### getCacheKey

    protected Object getCacheKey(String viewName,
                                 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(String viewName,
                            Locale locale)
                     throws BeansException

  Description copied from class: `AbstractCachingViewResolver`
  Subclasses must implement this method, building a View object for the specified view. The returned View objects will be cached by this ViewResolver base class.

  Subclasses are not forced to support internationalization: A subclass that does not may 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, or `null` if not found (optional, to allow for ViewResolver chaining)
  Throws:
    `BeansException`
  See Also:
    `AbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)`

### initFactory

    protected BeanFactory initFactory()
                               throws BeansException

  Initialize the view bean factory from the XML file. Synchronized because of access by parallel threads.

  Throws:
    `BeansException` - in case of initialization errors

### destroy

    public void destroy()
                 throws BeansException

  Close the view bean factory on context shutdown.

  Specified by:
    `destroy` in interface `DisposableBean`
  Throws:
    `BeansException`

The Spring Framework

Copyright © 2002-2008 The Spring Framework.