diff --git a/spring-context-support/src/main/java/org/springframework/mail/MailPreparationException.java b/spring-context-support/src/main/java/org/springframework/mail/MailPreparationException.java index b1e99b55917..d448f47f84a 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/MailPreparationException.java +++ b/spring-context-support/src/main/java/org/springframework/mail/MailPreparationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 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. @@ -18,11 +18,10 @@ package org.springframework.mail; /** * Exception to be thrown by user code if a mail cannot be prepared properly, - * for example when a Velocity template cannot be rendered for the mail text. + * for example when a FreeMarker template cannot be rendered for the mail text. * * @author Juergen Hoeller * @since 1.1 - * @see org.springframework.ui.velocity.VelocityEngineUtils#mergeTemplateIntoString * @see org.springframework.ui.freemarker.FreeMarkerTemplateUtils#processTemplateIntoString */ @SuppressWarnings("serial") diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessagePreparator.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessagePreparator.java index 9b0f49fc34d..2740bc19c71 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessagePreparator.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessagePreparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 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. @@ -46,7 +46,7 @@ public interface MimeMessagePreparator { * @throws java.io.IOException passing any exceptions thrown by MimeMessage methods * through for automatic conversion to the MailException hierarchy * @throws Exception if mail preparation failed, for example when a - * Velocity template cannot be rendered for the mail text + * FreeMarker template cannot be rendered for the mail text */ void prepare(MimeMessage mimeMessage) throws Exception; diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/SpringResourceLoader.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/SpringResourceLoader.java deleted file mode 100644 index f03a8e61900..00000000000 --- a/spring-context-support/src/main/java/org/springframework/ui/velocity/SpringResourceLoader.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ui.velocity; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -import org.apache.commons.collections.ExtendedProperties; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.apache.velocity.runtime.resource.Resource; -import org.apache.velocity.runtime.resource.loader.ResourceLoader; - -import org.springframework.util.StringUtils; - -/** - * Velocity ResourceLoader adapter that loads via a Spring ResourceLoader. - * Used by VelocityEngineFactory for any resource loader path that cannot - * be resolved to a {@code java.io.File}. - * - *
Note that this loader does not allow for modification detection: - * Use Velocity's default FileResourceLoader for {@code java.io.File} - * resources. - * - *
Expects "spring.resource.loader" and "spring.resource.loader.path" - * application attributes in the Velocity runtime: the former of type - * {@code org.springframework.core.io.ResourceLoader}, the latter a String. - * - * @author Juergen Hoeller - * @since 14.03.2004 - * @see VelocityEngineFactory#setResourceLoaderPath - * @see org.springframework.core.io.ResourceLoader - * @see org.apache.velocity.runtime.resource.loader.FileResourceLoader - */ -public class SpringResourceLoader extends ResourceLoader { - - public static final String NAME = "spring"; - - public static final String SPRING_RESOURCE_LOADER_CLASS = "spring.resource.loader.class"; - - public static final String SPRING_RESOURCE_LOADER_CACHE = "spring.resource.loader.cache"; - - public static final String SPRING_RESOURCE_LOADER = "spring.resource.loader"; - - public static final String SPRING_RESOURCE_LOADER_PATH = "spring.resource.loader.path"; - - - protected final Log logger = LogFactory.getLog(getClass()); - - private org.springframework.core.io.ResourceLoader resourceLoader; - - private String[] resourceLoaderPaths; - - - @Override - public void init(ExtendedProperties configuration) { - this.resourceLoader = (org.springframework.core.io.ResourceLoader) - this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER); - String resourceLoaderPath = (String) this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_PATH); - if (this.resourceLoader == null) { - throw new IllegalArgumentException( - "'resourceLoader' application attribute must be present for SpringResourceLoader"); - } - if (resourceLoaderPath == null) { - throw new IllegalArgumentException( - "'resourceLoaderPath' application attribute must be present for SpringResourceLoader"); - } - this.resourceLoaderPaths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath); - for (int i = 0; i < this.resourceLoaderPaths.length; i++) { - String path = this.resourceLoaderPaths[i]; - if (!path.endsWith("/")) { - this.resourceLoaderPaths[i] = path + "/"; - } - } - if (logger.isInfoEnabled()) { - logger.info("SpringResourceLoader for Velocity: using resource loader [" + this.resourceLoader + - "] and resource loader paths " + Arrays.asList(this.resourceLoaderPaths)); - } - } - - @Override - public InputStream getResourceStream(String source) throws ResourceNotFoundException { - if (logger.isDebugEnabled()) { - logger.debug("Looking for Velocity resource with name [" + source + "]"); - } - for (String resourceLoaderPath : this.resourceLoaderPaths) { - org.springframework.core.io.Resource resource = - this.resourceLoader.getResource(resourceLoaderPath + source); - try { - return resource.getInputStream(); - } - catch (IOException ex) { - if (logger.isDebugEnabled()) { - logger.debug("Could not find Velocity resource: " + resource); - } - } - } - throw new ResourceNotFoundException( - "Could not find resource [" + source + "] in Spring resource loader path"); - } - - @Override - public boolean isSourceModified(Resource resource) { - return false; - } - - @Override - public long getLastModified(Resource resource) { - return 0; - } - -} diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java deleted file mode 100644 index 399208e8312..00000000000 --- a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright 2002-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ui.velocity; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.exception.VelocityException; -import org.apache.velocity.runtime.RuntimeConstants; -import org.apache.velocity.runtime.log.CommonsLogLogChute; - -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.PropertiesLoaderUtils; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; - -/** - * Factory that configures a VelocityEngine. Can be used standalone, - * but typically you will either use {@link VelocityEngineFactoryBean} - * for preparing a VelocityEngine as bean reference, or - * {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer} - * for web views. - * - *
The optional "configLocation" property sets the location of the Velocity - * properties file, within the current application. Velocity properties can be - * overridden via "velocityProperties", or even completely specified locally, - * avoiding the need for an external properties file. - * - *
The "resourceLoaderPath" property can be used to specify the Velocity - * resource loader path via Spring's Resource abstraction, possibly relative - * to the Spring application context. - * - *
If "overrideLogging" is true (the default), the VelocityEngine will be - * configured to log via Commons Logging, that is, using - * {@link CommonsLogLogChute} as log system. - * - *
The simplest way to use this class is to specify a
- * {@link #setResourceLoaderPath(String) "resourceLoaderPath"}; the
- * VelocityEngine typically then does not need any further configuration.
- *
- * @author Juergen Hoeller
- * @see #setConfigLocation
- * @see #setVelocityProperties
- * @see #setResourceLoaderPath
- * @see #setOverrideLogging
- * @see #createVelocityEngine
- * @see VelocityEngineFactoryBean
- * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
- * @see org.apache.velocity.app.VelocityEngine
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityEngineFactory {
-
- protected final Log logger = LogFactory.getLog(getClass());
-
- private Resource configLocation;
-
- private final Map Note that the Velocity resource loader path also be set to any
- * Spring resource location via the "resourceLoaderPath" property.
- * Setting it here is just necessary when using a non-file-based
- * resource loader.
- * @see #setVelocityPropertiesMap
- * @see #setConfigLocation
- * @see #setResourceLoaderPath
- */
- public void setVelocityProperties(Properties velocityProperties) {
- CollectionUtils.mergePropertiesIntoMap(velocityProperties, this.velocityProperties);
- }
-
- /**
- * Set Velocity properties as Map, to allow for non-String values
- * like "ds.resource.loader.instance".
- * @see #setVelocityProperties
- */
- public void setVelocityPropertiesMap(Map When populated via a String, standard URLs like "file:" and "classpath:"
- * pseudo URLs are supported, as understood by ResourceLoader. Allows for
- * relative paths when running in an ApplicationContext.
- * Will define a path for the default Velocity resource loader with the name
- * "file". If the specified resource cannot be resolved to a {@code java.io.File},
- * a generic SpringResourceLoader will be used under the name "spring", without
- * modification detection.
- * Note that resource caching will be enabled in any case. With the file
- * resource loader, the last-modified timestamp will be checked on access to
- * detect changes. With SpringResourceLoader, the resource will be cached
- * forever (for example for class path resources).
- * To specify a modification check interval for files, use Velocity's
- * standard "file.resource.loader.modificationCheckInterval" property. By default,
- * the file timestamp is checked on every access (which is surprisingly fast).
- * Of course, this just applies when loading resources from the file system.
- * To enforce the use of SpringResourceLoader, i.e. to not resolve a path
- * as file system resource in any case, turn off the "preferFileSystemAccess"
- * flag. See the latter's javadoc for details.
- * @see #setResourceLoader
- * @see #setVelocityProperties
- * @see #setPreferFileSystemAccess
- * @see SpringResourceLoader
- * @see org.apache.velocity.runtime.resource.loader.FileResourceLoader
- */
- public void setResourceLoaderPath(String resourceLoaderPath) {
- this.resourceLoaderPath = resourceLoaderPath;
- }
-
- /**
- * Set the Spring ResourceLoader to use for loading Velocity template files.
- * The default is DefaultResourceLoader. Will get overridden by the
- * ApplicationContext if running in a context.
- * @see org.springframework.core.io.DefaultResourceLoader
- * @see org.springframework.context.ApplicationContext
- */
- public void setResourceLoader(ResourceLoader resourceLoader) {
- this.resourceLoader = resourceLoader;
- }
-
- /**
- * Return the Spring ResourceLoader to use for loading Velocity template files.
- */
- protected ResourceLoader getResourceLoader() {
- return this.resourceLoader;
- }
-
- /**
- * Set whether to prefer file system access for template loading.
- * File system access enables hot detection of template changes.
- * If this is enabled, VelocityEngineFactory will try to resolve the
- * specified "resourceLoaderPath" as file system resource (which will work
- * for expanded class path resources and ServletContext resources too).
- * Default is "true". Turn this off to always load via SpringResourceLoader
- * (i.e. as stream, without hot detection of template changes), which might
- * be necessary if some of your templates reside in an expanded classes
- * directory while others reside in jar files.
- * @see #setResourceLoaderPath
- */
- public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
- this.preferFileSystemAccess = preferFileSystemAccess;
- }
-
- /**
- * Return whether to prefer file system access for template loading.
- */
- protected boolean isPreferFileSystemAccess() {
- return this.preferFileSystemAccess;
- }
-
- /**
- * Set whether Velocity should log via Commons Logging, i.e. whether Velocity's
- * log system should be set to {@link CommonsLogLogChute}. Default is "true".
- */
- public void setOverrideLogging(boolean overrideLogging) {
- this.overrideLogging = overrideLogging;
- }
-
-
- /**
- * Prepare the VelocityEngine instance and return it.
- * @return the VelocityEngine instance
- * @throws IOException if the config file wasn't found
- * @throws VelocityException on Velocity initialization failure
- */
- public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
- VelocityEngine velocityEngine = newVelocityEngine();
- Map Called by {@code createVelocityEngine()}.
- * @return the VelocityEngine instance
- * @throws IOException if a config file wasn't found
- * @throws VelocityException on Velocity initialization failure
- * @see #createVelocityEngine()
- */
- protected VelocityEngine newVelocityEngine() throws IOException, VelocityException {
- return new VelocityEngine();
- }
-
- /**
- * Initialize a Velocity resource loader for the given VelocityEngine:
- * either a standard Velocity FileResourceLoader or a SpringResourceLoader.
- * Called by {@code createVelocityEngine()}.
- * @param velocityEngine the VelocityEngine to configure
- * @param resourceLoaderPath the path to load Velocity resources from
- * @see org.apache.velocity.runtime.resource.loader.FileResourceLoader
- * @see SpringResourceLoader
- * @see #initSpringResourceLoader
- * @see #createVelocityEngine()
- */
- protected void initVelocityResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
- if (isPreferFileSystemAccess()) {
- // Try to load via the file system, fall back to SpringResourceLoader
- // (for hot detection of template changes, if possible).
- try {
- StringBuilder resolvedPath = new StringBuilder();
- String[] paths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath);
- for (int i = 0; i < paths.length; i++) {
- String path = paths[i];
- Resource resource = getResourceLoader().getResource(path);
- File file = resource.getFile(); // will fail if not resolvable in the file system
- if (logger.isDebugEnabled()) {
- logger.debug("Resource loader path [" + path + "] resolved to file [" + file.getAbsolutePath() + "]");
- }
- resolvedPath.append(file.getAbsolutePath());
- if (i < paths.length - 1) {
- resolvedPath.append(',');
- }
- }
- velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
- velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
- velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, resolvedPath.toString());
- }
- catch (IOException ex) {
- if (logger.isDebugEnabled()) {
- logger.debug("Cannot resolve resource loader path [" + resourceLoaderPath +
- "] to [java.io.File]: using SpringResourceLoader", ex);
- }
- initSpringResourceLoader(velocityEngine, resourceLoaderPath);
- }
- }
- else {
- // Always load via SpringResourceLoader
- // (without hot detection of template changes).
- if (logger.isDebugEnabled()) {
- logger.debug("File system access not preferred: using SpringResourceLoader");
- }
- initSpringResourceLoader(velocityEngine, resourceLoaderPath);
- }
- }
-
- /**
- * Initialize a SpringResourceLoader for the given VelocityEngine.
- * Called by {@code initVelocityResourceLoader}.
- * @param velocityEngine the VelocityEngine to configure
- * @param resourceLoaderPath the path to load Velocity resources from
- * @see SpringResourceLoader
- * @see #initVelocityResourceLoader
- */
- protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
- velocityEngine.setProperty(
- RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME);
- velocityEngine.setProperty(
- SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName());
- velocityEngine.setProperty(
- SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true");
- velocityEngine.setApplicationAttribute(
- SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader());
- velocityEngine.setApplicationAttribute(
- SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath);
- }
-
- /**
- * To be implemented by subclasses that want to perform custom
- * post-processing of the VelocityEngine after this FactoryBean
- * performed its default configuration (but before VelocityEngine.init).
- * Called by {@code createVelocityEngine()}.
- * @param velocityEngine the current VelocityEngine
- * @throws IOException if a config file wasn't found
- * @throws VelocityException on Velocity initialization failure
- * @see #createVelocityEngine()
- * @see org.apache.velocity.app.VelocityEngine#init
- */
- protected void postProcessVelocityEngine(VelocityEngine velocityEngine)
- throws IOException, VelocityException {
- }
-
-}
diff --git a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactoryBean.java b/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactoryBean.java
deleted file mode 100644
index bb2baa16398..00000000000
--- a/spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactoryBean.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.ui.velocity;
-
-import java.io.IOException;
-
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.VelocityException;
-
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ResourceLoaderAware;
-
-/**
- * Factory bean that configures a VelocityEngine and provides it as bean
- * reference. This bean is intended for any kind of usage of Velocity in
- * application code, e.g. for generating email content. For web views,
- * VelocityConfigurer is used to set up a VelocityEngine for views.
- *
- * The simplest way to use this class is to specify a "resourceLoaderPath";
- * you do not need any further configuration then. For example, in a web
- * application context:
- *
- * When using this method to prepare a text for a mail to be sent with Spring's
- * mail support, consider wrapping VelocityException in MailPreparationException.
- * @param velocityEngine VelocityEngine to work with
- * @param templateLocation the location of template, relative to Velocity's resource loader path
- * @param model the Map that contains model names as keys and model objects as values
- * @return the result as String
- * @throws VelocityException if the template wasn't found or rendering failed
- * @see org.springframework.mail.MailPreparationException
- * @deprecated Use {@link #mergeTemplateIntoString(VelocityEngine, String, String, Map)}
- * instead, following Velocity 1.6's corresponding deprecation in its own API.
- */
- @Deprecated
- public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation,
- Map When using this method to prepare a text for a mail to be sent with Spring's
- * mail support, consider wrapping VelocityException in MailPreparationException.
- * @param velocityEngine VelocityEngine to work with
- * @param templateLocation the location of template, relative to Velocity's resource loader path
- * @param encoding the encoding of the template file
- * @param model the Map that contains model names as keys and model objects as values
- * @return the result as String
- * @throws VelocityException if the template wasn't found or rendering failed
- * @see org.springframework.mail.MailPreparationException
- */
- public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation,
- String encoding, Map Note that you must also configure Velocity by adding a
- * {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer} bean.
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
- @Deprecated
- public UrlBasedViewResolverRegistration velocity() {
- if (this.applicationContext != null && !hasBeanOfType(org.springframework.web.servlet.view.velocity.VelocityConfigurer.class)) {
- throw new BeanInitializationException("In addition to a Velocity view resolver " +
- "there must also be a single VelocityConfig bean in this web application context " +
- "(or its parent): VelocityConfigurer is the usual implementation. " +
- "This bean may be given any name.");
- }
- VelocityRegistration registration = new VelocityRegistration();
- this.viewResolvers.add(registration.getViewResolver());
- return registration;
- }
-
/**
* Register a Groovy markup view resolver with an empty default view name
* prefix and a default suffix of ".tpl".
@@ -309,15 +289,6 @@ public class ViewResolverRegistry {
}
}
- private static class VelocityRegistration extends UrlBasedViewResolverRegistration {
-
- @SuppressWarnings("deprecation")
- public VelocityRegistration() {
- super(new org.springframework.web.servlet.view.velocity.VelocityViewResolver());
- getViewResolver().setSuffix(".vm");
- }
- }
-
private static class FreeMarkerRegistration extends UrlBasedViewResolverRegistration {
public FreeMarkerRegistration() {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java
index 4fd4058ef15..dd003191e75 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/BindStatus.java
@@ -31,7 +31,7 @@ import org.springframework.web.util.HtmlUtils;
/**
* Simple adapter to expose the bind status of a field or object.
- * Set as a variable both by the JSP bind tag and Velocity/FreeMarker macros.
+ * Set as a variable both by the JSP bind tag and FreeMarker macros.
*
* Obviously, object status representations (i.e. errors at the object level
* rather than the field level) do not have an expression and a value but only
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java
index 9fae8679613..c1c9fa2e566 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -53,17 +53,18 @@ import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.WebUtils;
/**
- * Context holder for request-specific state, like current web application context, current locale, current theme,
- * and potential binding errors. Provides easy access to localized messages and Errors instances.
+ * Context holder for request-specific state, like current web application context, current locale,
+ * current theme, and potential binding errors. Provides easy access to localized messages and
+ * Errors instances.
*
- * Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL, Velocity
- * templates, etc. Necessary for views that do not have access to the servlet request, like Velocity templates.
+ * Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL,
+ * etc. Necessary for views that do not have access to the servlet request, like FreeMarker templates.
*
* Can be instantiated manually, or automatically exposed to views as model attribute via AbstractView's
* "requestContextAttribute" property.
*
- * Will also work outside of DispatcherServlet requests, accessing the root WebApplicationContext and using
- * an appropriate fallback for the locale (the HttpServletRequest's primary locale).
+ * Will also work outside of DispatcherServlet requests, accessing the root WebApplicationContext
+ * and using an appropriate fallback for the locale (the HttpServletRequest's primary locale).
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java
index 3f2f94ed574..899313949a7 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -123,8 +123,8 @@ public abstract class AbstractCachingViewResolver extends WebApplicationObjectSu
* Note that this flag only applies if the general {@link #setCache "cache"}
* flag is kept at its default of "true" as well.
* Of specific interest is the ability for some AbstractUrlBasedView
- * implementations (FreeMarker, Velocity, Tiles) to check if an underlying
- * resource exists via {@link AbstractUrlBasedView#checkResource(Locale)}.
+ * implementations (FreeMarker, Tiles) to check if an underlying resource
+ * exists via {@link AbstractUrlBasedView#checkResource(Locale)}.
* With this flag set to "false", an underlying resource that re-appears
* is noticed and used. With the flag set to "true", one check is made only.
*/
@@ -185,7 +185,7 @@ public abstract class AbstractCachingViewResolver extends WebApplicationObjectSu
/**
* Provides functionality to clear the cache for a certain view.
* This can be handy in case developer are able to modify views
- * (e.g. Velocity templates) at runtime after which you'd need to
+ * (e.g. FreeMarker templates) at runtime after which you'd need to
* clear the cache for the specified view.
* @param viewName the view name for which the cached view object
* (if any) needs to be removed
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateView.java
index f1d6e37d3dc..e8d00d273ff 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -26,10 +26,9 @@ import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.support.RequestContext;
/**
- * Adapter base class for template-based view technologies such as
- * Velocity and FreeMarker, with the ability to use request and session
- * attributes in their model and the option to expose helper objects
- * for Spring's Velocity/FreeMarker macro library.
+ * Adapter base class for template-based view technologies such as FreeMarker,
+ * with the ability to use request and session attributes in their model and
+ * the option to expose helper objects for Spring's FreeMarker macro library.
*
* JSP/JSTL and other view technologies automatically have access to the
* HttpServletRequest object and thereby the request/session attributes
@@ -40,7 +39,6 @@ import org.springframework.web.servlet.support.RequestContext;
* @author Darren Davison
* @since 1.0.2
* @see AbstractTemplateViewResolver
- * @see org.springframework.web.servlet.view.velocity.VelocityView
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerView
*/
public abstract class AbstractTemplateView extends AbstractUrlBasedView {
@@ -102,9 +100,9 @@ public abstract class AbstractTemplateView extends AbstractUrlBasedView {
/**
* Set whether to expose a RequestContext for use by Spring's macro library,
* under the name "springMacroRequestContext". Default is "true".
- * Currently needed for Spring's Velocity and FreeMarker default macros.
- * Note that this is not required for templates that use HTML
- * forms unless you wish to take advantage of the Spring helper macros.
+ * Currently needed for Spring's FreeMarker default macros.
+ * Note that this is not required for templates that use HTML forms
+ * unless you wish to take advantage of the Spring helper macros.
* @see #SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
*/
public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateViewResolver.java
index 3250cf35ea9..a97fcd2f6b3 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateViewResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractTemplateViewResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2016 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,17 +17,14 @@
package org.springframework.web.servlet.view;
/**
- * Abstract base class for template view resolvers,
- * in particular for Velocity and FreeMarker views.
+ * Abstract base class for template view resolvers, in particular for FreeMarker views.
*
- * Provides a convenient way to specify {@link AbstractTemplateView}'s
- * exposure flags for request attributes, session attributes,
- * and Spring's macro helpers.
+ * Provides a convenient way to specify {@link AbstractTemplateView}'s exposure
+ * flags for request attributes, session attributes, and Spring's macro helpers.
*
* @author Juergen Hoeller
* @since 1.1
* @see AbstractTemplateView
- * @see org.springframework.web.servlet.view.velocity.VelocityViewResolver
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver
*/
public class AbstractTemplateViewResolver extends UrlBasedViewResolver {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java
index 9b09f8a9656..a565c350ead 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/UrlBasedViewResolver.java
@@ -36,9 +36,8 @@ import org.springframework.web.servlet.View;
* (i.e. the symbolic name is the unique part of the resource's filename),
* without the need for a dedicated mapping to be defined for each view.
*
- * Supports {@link AbstractUrlBasedView} subclasses like {@link InternalResourceView},
- * {@link org.springframework.web.servlet.view.velocity.VelocityView} and
- * {@link org.springframework.web.servlet.view.freemarker.FreeMarkerView}.
+ * Supports {@link AbstractUrlBasedView} subclasses like {@link InternalResourceView}
+ * and {@link org.springframework.web.servlet.view.freemarker.FreeMarkerView}.
* The view class for all views generated by this resolver can be specified
* via the "viewClass" property.
*
@@ -79,7 +78,6 @@ import org.springframework.web.servlet.View;
* @see #REDIRECT_URL_PREFIX
* @see AbstractUrlBasedView
* @see InternalResourceView
- * @see org.springframework.web.servlet.view.velocity.VelocityView
* @see org.springframework.web.servlet.view.freemarker.FreeMarkerView
*/
public class UrlBasedViewResolver extends AbstractCachingViewResolver implements Ordered {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java
index 27f4fc9d4dc..9dd27b5879b 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/package-info.java
@@ -3,7 +3,7 @@
* including abstract base classes for custom implementations.
*
* Application developers don't usually need to implement views,
- * as the framework provides standard views for JSPs, Velocity,
+ * as the framework provides standard views for JSPs, FreeMarker,
* XSLT, etc. However, the ability to implement custom views easily
* by subclassing the AbstractView class in this package can be
* very helpful if an application has unusual view requirements.
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfig.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfig.java
deleted file mode 100644
index 934883a3092..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfig.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import org.apache.velocity.app.VelocityEngine;
-
-/**
- * Interface to be implemented by objects that configure and manage a
- * VelocityEngine for automatic lookup in a web environment. Detected
- * and used by VelocityView.
- *
- * @author Rod Johnson
- * @see VelocityConfigurer
- * @see VelocityView
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public interface VelocityConfig {
-
- /**
- * Return the VelocityEngine for the current web application context.
- * May be unique to one servlet, or shared in the root context.
- * @return the VelocityEngine
- */
- VelocityEngine getVelocityEngine();
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfigurer.java
deleted file mode 100644
index 5f10a43ad3c..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityConfigurer.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import java.io.IOException;
-import javax.servlet.ServletContext;
-
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ResourceLoaderAware;
-import org.springframework.web.context.ServletContextAware;
-
-/**
- * JavaBean to configure Velocity for web usage, via the "configLocation"
- * and/or "velocityProperties" and/or "resourceLoaderPath" bean properties.
- * The simplest way to use this class is to specify just a "resourceLoaderPath";
- * you do not need any further configuration then.
- *
- * Note that you can also refer to a pre-configured VelocityEngine
- * instance via the "velocityEngine" property, e.g. set up by
- * {@link org.springframework.ui.velocity.VelocityEngineFactoryBean},
- * This allows to share a VelocityEngine for web and email usage, for example.
- *
- * This configurer registers the "spring.vm" Velocimacro library for web views
- * (contained in this package and thus in {@code spring.jar}), which makes
- * all of Spring's default Velocity macros available to the views.
- * This allows for using the Spring-provided macros such as follows:
- *
- * Note that the Spring macros will not be enabled automatically in
- * case of an external VelocityEngine passed in here. Make sure to include
- * {@code spring.vm} in your template loader path in such a scenario
- * (if there is an actual need to use those macros).
- * If this is not set, VelocityEngineFactory's properties
- * (inherited by this class) have to be specified.
- */
- public void setVelocityEngine(VelocityEngine velocityEngine) {
- this.velocityEngine = velocityEngine;
- }
-
- @Override
- public void setServletContext(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- /**
- * Initialize VelocityEngineFactory's VelocityEngine
- * if not overridden by a pre-configured VelocityEngine.
- * @see #createVelocityEngine
- * @see #setVelocityEngine
- */
- @Override
- public void afterPropertiesSet() throws IOException, VelocityException {
- if (this.velocityEngine == null) {
- this.velocityEngine = createVelocityEngine();
- }
- }
-
- /**
- * Provides a ClasspathResourceLoader in addition to any default or user-defined
- * loader in order to load the spring Velocity macros from the class path.
- * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
- */
- @Override
- protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
- velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
- velocityEngine.setProperty(
- SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
- velocityEngine.addProperty(
- VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
- velocityEngine.addProperty(
- VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);
-
- if (logger.isInfoEnabled()) {
- logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
- "' added to configured VelocityEngine");
- }
- }
-
- @Override
- public VelocityEngine getVelocityEngine() {
- return this.velocityEngine;
- }
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutView.java
deleted file mode 100644
index b5e3ae8a55a..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutView.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import java.io.StringWriter;
-import java.util.Locale;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.velocity.Template;
-import org.apache.velocity.context.Context;
-import org.apache.velocity.exception.ResourceNotFoundException;
-
-import org.springframework.core.NestedIOException;
-
-/**
- * VelocityLayoutView emulates the functionality offered by Velocity's
- * VelocityLayoutServlet to ease page composition from different templates.
- *
- * The {@code url} property should be set to the content template
- * for the view, and the layout template location should be specified as
- * {@code layoutUrl} property. A view can override the configured
- * layout template location by setting the appropriate key (the default
- * is "layout") in the content template.
- *
- * When the view is rendered, the VelocityContext is first merged with
- * the content template (specified by the {@code url} property) and
- * then merged with the layout template to produce the final output.
- *
- * The layout template can include the screen content through a
- * VelocityContext variable (the default is "screen_content").
- * At runtime, this variable will contain the rendered content template.
- *
- * @author Darren Davison
- * @author Juergen Hoeller
- * @since 1.2
- * @see #setLayoutUrl
- * @see #setLayoutKey
- * @see #setScreenContentKey
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityLayoutView extends VelocityToolboxView {
-
- /**
- * The default {@link #setLayoutUrl(String) layout url}.
- */
- public static final String DEFAULT_LAYOUT_URL = "layout.vm";
-
- /**
- * The default {@link #setLayoutKey(String) layout key}.
- */
- public static final String DEFAULT_LAYOUT_KEY = "layout";
-
- /**
- * The default {@link #setScreenContentKey(String) screen content key}.
- */
- public static final String DEFAULT_SCREEN_CONTENT_KEY = "screen_content";
-
-
- private String layoutUrl = DEFAULT_LAYOUT_URL;
-
- private String layoutKey = DEFAULT_LAYOUT_KEY;
-
- private String screenContentKey = DEFAULT_SCREEN_CONTENT_KEY;
-
-
- /**
- * Set the layout template to use. Default is {@link #DEFAULT_LAYOUT_URL "layout.vm"}.
- * @param layoutUrl the template location (relative to the template
- * root directory)
- */
- public void setLayoutUrl(String layoutUrl) {
- this.layoutUrl = layoutUrl;
- }
-
- /**
- * Set the context key used to specify an alternate layout to be used instead
- * of the default layout. Screen content templates can override the layout
- * template that they wish to be wrapped with by setting this value in the
- * template, for example: Default key is {@link #DEFAULT_LAYOUT_KEY "layout"}, as illustrated above.
- * @param layoutKey the name of the key you wish to use in your
- * screen content templates to override the layout template
- */
- public void setLayoutKey(String layoutKey) {
- this.layoutKey = layoutKey;
- }
-
- /**
- * Set the name of the context key that will hold the content of
- * the screen within the layout template. This key must be present
- * in the layout template for the current screen to be rendered.
- * Default is {@link #DEFAULT_SCREEN_CONTENT_KEY "screen_content"}:
- * accessed in VTL as {@code $screen_content}.
- * @param screenContentKey the name of the screen content key to use
- */
- public void setScreenContentKey(String screenContentKey) {
- this.screenContentKey = screenContentKey;
- }
-
-
- /**
- * Overrides {@code VelocityView.checkTemplate()} to additionally check
- * that both the layout template and the screen content template can be loaded.
- * Note that during rendering of the screen content, the layout template
- * can be changed which may invalidate any early checking done here.
- */
- @Override
- public boolean checkResource(Locale locale) throws Exception {
- if (!super.checkResource(locale)) {
- return false;
- }
-
- try {
- // Check that we can get the template, even if we might subsequently get it again.
- getTemplate(this.layoutUrl);
- return true;
- }
- catch (ResourceNotFoundException ex) {
- throw new NestedIOException("Cannot find Velocity template for URL [" + this.layoutUrl +
- "]: Did you specify the correct resource loader path?", ex);
- }
- catch (Exception ex) {
- throw new NestedIOException(
- "Could not load Velocity template for URL [" + this.layoutUrl + "]", ex);
- }
- }
-
- /**
- * Overrides the normal rendering process in order to pre-process the Context,
- * merging it with the screen template into a single value (identified by the
- * value of screenContentKey). The layout template is then merged with the
- * modified Context in the super class.
- */
- @Override
- protected void doRender(Context context, HttpServletResponse response) throws Exception {
- renderScreenContent(context);
-
- // Velocity context now includes any mappings that were defined
- // (via #set) in screen content template.
- // The screen template can overrule the layout by doing
- // #set( $layout = "MyLayout.vm" )
- String layoutUrlToUse = (String) context.get(this.layoutKey);
- if (layoutUrlToUse != null) {
- if (logger.isDebugEnabled()) {
- logger.debug("Screen content template has requested layout [" + layoutUrlToUse + "]");
- }
- }
- else {
- // No explicit layout URL given -> use default layout of this view.
- layoutUrlToUse = this.layoutUrl;
- }
-
- mergeTemplate(getTemplate(layoutUrlToUse), context, response);
- }
-
- /**
- * The resulting context contains any mappings from render, plus screen content.
- */
- private void renderScreenContent(Context velocityContext) throws Exception {
- if (logger.isDebugEnabled()) {
- logger.debug("Rendering screen content template [" + getUrl() + "]");
- }
-
- StringWriter sw = new StringWriter();
- Template screenContentTemplate = getTemplate(getUrl());
- screenContentTemplate.merge(velocityContext, sw);
-
- // Put rendered content into Velocity context.
- velocityContext.put(this.screenContentKey, sw.toString());
- }
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutViewResolver.java
deleted file mode 100644
index 630dcc3e37b..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityLayoutViewResolver.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import org.springframework.web.servlet.view.AbstractUrlBasedView;
-
-/**
- * Convenience subclass of VelocityViewResolver, adding support
- * for VelocityLayoutView and its properties.
- *
- * See VelocityViewResolver's javadoc for general usage info.
- *
- * @author Juergen Hoeller
- * @since 1.2.7
- * @see VelocityViewResolver
- * @see VelocityLayoutView
- * @see #setLayoutUrl
- * @see #setLayoutKey
- * @see #setScreenContentKey
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityLayoutViewResolver extends VelocityViewResolver {
-
- private String layoutUrl;
-
- private String layoutKey;
-
- private String screenContentKey;
-
-
- /**
- * Requires VelocityLayoutView.
- * @see VelocityLayoutView
- */
- @Override
- protected Class> requiredViewClass() {
- return VelocityLayoutView.class;
- }
-
- /**
- * Set the layout template to use. Default is "layout.vm".
- * @param layoutUrl the template location (relative to the template
- * root directory)
- * @see VelocityLayoutView#setLayoutUrl
- */
- public void setLayoutUrl(String layoutUrl) {
- this.layoutUrl = layoutUrl;
- }
-
- /**
- * Set the context key used to specify an alternate layout to be used instead
- * of the default layout. Screen content templates can override the layout
- * template that they wish to be wrapped with by setting this value in the
- * template, for example: The default key is "layout", as illustrated above.
- * @param layoutKey the name of the key you wish to use in your
- * screen content templates to override the layout template
- * @see VelocityLayoutView#setLayoutKey
- */
- public void setLayoutKey(String layoutKey) {
- this.layoutKey = layoutKey;
- }
-
- /**
- * Set the name of the context key that will hold the content of
- * the screen within the layout template. This key must be present
- * in the layout template for the current screen to be rendered.
- * Default is "screen_content": accessed in VTL as
- * {@code $screen_content}.
- * @param screenContentKey the name of the screen content key to use
- * @see VelocityLayoutView#setScreenContentKey
- */
- public void setScreenContentKey(String screenContentKey) {
- this.screenContentKey = screenContentKey;
- }
-
-
- @Override
- protected AbstractUrlBasedView buildView(String viewName) throws Exception {
- VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName);
- // Use not-null checks to preserve VelocityLayoutView's defaults.
- if (this.layoutUrl != null) {
- view.setLayoutUrl(this.layoutUrl);
- }
- if (this.layoutKey != null) {
- view.setLayoutKey(this.layoutKey);
- }
- if (this.screenContentKey != null) {
- view.setScreenContentKey(this.screenContentKey);
- }
- return view;
- }
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java
deleted file mode 100644
index 8513f9d511b..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityToolboxView.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2002-2010 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.context.Context;
-import org.apache.velocity.tools.view.ToolboxManager;
-import org.apache.velocity.tools.view.context.ChainedContext;
-import org.apache.velocity.tools.view.servlet.ServletToolboxManager;
-
-import org.springframework.util.ClassUtils;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * {@link VelocityView} subclass which adds support for Velocity Tools toolboxes
- * and Velocity Tools ViewTool callbacks / Velocity Tools 1.3 init methods.
- *
- * Specify a "toolboxConfigLocation", for example "/WEB-INF/toolbox.xml",
- * to automatically load a Velocity Tools toolbox definition file and expose
- * all defined tools in the specified scopes. If no config location is
- * specified, no toolbox will be loaded and exposed.
- *
- * This view will always create a special Velocity context, namely an
- * instance of the ChainedContext class which is part of the view package
- * of Velocity tools. This allows to use tools from the view package of
- * Velocity Tools, like LinkTool, which need to be initialized with a special
- * context that implements the ViewContext interface (i.e. a ChainedContext).
- *
- * This view also checks tools that are specified as "toolAttributes":
- * If they implement the ViewTool interface, they will get initialized with
- * the Velocity context. This allows tools from the view package of Velocity
- * Tools, such as LinkTool, to be defined as
- * {@link #setToolAttributes "toolAttributes"} on a VelocityToolboxView,
- * instead of in a separate toolbox XML file.
- *
- * This is a separate class mainly to avoid a required dependency on
- * the view package of Velocity Tools in {@link VelocityView} itself.
- * As of Spring 3.0, this class requires Velocity Tools 1.3 or higher.
- *
- * @author Juergen Hoeller
- * @since 1.1.3
- * @see #setToolboxConfigLocation
- * @see #initTool
- * @see org.apache.velocity.tools.view.context.ViewContext
- * @see org.apache.velocity.tools.view.context.ChainedContext
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityToolboxView extends VelocityView {
-
- private String toolboxConfigLocation;
-
-
- /**
- * Set a Velocity Toolbox config location, for example "/WEB-INF/toolbox.xml",
- * to automatically load a Velocity Tools toolbox definition file and expose
- * all defined tools in the specified scopes. If no config location is
- * specified, no toolbox will be loaded and exposed.
- * The specified location string needs to refer to a ServletContext
- * resource, as expected by ServletToolboxManager which is part of
- * the view package of Velocity Tools.
- * @see org.apache.velocity.tools.view.servlet.ServletToolboxManager#getInstance
- */
- public void setToolboxConfigLocation(String toolboxConfigLocation) {
- this.toolboxConfigLocation = toolboxConfigLocation;
- }
-
- /**
- * Return the Velocity Toolbox config location, if any.
- */
- protected String getToolboxConfigLocation() {
- return this.toolboxConfigLocation;
- }
-
-
- /**
- * Overridden to create a ChainedContext, which is part of the view package
- * of Velocity Tools, as special context. ChainedContext is needed for
- * initialization of ViewTool instances.
- * @see #initTool
- */
- @Override
- protected Context createVelocityContext(
- Map Exposes the following JavaBean properties:
- * Depends on a VelocityConfig object such as VelocityConfigurer being
- * accessible in the current web application context, with any bean name.
- * Alternatively, you can set the VelocityEngine object as bean property.
- *
- * Note: Spring 3.0's VelocityView requires Velocity 1.4 or higher, and optionally
- * Velocity Tools 1.1 or higher (depending on the use of DateTool and/or NumberTool).
- *
- * @author Rod Johnson
- * @author Juergen Hoeller
- * @author Dave Syer
- * @see VelocityConfig
- * @see VelocityConfigurer
- * @see #setUrl
- * @see #setExposeSpringMacroHelpers
- * @see #setEncoding
- * @see #setVelocityEngine
- * @see VelocityConfig
- * @see VelocityConfigurer
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityView extends AbstractTemplateView {
-
- private Map For example, an instance of MathTool, which is part of the generic package
- * of Velocity Tools, can be bound under the attribute name "math", specifying the
- * fully qualified class name "org.apache.velocity.tools.generic.MathTool" as value.
- * Note that VelocityView can only create simple generic tools or values, that is,
- * classes with a public default constructor and no further initialization needs.
- * This class does not do any further checks, to not introduce a required dependency
- * on a specific tools package.
- * For tools that are part of the view package of Velocity Tools, a special
- * Velocity context and a special init callback are needed. Use VelocityToolboxView
- * in such a case, or override {@code createVelocityContext} and
- * {@code initTool} accordingly.
- * For a simple VelocityFormatter instance or special locale-aware instances
- * of DateTool/NumberTool, which are part of the generic package of Velocity Tools,
- * specify the "velocityFormatterAttribute", "dateToolAttribute" or
- * "numberToolAttribute" properties, respectively.
- * @param toolAttributes attribute names as keys, and tool class names as values
- * @see org.apache.velocity.tools.generic.MathTool
- * @see VelocityToolboxView
- * @see #createVelocityContext
- * @see #initTool
- * @see #setDateToolAttribute
- * @see #setNumberToolAttribute
- */
- public void setToolAttributes(Map DateTool is part of the generic package of Velocity Tools 1.0.
- * Spring uses a special locale-aware subclass of DateTool.
- * @see org.apache.velocity.tools.generic.DateTool
- * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
- * @see org.springframework.web.servlet.LocaleResolver
- */
- public void setDateToolAttribute(String dateToolAttribute) {
- this.dateToolAttribute = dateToolAttribute;
- }
-
- /**
- * Set the name of the NumberTool helper object to expose in the Velocity context
- * of this view, or {@code null} if not needed. The exposed NumberTool will be aware of
- * the current locale, as determined by Spring's LocaleResolver.
- * NumberTool is part of the generic package of Velocity Tools 1.1.
- * Spring uses a special locale-aware subclass of NumberTool.
- * @see org.apache.velocity.tools.generic.NumberTool
- * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
- * @see org.springframework.web.servlet.LocaleResolver
- */
- public void setNumberToolAttribute(String numberToolAttribute) {
- this.numberToolAttribute = numberToolAttribute;
- }
-
- /**
- * Set the encoding of the Velocity template file. Default is determined
- * by the VelocityEngine: "ISO-8859-1" if not specified otherwise.
- * Specify the encoding in the VelocityEngine rather than per template
- * if all your templates share a common encoding.
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Return the encoding for the Velocity template.
- */
- protected String getEncoding() {
- return this.encoding;
- }
-
- /**
- * Set whether the Velocity template should be cached. Default is "false".
- * It should normally be true in production, but setting this to false enables us to
- * modify Velocity templates without restarting the application (similar to JSPs).
- * Note that this is a minor optimization only, as Velocity itself caches
- * templates in a modification-aware fashion.
- */
- public void setCacheTemplate(boolean cacheTemplate) {
- this.cacheTemplate = cacheTemplate;
- }
-
- /**
- * Return whether the Velocity template should be cached.
- */
- protected boolean isCacheTemplate() {
- return this.cacheTemplate;
- }
-
- /**
- * Set the VelocityEngine to be used by this view.
- * If this is not set, the default lookup will occur: A single VelocityConfig
- * is expected in the current web application context, with any bean name.
- * @see VelocityConfig
- */
- public void setVelocityEngine(VelocityEngine velocityEngine) {
- this.velocityEngine = velocityEngine;
- }
-
- /**
- * Return the VelocityEngine used by this view.
- */
- protected VelocityEngine getVelocityEngine() {
- return this.velocityEngine;
- }
-
-
- /**
- * Invoked on startup. Looks for a single VelocityConfig bean to
- * find the relevant VelocityEngine for this factory.
- */
- @Override
- protected void initApplicationContext() throws BeansException {
- super.initApplicationContext();
-
- if (getVelocityEngine() == null) {
- // No explicit VelocityEngine: try to autodetect one.
- setVelocityEngine(autodetectVelocityEngine());
- }
- }
-
- /**
- * Autodetect a VelocityEngine via the ApplicationContext.
- * Called if no explicit VelocityEngine has been specified.
- * @return the VelocityEngine to use for VelocityViews
- * @throws BeansException if no VelocityEngine could be found
- * @see #getApplicationContext
- * @see #setVelocityEngine
- */
- protected VelocityEngine autodetectVelocityEngine() throws BeansException {
- try {
- VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(
- getApplicationContext(), VelocityConfig.class, true, false);
- return velocityConfig.getVelocityEngine();
- }
- catch (NoSuchBeanDefinitionException ex) {
- throw new ApplicationContextException(
- "Must define a single VelocityConfig bean in this web application context " +
- "(may be inherited): VelocityConfigurer is the usual implementation. " +
- "This bean may be given any name.", ex);
- }
- }
-
- /**
- * Check that the Velocity template used for this view exists and is valid.
- * Can be overridden to customize the behavior, for example in case of
- * multiple templates to be rendered into a single view.
- */
- @Override
- public boolean checkResource(Locale locale) throws Exception {
- try {
- // Check that we can get the template, even if we might subsequently get it again.
- this.template = getTemplate(getUrl());
- return true;
- }
- catch (ResourceNotFoundException ex) {
- if (logger.isDebugEnabled()) {
- logger.debug("No Velocity view found for URL: " + getUrl());
- }
- return false;
- }
- catch (Exception ex) {
- throw new NestedIOException(
- "Could not load Velocity template for URL [" + getUrl() + "]", ex);
- }
- }
-
-
- /**
- * Process the model map by merging it with the Velocity template.
- * Output is directed to the servlet response.
- * This method can be overridden if custom behavior is needed.
- */
- @Override
- protected void renderMergedTemplateModel(
- Map Called by {@code renderMergedTemplateModel}. The default implementation
- * is empty. This method can be overridden to add custom helpers to the model.
- * @param model the model that will be passed to the template for merging
- * @param request current HTTP request
- * @throws Exception if there's a fatal error while we're adding model attributes
- * @see #renderMergedTemplateModel
- */
- protected void exposeHelpers(Map The default implementation delegates to {@link #createVelocityContext(Map)}.
- * Can be overridden for a special context class, for example ChainedContext which
- * is part of the view package of Velocity Tools. ChainedContext is needed for
- * initialization of ViewTool instances.
- * Have a look at {@link VelocityToolboxView}, which pre-implements
- * ChainedContext support. This is not part of the standard VelocityView class
- * in order to avoid a required dependency on the view package of Velocity Tools.
- * @param model the model Map, containing the model attributes to be exposed to the view
- * @param request current HTTP request
- * @param response current HTTP response
- * @return the Velocity Context
- * @throws Exception if there's a fatal error while creating the context
- * @see #createVelocityContext(Map)
- * @see #initTool
- * @see org.apache.velocity.tools.view.context.ChainedContext
- * @see VelocityToolboxView
- */
- protected Context createVelocityContext(
- Map Default implementation creates an instance of Velocity's
- * VelocityContext implementation class.
- * @param model the model Map, containing the model attributes
- * to be exposed to the view
- * @return the Velocity Context
- * @throws Exception if there's a fatal error while creating the context
- * @see org.apache.velocity.VelocityContext
- */
- protected Context createVelocityContext(Map Called by {@code renderMergedTemplateModel}. Default implementation
- * delegates to {@code exposeHelpers(velocityContext, request)}. This method
- * can be overridden to add special tools to the context, needing the servlet response
- * to initialize (see Velocity Tools, for example LinkTool and ViewTool/ChainedContext).
- * @param velocityContext Velocity context that will be passed to the template
- * @param request current HTTP request
- * @param response current HTTP response
- * @throws Exception if there's a fatal error while we're adding model attributes
- * @see #exposeHelpers(org.apache.velocity.context.Context, HttpServletRequest)
- */
- protected void exposeHelpers(
- Context velocityContext, HttpServletRequest request, HttpServletResponse response) throws Exception {
-
- exposeHelpers(velocityContext, request);
- }
-
- /**
- * Expose helpers unique to each rendering operation. This is necessary so that
- * different rendering operations can't overwrite each other's formats etc.
- * Default implementation is empty. This method can be overridden to add
- * custom helpers to the Velocity context.
- * @param velocityContext Velocity context that will be passed to the template
- * @param request current HTTP request
- * @throws Exception if there's a fatal error while we're adding model attributes
- * @see #exposeHelpers(Map, HttpServletRequest)
- */
- protected void exposeHelpers(Context velocityContext, HttpServletRequest request) throws Exception {
- }
-
- /**
- * Expose the tool attributes, according to corresponding bean property settings.
- * Do not override this method unless for further tools driven by bean properties.
- * Override one of the {@code exposeHelpers} methods to add custom helpers.
- * @param velocityContext Velocity context that will be passed to the template
- * @param request current HTTP request
- * @throws Exception if there's a fatal error while we're adding model attributes
- * @see #setDateToolAttribute
- * @see #setNumberToolAttribute
- * @see #exposeHelpers(Map, HttpServletRequest)
- * @see #exposeHelpers(org.apache.velocity.context.Context, HttpServletRequest, HttpServletResponse)
- */
- protected void exposeToolAttributes(Context velocityContext, HttpServletRequest request) throws Exception {
- // Expose generic attributes.
- if (this.toolAttributes != null) {
- for (Map.Entry Can be overridden to check for special callback interfaces, for example
- * the ViewContext interface which is part of the view package of Velocity Tools.
- * In the particular case of ViewContext, you'll usually also need a special
- * Velocity context, like ChainedContext which is part of Velocity Tools too.
- * Have a look at {@link VelocityToolboxView}, which pre-implements such a
- * ViewTool check. This is not part of the standard VelocityView class in order
- * to avoid a required dependency on the view package of Velocity Tools.
- * @param tool the tool instance to initialize
- * @param velocityContext the Velocity context
- * @throws Exception if initializion of the tool failed
- * @see #createVelocityContext
- * @see org.apache.velocity.tools.view.context.ViewContext
- * @see org.apache.velocity.tools.view.context.ChainedContext
- * @see VelocityToolboxView
- */
- protected void initTool(Object tool, Context velocityContext) throws Exception {
- }
-
-
- /**
- * Render the Velocity view to the given response, using the given Velocity
- * context which contains the complete template model to use.
- * The default implementation renders the template specified by the "url"
- * bean property, retrieved via {@code getTemplate}. It delegates to the
- * {@code mergeTemplate} method to merge the template instance with the
- * given Velocity context.
- * Can be overridden to customize the behavior, for example to render
- * multiple templates into a single view.
- * @param context the Velocity context to use for rendering
- * @param response servlet response (use this to get the OutputStream or Writer)
- * @throws Exception if thrown by Velocity
- * @see #setUrl
- * @see #getTemplate()
- * @see #mergeTemplate
- */
- protected void doRender(Context context, HttpServletResponse response) throws Exception {
- if (logger.isDebugEnabled()) {
- logger.debug("Rendering Velocity template [" + getUrl() + "] in VelocityView '" + getBeanName() + "'");
- }
- mergeTemplate(getTemplate(), context, response);
- }
-
- /**
- * Retrieve the Velocity template to be rendered by this view.
- * By default, the template specified by the "url" bean property will be
- * retrieved: either returning a cached template instance or loading a fresh
- * instance (according to the "cacheTemplate" bean property)
- * @return the Velocity template to render
- * @throws Exception if thrown by Velocity
- * @see #setUrl
- * @see #setCacheTemplate
- * @see #getTemplate(String)
- */
- protected Template getTemplate() throws Exception {
- // We already hold a reference to the template, but we might want to load it
- // if not caching. Velocity itself caches templates, so our ability to
- // cache templates in this class is a minor optimization only.
- if (isCacheTemplate() && this.template != null) {
- return this.template;
- }
- else {
- return getTemplate(getUrl());
- }
- }
-
- /**
- * Retrieve the Velocity template specified by the given name,
- * using the encoding specified by the "encoding" bean property.
- * Can be called by subclasses to retrieve a specific template,
- * for example to render multiple templates into a single view.
- * @param name the file name of the desired template
- * @return the Velocity template
- * @throws Exception if thrown by Velocity
- * @see org.apache.velocity.app.VelocityEngine#getTemplate
- */
- protected Template getTemplate(String name) throws Exception {
- return (getEncoding() != null ?
- getVelocityEngine().getTemplate(name, getEncoding()) :
- getVelocityEngine().getTemplate(name));
- }
-
- /**
- * Merge the template with the context.
- * Can be overridden to customize the behavior.
- * @param template the template to merge
- * @param context the Velocity context to use for rendering
- * @param response servlet response (use this to get the OutputStream or Writer)
- * @throws Exception if thrown by Velocity
- * @see org.apache.velocity.Template#merge
- */
- protected void mergeTemplate(
- Template template, Context context, HttpServletResponse response) throws Exception {
-
- try {
- template.merge(context, response.getWriter());
- }
- catch (MethodInvocationException ex) {
- Throwable cause = ex.getWrappedThrowable();
- throw new NestedServletException(
- "Method invocation failed during rendering of Velocity view with name '" +
- getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
- "], method '" + ex.getMethodName() + "'",
- cause==null ? ex : cause);
- }
- }
-
-
- /**
- * Subclass of DateTool from Velocity Tools, using a Spring-resolved
- * Locale and TimeZone instead of the default Locale.
- * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
- * @see org.springframework.web.servlet.support.RequestContextUtils#getTimeZone
- */
- private static class LocaleAwareDateTool extends DateTool {
-
- private final HttpServletRequest request;
-
- public LocaleAwareDateTool(HttpServletRequest request) {
- this.request = request;
- }
-
- @Override
- public Locale getLocale() {
- return RequestContextUtils.getLocale(this.request);
- }
-
- @Override
- public TimeZone getTimeZone() {
- TimeZone timeZone = RequestContextUtils.getTimeZone(this.request);
- return (timeZone != null ? timeZone : super.getTimeZone());
- }
- }
-
-
- /**
- * Subclass of NumberTool from Velocity Tools, using a Spring-resolved
- * Locale instead of the default Locale.
- * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
- */
- private static class LocaleAwareNumberTool extends NumberTool {
-
- private final HttpServletRequest request;
-
- public LocaleAwareNumberTool(HttpServletRequest request) {
- this.request = request;
- }
-
- @Override
- public Locale getLocale() {
- return RequestContextUtils.getLocale(this.request);
- }
- }
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityViewResolver.java
deleted file mode 100644
index 95191a4aaeb..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/VelocityViewResolver.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.view.velocity;
-
-import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
-import org.springframework.web.servlet.view.AbstractUrlBasedView;
-
-/**
- * Convenience subclass of {@link org.springframework.web.servlet.view.UrlBasedViewResolver}
- * that supports {@link VelocityView} (i.e. Velocity templates) and custom subclasses of it.
- *
- * The view class for all views generated by this resolver can be specified
- * via the "viewClass" property. See UrlBasedViewResolver's javadoc for details.
- *
- * Note: When chaining ViewResolvers, a VelocityViewResolver will
- * check for the existence of the specified template resources and only return
- * a non-null View object if the template was actually found.
- *
- * @author Juergen Hoeller
- * @since 13.12.2003
- * @see #setViewClass
- * @see #setPrefix
- * @see #setSuffix
- * @see #setRequestContextAttribute
- * @see #setExposeSpringMacroHelpers
- * @see #setDateToolAttribute
- * @see #setNumberToolAttribute
- * @see VelocityView
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityViewResolver extends AbstractTemplateViewResolver {
-
- private String dateToolAttribute;
-
- private String numberToolAttribute;
-
- private String toolboxConfigLocation;
-
-
- public VelocityViewResolver() {
- setViewClass(requiredViewClass());
- }
-
- /**
- * Requires {@link VelocityView}.
- */
- @Override
- protected Class> requiredViewClass() {
- return VelocityView.class;
- }
-
-
- /**
- * Set the name of the DateTool helper object to expose in the Velocity context
- * of this view, or {@code null} if not needed. DateTool is part of Velocity Tools 1.0.
- * @see org.apache.velocity.tools.generic.DateTool
- * @see VelocityView#setDateToolAttribute
- */
- public void setDateToolAttribute(String dateToolAttribute) {
- this.dateToolAttribute = dateToolAttribute;
- }
-
- /**
- * Set the name of the NumberTool helper object to expose in the Velocity context
- * of this view, or {@code null} if not needed. NumberTool is part of Velocity Tools 1.1.
- * @see org.apache.velocity.tools.generic.NumberTool
- * @see VelocityView#setNumberToolAttribute
- */
- public void setNumberToolAttribute(String numberToolAttribute) {
- this.numberToolAttribute = numberToolAttribute;
- }
-
- /**
- * Set a Velocity Toolbox config location, for example "/WEB-INF/toolbox.xml",
- * to automatically load a Velocity Tools toolbox definition file and expose
- * all defined tools in the specified scopes. If no config location is
- * specified, no toolbox will be loaded and exposed.
- * The specified location string needs to refer to a ServletContext
- * resource, as expected by ServletToolboxManager which is part of
- * the view package of Velocity Tools.
- * Note: Specifying a toolbox config location will lead to
- * VelocityToolboxView instances being created.
- * @see org.apache.velocity.tools.view.servlet.ServletToolboxManager#getInstance
- * @see VelocityToolboxView#setToolboxConfigLocation
- */
- public void setToolboxConfigLocation(String toolboxConfigLocation) {
- this.toolboxConfigLocation = toolboxConfigLocation;
- }
-
-
- @Override
- protected void initApplicationContext() {
- super.initApplicationContext();
-
- if (this.toolboxConfigLocation != null) {
- if (VelocityView.class == getViewClass()) {
- logger.info("Using VelocityToolboxView instead of default VelocityView " +
- "due to specified toolboxConfigLocation");
- setViewClass(VelocityToolboxView.class);
- }
- else if (!VelocityToolboxView.class.isAssignableFrom(getViewClass())) {
- throw new IllegalArgumentException(
- "Given view class [" + getViewClass().getName() +
- "] is not of type [" + VelocityToolboxView.class.getName() +
- "], which it needs to be in case of a specified toolboxConfigLocation");
- }
- }
- }
-
-
- @Override
- protected AbstractUrlBasedView buildView(String viewName) throws Exception {
- VelocityView view = (VelocityView) super.buildView(viewName);
- view.setDateToolAttribute(this.dateToolAttribute);
- view.setNumberToolAttribute(this.numberToolAttribute);
- if (this.toolboxConfigLocation != null) {
- ((VelocityToolboxView) view).setToolboxConfigLocation(this.toolboxConfigLocation);
- }
- return view;
- }
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/package-info.java
deleted file mode 100644
index e6fbf81b51c..00000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/velocity/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * Support classes for the integration of
- * Velocity
- * as Spring web view technology.
- * Contains a View implementation for Velocity templates.
- */
-package org.springframework.web.servlet.view.velocity;
diff --git a/spring-webmvc/src/main/resources/org/springframework/web/servlet/view/velocity/spring.vm b/spring-webmvc/src/main/resources/org/springframework/web/servlet/view/velocity/spring.vm
deleted file mode 100644
index 8ae5fe2aa61..00000000000
--- a/spring-webmvc/src/main/resources/org/springframework/web/servlet/view/velocity/spring.vm
+++ /dev/null
@@ -1,320 +0,0 @@
-#**
- * spring.vm
- *
- * This file consists of a collection of Velocity macros aimed at easing
- * some of the common requirements of web applications - in particular
- * handling of forms.
- *
- * Spring's Velocity support will automatically make this file and therefore
- * all macros within it available to any application using Spring's
- * VelocityConfigurer.
- *
- * To take advantage of these macros, the "exposeSpringMacroHelpers" property
- * of the VelocityView class needs to be set to "true". This will expose a
- * RequestContext under the name "springMacroRequestContext", as needed by
- * the macros in this library.
- *
- * @author Darren Davison
- * @author Juergen Hoeller
- * @since 1.1
- *#
-
-#**
- * springMessage
- *
- * Macro to translate a message code into a message.
- *#
-#macro( springMessage $code )$springMacroRequestContext.getMessage($code)#end
-
-#**
- * springMessageText
- *
- * Macro to translate a message code into a message,
- * using the given default text if no message found.
- *#
-#macro( springMessageText $code $text )$springMacroRequestContext.getMessage($code, $text)#end
-
-#**
- * springTheme
- *
- * Macro to translate a theme message code into a string.
- *#
-#macro( springTheme $code )$springMacroRequestContext.getThemeMessage($code)#end
-
-#**
- * springThemeText
- *
- * Macro to translate a theme message code into a string,
- * using the given default text if no message found.
- *#
-#macro( springThemeText $code $text )$springMacroRequestContext.getThemeMessage($code, $text)#end
-
-#**
- * springUrl
- *
- * Takes a relative URL and makes it absolute from the server root by
- * adding the context root for the web application.
- *#
-#macro( springUrl $relativeUrl )$springMacroRequestContext.getContextUrl(${relativeUrl})#end
-
-#**
- * springBind
- *
- * Exposes a BindStatus object for the given bind path, which can be
- * a bean (e.g. "person") to get global errors, or a bean property
- * (e.g. "person.name") to get field errors. Can be called multiple times
- * within a form to bind to multiple command objects and/or field names.
- *
- * This macro will participate in the default HTML escape setting for the given
- * RequestContext. This can be customized by calling "setDefaultHtmlEscape"
- * on the "springMacroRequestContext" context variable, or via the
- * "defaultHtmlEscape" context-param in web.xml (same as for the JSP bind tag).
- * Also regards a "springHtmlEscape" variable in the template context.
- *
- * Producing no output, the following context variable will be available
- * each time this macro is referenced:
- *
- * $status : a BindStatus instance holding the command object name,
- * expression, value, and error codes and messages for the path supplied
- *
- * @param $path : the path (string value) of the value required to bind to.
- * Spring defaults to a command name of "command" but this can be overridden
- * by user config.
- *#
-#macro( springBind $path )
- #if("$!springHtmlEscape"!="")
- #set( $status = $springMacroRequestContext.getBindStatus($path, $springHtmlEscape) )
- #else
- #set( $status = $springMacroRequestContext.getBindStatus($path) )
- #end
-#end
-
-#**
- * springBindEscaped
- *
- * Similar to springBind, but takes an explicit HTML escape flag rather
- * than relying on the default HTML escape setting.
- *#
-#macro( springBindEscaped $path $htmlEscape )
- #set( $status = $springMacroRequestContext.getBindStatus($path, $htmlEscape) )
-#end
-
-#**
- * springFormInput
- *
- * Display a form input field of type 'text' and bind it to an attribute
- * of a command or bean.
- *
- * @param path the name of the field to bind to
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
- *
- *#
-#macro( springFormInput $path $attributes )
- #springBind($path)
-
-$!status.value
-#end
-
-#**
- * springFormSingleSelect
- *
- * Show a selectbox (dropdown) input element allowing a single value to be chosen
- * from a list of options.
- *
- * The null check for $status.value leverages Velocity's 'quiet' notation rather
- * than the more common #if($status.value) since this method evaluates to the
- * boolean 'false' if the content of $status.value is the String "false" - not
- * what we want.
- *
- * @param path the name of the field to bind to
- * @param options a map (value=label) of all the available options
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
-*#
-#macro( springFormSingleSelect $path $options $attributes )
- #springBind($path)
-
-#end
-
-#**
- * springFormMultiSelect
- *
- * Show a listbox of options allowing the user to make 0 or more choices from
- * the list of options.
- *
- * @param path the name of the field to bind to
- * @param options a map (value=label) of all the available options
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
-*#
-#macro( springFormMultiSelect $path $options $attributes )
- #springBind($path)
-
-#end
-
-#**
- * springFormRadioButtons
- *
- * Show radio buttons.
- *
- * @param path the name of the field to bind to
- * @param options a map (value=label) of all the available options
- * @param separator the html tag or other character list that should be used to
- * separate each option. Typically ' ' or ' <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
- * <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
- * </bean>
- *
- * See the base class VelocityEngineFactory for configuration details.
- *
- * @author Juergen Hoeller
- * @see #setConfigLocation
- * @see #setVelocityProperties
- * @see #setResourceLoaderPath
- * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityEngineFactoryBean extends VelocityEngineFactory
- implements FactoryBean
- * <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
- * <property name="resourceLoaderPath"><value>/WEB-INF/velocity/</value></property>
- * </bean>
- *
- * This bean must be included in the application context of any application
- * using Spring's {@link VelocityView} for web MVC. It exists purely to configure
- * Velocity; it is not meant to be referenced by application components (just
- * internally by VelocityView). This class implements {@link VelocityConfig}
- * in order to be found by VelocityView without depending on the bean name of
- * this configurer. Each DispatcherServlet may define its own VelocityConfigurer
- * if desired, potentially with different template loader paths.
- *
- *
- * #springBind("person.age")
- * age is ${status.value}
- *
- * @author Rod Johnson
- * @author Juergen Hoeller
- * @author Darren Davison
- * @see #setConfigLocation
- * @see #setVelocityProperties
- * @see #setResourceLoaderPath
- * @see #setVelocityEngine
- * @see VelocityView
- * @deprecated as of Spring 4.3, in favor of FreeMarker
- */
-@Deprecated
-public class VelocityConfigurer extends org.springframework.ui.velocity.VelocityEngineFactory
- implements VelocityConfig, InitializingBean, ResourceLoaderAware, ServletContextAware {
-
- /** the name of the resource loader for Spring's bind macros */
- private static final String SPRING_MACRO_RESOURCE_LOADER_NAME = "springMacro";
-
- /** the key for the class of Spring's bind macro resource loader */
- private static final String SPRING_MACRO_RESOURCE_LOADER_CLASS = "springMacro.resource.loader.class";
-
- /** the name of Spring's default bind macro library */
- private static final String SPRING_MACRO_LIBRARY = "org/springframework/web/servlet/view/velocity/spring.vm";
-
-
- private VelocityEngine velocityEngine;
-
- private ServletContext servletContext;
-
-
- /**
- * Set a pre-configured VelocityEngine to use for the Velocity web
- * configuration: e.g. a shared one for web and email usage, set up via
- * {@link org.springframework.ui.velocity.VelocityEngineFactoryBean}.
- *
- * {@code #set($layout = "MyLayout.vm" )}
- *
- * {@code #set($layout = "MyLayout.vm" )}
- *
- *
- *
- *
'
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
-*#
-#macro( springFormRadioButtons $path $options $separator $attributes )
- #springBind($path)
- #foreach($option in $options.keySet())
- '.
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
-*#
-#macro( springFormCheckboxes $path $options $separator $attributes )
- #springBind($path)
- #foreach($option in $options.keySet())
-
-#end
-
-#**
- * springFormCheckbox
- *
- * Show a single checkbox.
- *
- * @param path the name of the field to bind to
- * @param attributes any additional attributes for the element (such as class
- * or CSS styles or size)
-*#
-#macro( springFormCheckbox $path $attributes )
- #springBind($path)
-
-
-#end
-
-#**
- * springShowErrors
- *
- * Show validation errors for the currently bound field, with
- * optional style attributes.
- *
- * @param separator the html tag or other character list that should be used to
- * separate each option. Typically '
'.
- * @param classOrStyle either the name of a CSS class element (which is defined in
- * the template or an external CSS file) or an inline style. If the value passed in here
- * contains a colon (:) then a 'style=' attribute will be used, else a 'class=' attribute
- * will be used.
-*#
-#macro( springShowErrors $separator $classOrStyle )
- #foreach($error in $status.errorMessages)
- #if($classOrStyle=="")
- ${error}
- #else
- #if($classOrStyle.indexOf(":")==-1)
- #set($attr="class")
- #else
- #set($attr="style")
- #end
- ${error}
- #end
- ${separator}
- #end
-#end
-
-#**
- * springCloseTag
- *
- * Simple macro to close an HTML tag that has no body with '>' or '/>',
- * depending on the value of a 'springXhtmlCompliant' variable in the
- * template context.
- *#
-#macro( springCloseTag )#if($springXhtmlCompliant)/>#else>#end#end
-
-#macro( springXmlId $id)#if($id)$id.replaceAll("\[","").replaceAll("\]","")#else$id#end#end
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java
index 859bf4eb27b..98fbffff405 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -141,8 +141,6 @@ import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;
import org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
-import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
-import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
import org.springframework.web.util.UrlPathHelper;
import static org.hamcrest.CoreMatchers.*;
@@ -742,11 +740,11 @@ public class MvcNamespaceTests {
@Test
public void testViewResolution() throws Exception {
- loadBeanDefinitions("mvc-config-view-resolution.xml", 7);
+ loadBeanDefinitions("mvc-config-view-resolution.xml", 6);
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
assertNotNull(compositeResolver);
- assertEquals("Actual: " + compositeResolver.getViewResolvers(), 9, compositeResolver.getViewResolvers().size());
+ assertEquals("Actual: " + compositeResolver.getViewResolvers(), 8, compositeResolver.getViewResolvers().size());
assertEquals(Ordered.LOWEST_PRECEDENCE, compositeResolver.getOrder());
List