|
|
|
@ -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"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with 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 |
|
|
|
* Merge the specified Velocity template with the given model and write |
|
|
|
* the result to the given Writer. |
|
|
|
* the result to the given Writer. |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param templateLocation the location of template, relative to Velocity's |
|
|
|
* @param templateLocation the location of template, relative to Velocity's resource loader path |
|
|
|
* resource loader path |
|
|
|
* @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 |
|
|
|
* @param writer the Writer to write the result to |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @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( |
|
|
|
public static void mergeTemplate( |
|
|
|
VelocityEngine velocityEngine, String templateLocation, Map model, Writer writer) |
|
|
|
VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model, Writer writer) |
|
|
|
throws VelocityException { |
|
|
|
throws VelocityException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -70,20 +71,18 @@ public abstract class VelocityEngineUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Merge the specified Velocity template with the given model and write |
|
|
|
* Merge the specified Velocity template with the given model and write the result |
|
|
|
* the result to the given Writer. |
|
|
|
* to the given Writer. |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param templateLocation the location of template, relative to Velocity's |
|
|
|
* @param templateLocation the location of template, relative to Velocity's resource loader path |
|
|
|
* resource loader path |
|
|
|
|
|
|
|
* @param encoding the encoding of the template file |
|
|
|
* @param encoding the encoding of the template file |
|
|
|
* @param model the Map that contains model names as keys and model objects |
|
|
|
* @param model the Map that contains model names as keys and model objects as values |
|
|
|
* as values |
|
|
|
|
|
|
|
* @param writer the Writer to write the result to |
|
|
|
* @param writer the Writer to write the result to |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void mergeTemplate( |
|
|
|
public static void mergeTemplate( |
|
|
|
VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer) |
|
|
|
VelocityEngine velocityEngine, String templateLocation, String encoding, |
|
|
|
throws VelocityException { |
|
|
|
Map<String, Object> model, Writer writer) throws VelocityException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
VelocityContext velocityContext = new VelocityContext(model); |
|
|
|
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 |
|
|
|
* <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. |
|
|
|
* mail support, consider wrapping VelocityException in MailPreparationException. |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param templateLocation the location of template, relative to Velocity's |
|
|
|
* @param templateLocation the location of template, relative to Velocity's resource loader path |
|
|
|
* resource loader path |
|
|
|
* @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 |
|
|
|
* @return the result as String |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @see org.springframework.mail.MailPreparationException |
|
|
|
* @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( |
|
|
|
@Deprecated |
|
|
|
VelocityEngine velocityEngine, String templateLocation, Map model) |
|
|
|
public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, |
|
|
|
throws VelocityException { |
|
|
|
Map<String, Object> model) throws VelocityException { |
|
|
|
|
|
|
|
|
|
|
|
StringWriter result = new StringWriter(); |
|
|
|
StringWriter result = new StringWriter(); |
|
|
|
mergeTemplate(velocityEngine, templateLocation, model, result); |
|
|
|
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 |
|
|
|
* <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. |
|
|
|
* mail support, consider wrapping VelocityException in MailPreparationException. |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param velocityEngine VelocityEngine to work with |
|
|
|
* @param templateLocation the location of template, relative to Velocity's |
|
|
|
* @param templateLocation the location of template, relative to Velocity's resource loader path |
|
|
|
* resource loader path |
|
|
|
|
|
|
|
* @param encoding the encoding of the template file |
|
|
|
* @param encoding the encoding of the template file |
|
|
|
* @param model the Map that contains model names as keys and model objects |
|
|
|
* @param model the Map that contains model names as keys and model objects as values |
|
|
|
* as values |
|
|
|
|
|
|
|
* @return the result as String |
|
|
|
* @return the result as String |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @throws VelocityException if the template wasn't found or rendering failed |
|
|
|
* @see org.springframework.mail.MailPreparationException |
|
|
|
* @see org.springframework.mail.MailPreparationException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static String mergeTemplateIntoString( |
|
|
|
public static String mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, |
|
|
|
VelocityEngine velocityEngine, String templateLocation, String encoding, Map model) |
|
|
|
String encoding, Map<String, Object> model) throws VelocityException { |
|
|
|
throws VelocityException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringWriter result = new StringWriter(); |
|
|
|
StringWriter result = new StringWriter(); |
|
|
|
mergeTemplate(velocityEngine, templateLocation, encoding, model, result); |
|
|
|
mergeTemplate(velocityEngine, templateLocation, encoding, model, result); |
|
|
|
|