Velocity 1.6 oriented updates to Spring's Velocity support
This commit is contained in:
parent
48f405e8fd
commit
89fc6acba8
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* 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.
|
||||
|
@ -26,10 +26,16 @@ import org.apache.velocity.runtime.log.LogSystem;
|
|||
* Velocity LogSystem implementation for Jakarta Commons Logging.
|
||||
* Used by VelocityConfigurer to redirect log output.
|
||||
*
|
||||
* <p><b>NOTE:</b> To be replaced by Velocity 1.5's <code>LogChute</code> mechanism
|
||||
* and Velocity 1.6's <code>CommonsLogLogChute</code> implementation once we
|
||||
* upgrade to Velocity 1.6+ (likely Velocity 1.7+) in a future version of Spring.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 07.08.2003
|
||||
* @see VelocityEngineFactoryBean
|
||||
* @deprecated as of Spring 3.2, in favor of Velocity 1.6's <code>CommonsLogLogChute</code>
|
||||
*/
|
||||
@Deprecated
|
||||
public class CommonsLoggingLogSystem implements LogSystem {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(VelocityEngine.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
|
@ -99,9 +99,9 @@ public class SpringResourceLoader extends ResourceLoader {
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Looking for Velocity resource with name [" + source + "]");
|
||||
}
|
||||
for (int i = 0; i < this.resourceLoaderPaths.length; i++) {
|
||||
for (String resourceLoaderPath : this.resourceLoaderPaths) {
|
||||
org.springframework.core.io.Resource resource =
|
||||
this.resourceLoader.getResource(this.resourceLoaderPaths[i] + source);
|
||||
this.resourceLoader.getResource(resourceLoaderPath + source);
|
||||
try {
|
||||
return resource.getInputStream();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
|
@ -42,15 +42,16 @@ public abstract class VelocityEngineUtils {
|
|||
* Merge the specified Velocity template with the given model and write
|
||||
* the result to the given Writer.
|
||||
* @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
|
||||
* @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
|
||||
* @param writer the Writer to write the result to
|
||||
* @throws VelocityException if the template wasn't found or rendering failed
|
||||
* @deprecated Use {@link #mergeTemplate(VelocityEngine, String, String, Map, Writer)}
|
||||
* instead, following Velocity 1.6's corresponding deprecation in its own API.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void mergeTemplate(
|
||||
VelocityEngine velocityEngine, String templateLocation, Map model, Writer writer)
|
||||
VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model, Writer writer)
|
||||
throws VelocityException {
|
||||
|
||||
try {
|
||||
|
@ -70,20 +71,18 @@ public abstract class VelocityEngineUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Merge the specified Velocity template with the given model and write
|
||||
* the result to the given Writer.
|
||||
* Merge the specified Velocity template with the given model and write the result
|
||||
* to the given Writer.
|
||||
* @param velocityEngine VelocityEngine to work with
|
||||
* @param templateLocation the location of template, relative to Velocity's
|
||||
* resource loader path
|
||||
* @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
|
||||
* @param model the Map that contains model names as keys and model objects as values
|
||||
* @param writer the Writer to write the result to
|
||||
* @throws VelocityException if the template wasn't found or rendering failed
|
||||
*/
|
||||
public static void mergeTemplate(
|
||||
VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer)
|
||||
throws VelocityException {
|
||||
VelocityEngine velocityEngine, String templateLocation, String encoding,
|
||||
Map<String, Object> model, Writer writer) throws VelocityException {
|
||||
|
||||
try {
|
||||
VelocityContext velocityContext = new VelocityContext(model);
|
||||
|
@ -106,17 +105,17 @@ public abstract class VelocityEngineUtils {
|
|||
* <p>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
|
||||
* @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.
|
||||
*/
|
||||
public static String mergeTemplateIntoString(
|
||||
VelocityEngine velocityEngine, String templateLocation, Map model)
|
||||
throws VelocityException {
|
||||
@Deprecated
|
||||
public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation,
|
||||
Map<String, Object> model) throws VelocityException {
|
||||
|
||||
StringWriter result = new StringWriter();
|
||||
mergeTemplate(velocityEngine, templateLocation, model, result);
|
||||
|
@ -128,18 +127,15 @@ public abstract class VelocityEngineUtils {
|
|||
* <p>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 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
|
||||
* @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 model)
|
||||
throws VelocityException {
|
||||
public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation,
|
||||
String encoding, Map<String, Object> model) throws VelocityException {
|
||||
|
||||
StringWriter result = new StringWriter();
|
||||
mergeTemplate(velocityEngine, templateLocation, encoding, model, result);
|
||||
|
|
Loading…
Reference in New Issue