FreeMarkerView and ResourceBundle/XmlViewResolver can be initialized with ServletContext only (e.g. for testing)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.view;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -28,6 +27,7 @@ import java.util.ResourceBundle;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -61,7 +61,8 @@ import org.springframework.web.servlet.View;
|
||||
* @see java.util.PropertyResourceBundle
|
||||
* @see UrlBasedViewResolver
|
||||
*/
|
||||
public class ResourceBundleViewResolver extends AbstractCachingViewResolver implements Ordered, DisposableBean {
|
||||
public class ResourceBundleViewResolver extends AbstractCachingViewResolver
|
||||
implements Ordered, InitializingBean, DisposableBean {
|
||||
|
||||
/** The default basename if no other basename is supplied. */
|
||||
public final static String DEFAULT_BASENAME = "views";
|
||||
@@ -175,9 +176,11 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver impl
|
||||
this.localesToInitialize = localesToInitialize;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initApplicationContext() throws BeansException {
|
||||
/**
|
||||
* Eagerly initialize Locales if necessary.
|
||||
* @see #setLocalesToInitialize
|
||||
*/
|
||||
public void afterPropertiesSet() throws BeansException {
|
||||
if (this.localesToInitialize != null) {
|
||||
for (Locale locale : this.localesToInitialize) {
|
||||
initFactory(locale);
|
||||
@@ -185,6 +188,7 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver impl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected View loadView(String viewName, Locale locale) throws Exception {
|
||||
BeanFactory factory = initFactory(locale);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.util.Locale;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.xml.ResourceEntityResolver;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
@@ -50,7 +51,8 @@ import org.springframework.web.servlet.View;
|
||||
* @see ResourceBundleViewResolver
|
||||
* @see UrlBasedViewResolver
|
||||
*/
|
||||
public class XmlViewResolver extends AbstractCachingViewResolver implements Ordered, DisposableBean {
|
||||
public class XmlViewResolver extends AbstractCachingViewResolver
|
||||
implements Ordered, InitializingBean, DisposableBean {
|
||||
|
||||
/** Default if no other location is supplied */
|
||||
public final static String DEFAULT_LOCATION = "/WEB-INF/views.xml";
|
||||
@@ -84,8 +86,7 @@ public class XmlViewResolver extends AbstractCachingViewResolver implements Orde
|
||||
* Pre-initialize the factory from the XML file.
|
||||
* Only effective if caching is enabled.
|
||||
*/
|
||||
@Override
|
||||
protected void initApplicationContext() throws BeansException {
|
||||
public void afterPropertiesSet() throws BeansException {
|
||||
if (isCache()) {
|
||||
initFactory();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -138,11 +138,9 @@ public class FreeMarkerView extends AbstractTemplateView {
|
||||
* @see freemarker.cache.TemplateCache#getTemplate
|
||||
*/
|
||||
@Override
|
||||
protected void initApplicationContext() throws BeansException {
|
||||
super.initApplicationContext();
|
||||
|
||||
protected void initServletContext(ServletContext servletContext) throws BeansException {
|
||||
if (getConfiguration() != null) {
|
||||
this.taglibFactory = new TaglibFactory(getServletContext());
|
||||
this.taglibFactory = new TaglibFactory(servletContext);
|
||||
}
|
||||
else {
|
||||
FreeMarkerConfig config = autodetectConfiguration();
|
||||
|
||||
Reference in New Issue
Block a user