This is an automated email from the ASF dual-hosted git repository.
cbrisson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-engine.git
The following commit(s) were added to refs/heads/master by this push:
new 08211a61 Normalize some tab-indented source files
08211a61 is described below
commit 08211a616416ed98dda139ebed477302ca732e10
Author: Claude Brisson <[email protected]>
AuthorDate: Fri Aug 23 09:42:47 2024 +0200
Normalize some tab-indented source files
---
.../velocity/spring/SpringResourceLoader.java | 168 +++----
.../velocity/spring/VelocityEngineFactory.java | 530 ++++++++++-----------
.../velocity/spring/VelocityEngineFactoryBean.java | 36 +-
.../velocity/spring/VelocityEngineUtils.java | 138 +++---
.../test/VelocityEngineFactoryBeanTests.java | 60 +--
.../spring/test/VelocityEngineFactoryTests.java | 58 +--
.../exception/MethodInvocationException.java | 6 +-
.../org/apache/velocity/io/VelocityWriter.java | 2 +-
.../velocity/runtime/parser/node/ASTDirective.java | 4 +-
.../runtime/parser/node/ASTStringLiteral.java | 14 +-
.../runtime/resource/ResourceCacheImpl.java | 52 +-
.../util/StringResourceRepositoryImpl.java | 4 +-
.../velocity/util/introspection/ClassFieldMap.java | 10 +-
.../velocity/util/introspection/ClassMap.java | 28 +-
.../util/introspection/IntrospectorBase.java | 2 +-
.../src/test/java/classloader/Foo.java | 8 +-
.../velocity/test/ClassloaderChangeTestCase.java | 2 +-
.../test/FilteredEventHandlingTestCase.java | 2 +-
.../velocity/test/Introspector2TestCase.java | 2 +-
.../velocity/test/MacroForwardDefineTestCase.java | 2 +-
.../velocity/test/OldPropertiesTestCase.java | 2 +-
.../org/apache/velocity/test/TestBaseTestCase.java | 2 +-
.../test/sql/DataSourceResourceLoaderTestCase.java | 16 +-
.../introspection/ChainedUberspectorsTestCase.java | 2 +-
.../test/util/introspection/ClassMapTestCase.java | 2 +-
.../velocity/script/VelocityScriptEngine.java | 6 +-
26 files changed, 579 insertions(+), 579 deletions(-)
diff --git
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/SpringResourceLoader.java
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/SpringResourceLoader.java
index befe4c5b..62ab8aa0 100644
---
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/SpringResourceLoader.java
+++
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/SpringResourceLoader.java
@@ -52,89 +52,89 @@ import org.springframework.util.StringUtils;
*/
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 Logger logger = LoggerFactory.getLogger(getClass());
-
- private org.springframework.core.io.ResourceLoader resourceLoader;
-
- private String[] resourceLoaderPaths;
-
-
- @Override
- public void init(ExtProperties 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));
- }
- }
-
- /**
- * Get the Reader that the Runtime will parse
- * to create a template.
- *
- * @param source resource name
- * @param encoding resource encoding
- * @return The reader for the requested resource.
- * @throws ResourceNotFoundException
- * @since 2.0
- */
- @Override
- public Reader getResourceReader(String source, String encoding) 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 new
InputStreamReader(resource.getInputStream(), encoding);
- }
- 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;
- }
+ 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 Logger logger = LoggerFactory.getLogger(getClass());
+
+ private org.springframework.core.io.ResourceLoader resourceLoader;
+
+ private String[] resourceLoaderPaths;
+
+
+ @Override
+ public void init(ExtProperties 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));
+ }
+ }
+
+ /**
+ * Get the Reader that the Runtime will parse
+ * to create a template.
+ *
+ * @param source resource name
+ * @param encoding resource encoding
+ * @return The reader for the requested resource.
+ * @throws ResourceNotFoundException
+ * @since 2.0
+ */
+ @Override
+ public Reader getResourceReader(String source, String encoding) 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 new InputStreamReader(resource.getInputStream(),
encoding);
+ }
+ 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-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactory.java
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactory.java
index b1c062da..c38590b0 100644
---
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactory.java
+++
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactory.java
@@ -68,270 +68,270 @@ import org.springframework.util.StringUtils;
*/
public class VelocityEngineFactory {
- protected static final Logger logger =
LoggerFactory.getLogger(VelocityEngineFactory.class);
-
- private Resource configLocation;
-
- private final Map<String, Object> velocityProperties = new
HashMap<String, Object>();
-
- private String resourceLoaderPath;
-
- private ResourceLoader resourceLoader = new DefaultResourceLoader();
-
- private boolean preferFileSystemAccess = true;
-
- private boolean overrideLogging = true;
-
-
- /**
- * Set the location of the Velocity config file.
- * Alternatively, you can specify all properties locally.
- * @see #setVelocityProperties
- * @see #setResourceLoaderPath
- */
- public void setConfigLocation(Resource configLocation) {
- this.configLocation = configLocation;
- }
-
- /**
- * Set Velocity properties, like "file.resource.loader.path".
- * Can be used to override values in a Velocity config file,
- * or to specify all necessary properties locally.
- * <p>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<String, Object>
velocityPropertiesMap) {
- if (velocityPropertiesMap != null) {
- this.velocityProperties.putAll(velocityPropertiesMap);
- }
- }
-
- /**
- * Set the Velocity resource loader path via a Spring resource location.
- * Accepts multiple locations in Velocity's comma-separated path style.
- * <p>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.
- * <p>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.
- * <p>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).
- * <p>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.
- * <p>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.
- * <p>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).
- * <p>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;
- }
-
- /**
- * 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<String, Object> props = new HashMap<String, Object>();
-
- // Load config file if set.
- if (this.configLocation != null) {
- if (logger.isInfoEnabled()) {
- logger.info("Loading Velocity config from [" +
this.configLocation + "]");
- }
-
CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation),
props);
- }
-
- // Merge local properties if set.
- if (!this.velocityProperties.isEmpty()) {
- props.putAll(this.velocityProperties);
- }
-
- // Set a resource loader path, if required.
- if (this.resourceLoaderPath != null) {
- initVelocityResourceLoader(velocityEngine,
this.resourceLoaderPath);
- }
-
- // Apply properties to VelocityEngine.
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- velocityEngine.setProperty(entry.getKey(),
entry.getValue());
- }
-
- postProcessVelocityEngine(velocityEngine);
-
- // Perform actual initialization.
- velocityEngine.init();
-
- return velocityEngine;
- }
-
- /**
- * Return a new VelocityEngine. Subclasses can override this for
- * custom initialization, or for using a mock object for testing.
- * <p>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.
- * <p>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_LOADERS, "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.
- * <p>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_LOADERS,
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).
- * <p>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 {
- }
+ protected static final Logger logger =
LoggerFactory.getLogger(VelocityEngineFactory.class);
+
+ private Resource configLocation;
+
+ private final Map<String, Object> velocityProperties = new HashMap<String,
Object>();
+
+ private String resourceLoaderPath;
+
+ private ResourceLoader resourceLoader = new DefaultResourceLoader();
+
+ private boolean preferFileSystemAccess = true;
+
+ private boolean overrideLogging = true;
+
+
+ /**
+ * Set the location of the Velocity config file.
+ * Alternatively, you can specify all properties locally.
+ * @see #setVelocityProperties
+ * @see #setResourceLoaderPath
+ */
+ public void setConfigLocation(Resource configLocation) {
+ this.configLocation = configLocation;
+ }
+
+ /**
+ * Set Velocity properties, like "file.resource.loader.path".
+ * Can be used to override values in a Velocity config file,
+ * or to specify all necessary properties locally.
+ * <p>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<String, Object>
velocityPropertiesMap) {
+ if (velocityPropertiesMap != null) {
+ this.velocityProperties.putAll(velocityPropertiesMap);
+ }
+ }
+
+ /**
+ * Set the Velocity resource loader path via a Spring resource location.
+ * Accepts multiple locations in Velocity's comma-separated path style.
+ * <p>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.
+ * <p>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.
+ * <p>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).
+ * <p>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.
+ * <p>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.
+ * <p>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).
+ * <p>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;
+ }
+
+ /**
+ * 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<String, Object> props = new HashMap<String, Object>();
+
+ // Load config file if set.
+ if (this.configLocation != null) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Loading Velocity config from [" +
this.configLocation + "]");
+ }
+
CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation),
props);
+ }
+
+ // Merge local properties if set.
+ if (!this.velocityProperties.isEmpty()) {
+ props.putAll(this.velocityProperties);
+ }
+
+ // Set a resource loader path, if required.
+ if (this.resourceLoaderPath != null) {
+ initVelocityResourceLoader(velocityEngine,
this.resourceLoaderPath);
+ }
+
+ // Apply properties to VelocityEngine.
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ velocityEngine.setProperty(entry.getKey(), entry.getValue());
+ }
+
+ postProcessVelocityEngine(velocityEngine);
+
+ // Perform actual initialization.
+ velocityEngine.init();
+
+ return velocityEngine;
+ }
+
+ /**
+ * Return a new VelocityEngine. Subclasses can override this for
+ * custom initialization, or for using a mock object for testing.
+ * <p>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.
+ * <p>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_LOADERS, "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.
+ * <p>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_LOADERS,
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).
+ * <p>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-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactoryBean.java
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactoryBean.java
index 78299ab1..b84d9987 100644
---
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactoryBean.java
+++
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineFactoryBean.java
@@ -50,30 +50,30 @@ import org.springframework.context.ResourceLoaderAware;
* @see <a
href="https://docs.spring.io/spring-framework/docs/4.3.29.RELEASE/javadoc-api/org/springframework/web/servlet/view/velocity/VelocityConfigurer.html">org.springframework.web.servlet.view.velocity.VelocityConfigurer</a>
*/
public class VelocityEngineFactoryBean extends VelocityEngineFactory
- implements FactoryBean<VelocityEngine>, InitializingBean,
ResourceLoaderAware {
+ implements FactoryBean<VelocityEngine>, InitializingBean,
ResourceLoaderAware {
- private VelocityEngine velocityEngine;
+ private VelocityEngine velocityEngine;
- @Override
- public void afterPropertiesSet() throws IOException, VelocityException {
- this.velocityEngine = createVelocityEngine();
- }
+ @Override
+ public void afterPropertiesSet() throws IOException, VelocityException {
+ this.velocityEngine = createVelocityEngine();
+ }
- @Override
- public VelocityEngine getObject() {
- return this.velocityEngine;
- }
+ @Override
+ public VelocityEngine getObject() {
+ return this.velocityEngine;
+ }
- @Override
- public Class<? extends VelocityEngine> getObjectType() {
- return VelocityEngine.class;
- }
+ @Override
+ public Class<? extends VelocityEngine> getObjectType() {
+ return VelocityEngine.class;
+ }
- @Override
- public boolean isSingleton() {
- return true;
- }
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
}
diff --git
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineUtils.java
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineUtils.java
index 7e0be723..dba34108 100644
---
a/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineUtils.java
+++
b/spring-velocity-support/src/main/java/org/apache/velocity/spring/VelocityEngineUtils.java
@@ -34,79 +34,79 @@ import org.apache.velocity.exception.VelocityException;
*/
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 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<String, Object> model, Writer writer)
- throws VelocityException {
- mergeTemplate(velocityEngine, templateLocation, null, 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 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<String, Object> model, Writer writer)
+ throws VelocityException {
+ mergeTemplate(velocityEngine, templateLocation, null, 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 encoding the encoding of the template file
- * @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<String, Object> model, Writer writer) throws
VelocityException {
+ /**
+ * 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 encoding the encoding of the template file
+ * @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<String, Object> model, Writer writer) throws
VelocityException {
- VelocityContext velocityContext = new VelocityContext(model);
- velocityEngine.mergeTemplate(templateLocation, encoding,
velocityContext, writer);
- }
+ VelocityContext velocityContext = new VelocityContext(model);
+ velocityEngine.mergeTemplate(templateLocation, encoding,
velocityContext, writer);
+ }
- /**
- * Merge the specified Velocity template with the given model into a
String.
- * <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
- * @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<String, Object> model) throws VelocityException {
- return mergeTemplateIntoString(velocityEngine,
templateLocation, null, model);
- }
+ /**
+ * Merge the specified Velocity template with the given model into a
String.
+ * <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
+ * @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<String, Object> model) throws VelocityException {
+ return mergeTemplateIntoString(velocityEngine, templateLocation, null,
model);
+ }
- /**
- * Merge the specified Velocity template with the given model into a
String.
- * <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 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<String, Object> model) throws
VelocityException {
+ /**
+ * Merge the specified Velocity template with the given model into a
String.
+ * <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 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<String, Object> model) throws
VelocityException {
- StringWriter result = new StringWriter();
- mergeTemplate(velocityEngine, templateLocation, encoding,
model, result);
- return result.toString();
- }
+ StringWriter result = new StringWriter();
+ mergeTemplate(velocityEngine, templateLocation, encoding, model,
result);
+ return result.toString();
+ }
}
diff --git
a/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryBeanTests.java
b/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryBeanTests.java
index 97fdfd75..ad814ca0 100644
---
a/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryBeanTests.java
+++
b/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryBeanTests.java
@@ -37,38 +37,38 @@ import static org.junit.Assert.assertEquals;
*/
public class VelocityEngineFactoryBeanTests
{
- private static final String resourcesPath =
System.getProperty("test.resources.dir");
- private final VelocityEngineFactoryBean vefb = new
VelocityEngineFactoryBean();
+ private static final String resourcesPath =
System.getProperty("test.resources.dir");
+ private final VelocityEngineFactoryBean vefb = new
VelocityEngineFactoryBean();
- @Test
- public void velocityFactoryBeanWithConfigLocation() throws Exception {
- vefb.setConfigLocation(new
ClassPathResource("velocity.properties"));
- vefb.afterPropertiesSet();
- VelocityEngine engine = vefb.getObject();
- assertEquals("bean config location failed", "bar",
engine.getProperty("foo"));
- }
+ @Test
+ public void velocityFactoryBeanWithConfigLocation() throws Exception {
+ vefb.setConfigLocation(new ClassPathResource("velocity.properties"));
+ vefb.afterPropertiesSet();
+ VelocityEngine engine = vefb.getObject();
+ assertEquals("bean config location failed", "bar",
engine.getProperty("foo"));
+ }
- @Test
- public void velocityFactoryBeanWithResourceLoaderPath() throws
Exception {
- vefb.setResourceLoaderPath("file:" + resourcesPath);
- vefb.afterPropertiesSet();
- VelocityEngine engine = vefb.getObject();
- Map<String, Object> model = new HashMap<String, Object>();
- model.put("foo", "bar");
- String merged =
VelocityEngineUtils.mergeTemplateIntoString(engine, "simple.vm", "utf-8",
model).trim();
- assertEquals("resource loader failed", "foo=bar", merged);
- }
+ @Test
+ public void velocityFactoryBeanWithResourceLoaderPath() throws Exception {
+ vefb.setResourceLoaderPath("file:" + resourcesPath);
+ vefb.afterPropertiesSet();
+ VelocityEngine engine = vefb.getObject();
+ Map<String, Object> model = new HashMap<String, Object>();
+ model.put("foo", "bar");
+ String merged = VelocityEngineUtils.mergeTemplateIntoString(engine,
"simple.vm", "utf-8", model).trim();
+ assertEquals("resource loader failed", "foo=bar", merged);
+ }
- @Test // SPR-12448
- public void velocityConfigurationAsBean() {
- DefaultListableBeanFactory beanFactory = new
DefaultListableBeanFactory();
- RootBeanDefinition loaderDef = new
RootBeanDefinition(SpringResourceLoader.class);
-
loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new
DefaultResourceLoader());
-
loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
- // RootBeanDefinition configDef = new
RootBeanDefinition(Configuration.class);
- //configDef.getPropertyValues().add("templateLoader",
loaderDef);
- //beanFactory.registerBeanDefinition("freeMarkerConfig",
configDef);
- //
assertThat(beanFactory.getBean(Configuration.class)).isNotNull();
- }
+ @Test // SPR-12448
+ public void velocityConfigurationAsBean() {
+ DefaultListableBeanFactory beanFactory = new
DefaultListableBeanFactory();
+ RootBeanDefinition loaderDef = new
RootBeanDefinition(SpringResourceLoader.class);
+ loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new
DefaultResourceLoader());
+
loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
+ // RootBeanDefinition configDef = new
RootBeanDefinition(Configuration.class);
+ //configDef.getPropertyValues().add("templateLoader", loaderDef);
+ //beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
+ // assertThat(beanFactory.getBean(Configuration.class)).isNotNull();
+ }
}
diff --git
a/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryTests.java
b/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryTests.java
index 68b440b7..46c0fc83 100644
---
a/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryTests.java
+++
b/spring-velocity-support/src/test/java/org/apache/velocity/spring/test/VelocityEngineFactoryTests.java
@@ -34,37 +34,37 @@ import static org.junit.Assert.assertEquals;
*/
public class VelocityEngineFactoryTests {
- private static final String resourcesPath =
System.getProperty("test.resources.dir");
+ private static final String resourcesPath =
System.getProperty("test.resources.dir");
- @Test
- public void testCreateEngineDefaultFileLoader() throws Exception {
- VelocityEngineFactory factory = new VelocityEngineFactory();
- factory.setResourceLoaderPath("."); // defaults to
target/test-classes file resource loading
- VelocityEngine engine = factory.createVelocityEngine();
- Map<String, Object> model = new HashMap<String, Object>();
- model.put("foo", "bar");
- String merged =
VelocityEngineUtils.mergeTemplateIntoString(engine, "simple.vm", "utf-8",
model).trim();
- assertEquals("file loader failed", "foo=bar", merged);
- }
+ @Test
+ public void testCreateEngineDefaultFileLoader() throws Exception {
+ VelocityEngineFactory factory = new VelocityEngineFactory();
+ factory.setResourceLoaderPath("."); // defaults to target/test-classes
file resource loading
+ VelocityEngine engine = factory.createVelocityEngine();
+ Map<String, Object> model = new HashMap<String, Object>();
+ model.put("foo", "bar");
+ String merged = VelocityEngineUtils.mergeTemplateIntoString(engine,
"simple.vm", "utf-8", model).trim();
+ assertEquals("file loader failed", "foo=bar", merged);
+ }
- @Test
- public void testCreateEngineDefaultClasspathLoader() throws Exception {
- VelocityEngineFactory factory = new VelocityEngineFactory();
- factory.setResourceLoaderPath("/"); // defaults to classpath
resource loading
- VelocityEngine engine = factory.createVelocityEngine();
- Map<String, Object> model = new HashMap<String, Object>();
- model.put("foo", "bar");
- String merged =
VelocityEngineUtils.mergeTemplateIntoString(engine, "simple.vm", "utf-8",
model).trim();
- assertEquals("classpath loader failed", "foo=bar", merged);
- }
+ @Test
+ public void testCreateEngineDefaultClasspathLoader() throws Exception {
+ VelocityEngineFactory factory = new VelocityEngineFactory();
+ factory.setResourceLoaderPath("/"); // defaults to classpath resource
loading
+ VelocityEngine engine = factory.createVelocityEngine();
+ Map<String, Object> model = new HashMap<String, Object>();
+ model.put("foo", "bar");
+ String merged = VelocityEngineUtils.mergeTemplateIntoString(engine,
"simple.vm", "utf-8", model).trim();
+ assertEquals("classpath loader failed", "foo=bar", merged);
+ }
- @Test
- public void testCreateEngineCustomConfig() throws Exception {
- VelocityEngineFactory factory = new VelocityEngineFactory();
- factory.setResourceLoaderPath(".");
- factory.setConfigLocation(new
ClassPathResource("/velocity.properties"));
- VelocityEngine engine = factory.createVelocityEngine();
- assertEquals("custom config failed", "bar",
engine.getProperty("foo"));
- }
+ @Test
+ public void testCreateEngineCustomConfig() throws Exception {
+ VelocityEngineFactory factory = new VelocityEngineFactory();
+ factory.setResourceLoaderPath(".");
+ factory.setConfigLocation(new
ClassPathResource("/velocity.properties"));
+ VelocityEngine engine = factory.createVelocityEngine();
+ assertEquals("custom config failed", "bar", engine.getProperty("foo"));
+ }
}
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/exception/MethodInvocationException.java
b/velocity-engine-core/src/main/java/org/apache/velocity/exception/MethodInvocationException.java
index a47f6e92..f9720bbc 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/exception/MethodInvocationException.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/exception/MethodInvocationException.java
@@ -129,7 +129,7 @@ public class MethodInvocationException extends
VelocityException implements Exte
@Override
public int getColumnNumber()
{
- return columnNumber;
+ return columnNumber;
}
/**
@@ -139,7 +139,7 @@ public class MethodInvocationException extends
VelocityException implements Exte
@Override
public int getLineNumber()
{
- return lineNumber;
+ return lineNumber;
}
/**
@@ -149,7 +149,7 @@ public class MethodInvocationException extends
VelocityException implements Exte
@Override
public String getTemplateName()
{
- return templateName;
+ return templateName;
}
/**
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/io/VelocityWriter.java
b/velocity-engine-core/src/main/java/org/apache/velocity/io/VelocityWriter.java
index b9419689..1c437f48 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/io/VelocityWriter.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/io/VelocityWriter.java
@@ -209,7 +209,7 @@ public final class VelocityWriter extends Writer implements
Filter
*/
private int min(int a, int b)
{
- return (a < b ? a : b);
+ return (a < b ? a : b);
}
/**
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
index 9d19f218..0cd3c7cd 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
@@ -347,8 +347,8 @@ public class ASTDirective extends SimpleNode
@Override
public String toString()
{
- return "ASTDirective [" + super.toString() + ", directiveName="
- + directiveName + "]";
+ return "ASTDirective [" + super.toString() + ", directiveName="
+ + directiveName + "]";
}
/**
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
index 1131e3d2..c1122d4e 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
@@ -205,9 +205,9 @@ public class ASTStringLiteral extends SimpleNode
/**
* Replaces double double-quotes with a single double quote ("" to ").
* Replaces double single quotes with a single quote ('' to ').
- *
- * @param s StringLiteral without the surrounding quotes
- * @param literalQuoteChar char that starts the StringLiteral (" or ')
+ *
+ * @param s StringLiteral without the surrounding quotes
+ * @param literalQuoteChar char that starts the StringLiteral (" or ')
*/
private String replaceQuotes(String s, char literalQuoteChar)
{
@@ -226,11 +226,11 @@ public class ASTStringLiteral extends SimpleNode
if( i + 1 < is )
{
char next = s.charAt(i + 1);
- // '""' -> "", "''" -> ''
- // thus it is not necessary to double quotes if
the "surrounding" quotes
- // of the StringLiteral are different. See
VELOCITY-785
+ // '""' -> "", "''" -> ''
+ // thus it is not necessary to double quotes if the
"surrounding" quotes
+ // of the StringLiteral are different. See VELOCITY-785
if( (literalQuoteChar == '"' && (next == '"' && c == '"')) ||
- (literalQuoteChar == '\'' && (next == '\''
&& c == '\'')) )
+ (literalQuoteChar == '\'' && (next == '\'' && c ==
'\'')) )
{
i++;
}
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java
index 7ad03518..e89f1464 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java
@@ -48,42 +48,42 @@ import java.util.concurrent.ConcurrentHashMap;
public class ResourceCacheImpl implements ResourceCache
{
- /**
- * A simple LRU Map based on {@link LinkedHashSet}.
- *
- * @param <K> The key type of the map.
- * @param <V> The value type of the map.
- */
- private static class LRUMap<K, V> extends LinkedHashMap<K, V>{
-
- /**
+ /**
+ * A simple LRU Map based on {@link LinkedHashSet}.
+ *
+ * @param <K> The key type of the map.
+ * @param <V> The value type of the map.
+ */
+ private static class LRUMap<K, V> extends LinkedHashMap<K, V>{
+
+ /**
* The serial version uid;
*/
private static final long serialVersionUID = 5889225121697975043L;
- /**
- * The size of the cache.
- */
- private int cacheSize;
-
- /**
- * Constructor.
- *
- * @param cacheSize The size of the cache. After reaching this
size, the
- * eldest-accessed element will be erased.
- */
- public LRUMap(int cacheSize)
+ /**
+ * The size of the cache.
+ */
+ private int cacheSize;
+
+ /**
+ * Constructor.
+ *
+ * @param cacheSize The size of the cache. After reaching this size, the
+ * eldest-accessed element will be erased.
+ */
+ public LRUMap(int cacheSize)
{
- this.cacheSize = cacheSize;
+ this.cacheSize = cacheSize;
}
- /** {@inheritDoc} */
- @Override
+ /** {@inheritDoc} */
+ @Override
protected boolean removeEldestEntry(Entry<K, V> eldest)
{
- return size() > cacheSize;
+ return size() > cacheSize;
}
- }
+ }
/**
* Cache storage, assumed to be thread-safe.
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/util/StringResourceRepositoryImpl.java
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/util/StringResourceRepositoryImpl.java
index fc93602d..aab0ceae 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/util/StringResourceRepositoryImpl.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/util/StringResourceRepositoryImpl.java
@@ -90,7 +90,7 @@ public class StringResourceRepositoryImpl implements
StringResourceRepository
@Override
public String getEncoding()
{
- return encoding;
+ return encoding;
}
/**
@@ -99,6 +99,6 @@ public class StringResourceRepositoryImpl implements
StringResourceRepository
@Override
public void setEncoding(final String encoding)
{
- this.encoding = encoding;
+ this.encoding = encoding;
}
}
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java
index 37d3003a..4765ce51 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java
@@ -111,11 +111,11 @@ public class ClassFieldMap
private Map<String, Field> createFieldCache()
{
Map<String, Field> fieldCache = new ConcurrentHashMap<>();
- //
- // Looks through all elements in the class hierarchy.
- //
- // We ignore all SecurityExceptions that might happen due to
SecurityManager restrictions (prominently
- // hit with Tomcat 5.5).
+ //
+ // Looks through all elements in the class hierarchy.
+ //
+ // We ignore all SecurityExceptions that might happen due to
SecurityManager restrictions (prominently
+ // hit with Tomcat 5.5).
// Ah, the miracles of Java for(;;) ...
for (Class<?> classToReflect = getCachedClass(); classToReflect !=
null ; classToReflect = classToReflect.getSuperclass())
{
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java
index d46f7e1d..e5fe9d7f 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java
@@ -125,19 +125,19 @@ public class ClassMap
private MethodCache createMethodCache(TypeConversionHandler
conversionHandler)
{
MethodCache methodCache = new MethodCache(log, conversionHandler);
- //
- // Looks through all elements in the class hierarchy. This one is
bottom-first (i.e. we start
- // with the actual declaring class and its interfaces and then move up
(superclass etc.) until we
- // hit java.lang.Object. That is important because it will give us the
methods of the declaring class
- // which might in turn be abstract further up the tree.
- //
- // We also ignore all SecurityExceptions that might happen due to
SecurityManager restrictions (prominently
- // hit with Tomcat 5.5).
- //
- // We can also omit all that complicated getPublic, getAccessible and
upcast logic that the class map had up
- // until Velocity 1.4. As we always reflect all elements of the tree
(that's what we have a cache for), we will
- // hit the public elements sooner or later because we reflect all the
public elements anyway.
- //
+ //
+ // Looks through all elements in the class hierarchy. This one is
bottom-first (i.e. we start
+ // with the actual declaring class and its interfaces and then move up
(superclass etc.) until we
+ // hit java.lang.Object. That is important because it will give us the
methods of the declaring class
+ // which might in turn be abstract further up the tree.
+ //
+ // We also ignore all SecurityExceptions that might happen due to
SecurityManager restrictions (prominently
+ // hit with Tomcat 5.5).
+ //
+ // We can also omit all that complicated getPublic, getAccessible and
upcast logic that the class map had up
+ // until Velocity 1.4. As we always reflect all elements of the tree
(that's what we have a cache for), we will
+ // hit the public elements sooner or later because we reflect all the
public elements anyway.
+ //
// Ah, the miracles of Java for(;;) ...
for (Class<?> classToReflect = getCachedClass(); classToReflect !=
null ; classToReflect = classToReflect.getSuperclass())
{
@@ -221,7 +221,7 @@ public class ClassMap
}
/** Class logger */
- private final Logger log;
+ private final Logger log;
/**
* Cache of Methods, or CACHE_MISS, keyed by method
diff --git
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
index bce0d4c9..eca210a6 100644
---
a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
+++
b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectorBase.java
@@ -132,7 +132,7 @@ public abstract class IntrospectorBase
*/
protected IntrospectorCache getIntrospectorCache()
{
- return introspectorCache;
+ return introspectorCache;
}
}
diff --git a/velocity-engine-core/src/test/java/classloader/Foo.java
b/velocity-engine-core/src/test/java/classloader/Foo.java
index 436c780b..dda1ffc8 100644
--- a/velocity-engine-core/src/test/java/classloader/Foo.java
+++ b/velocity-engine-core/src/test/java/classloader/Foo.java
@@ -37,9 +37,9 @@ public class Foo
private static String MSG =
"Hello From Foo";
- public String doIt()
- {
- return MSG;
- }
+ public String doIt()
+ {
+ return MSG;
+ }
}
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/ClassloaderChangeTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/ClassloaderChangeTestCase.java
index 73f7b08d..a6b5bf4f 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/ClassloaderChangeTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/ClassloaderChangeTestCase.java
@@ -40,7 +40,7 @@ import java.io.StringWriter;
public class ClassloaderChangeTestCase extends TestCase
{
private VelocityEngine ve = null;
- private TestLogger logger = null;
+ private TestLogger logger = null;
private static String OUTPUT = "Hello From Foo";
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/FilteredEventHandlingTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/FilteredEventHandlingTestCase.java
index e56fa733..210fbd3a 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/FilteredEventHandlingTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/FilteredEventHandlingTestCase.java
@@ -77,7 +77,7 @@ public class FilteredEventHandlingTestCase extends
BaseTestCase
private static final String COMPARE_DIR = TEST_COMPARE_DIR +
"/includeevent/compare";
- private TestLogger logger = new TestLogger(false, false);
+ private TestLogger logger = new TestLogger(false, false);
/**
* Default constructor.
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/Introspector2TestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/Introspector2TestCase.java
index f97f1c49..91afba0d 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/Introspector2TestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/Introspector2TestCase.java
@@ -60,7 +60,7 @@ public class Introspector2TestCase extends BaseTestCase
throws Exception
{
Velocity.setProperty(
- Velocity.RUNTIME_LOG_INSTANCE, new
TestLogger());
+ Velocity.RUNTIME_LOG_INSTANCE, new
TestLogger());
Velocity.init();
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/MacroForwardDefineTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/MacroForwardDefineTestCase.java
index 5a9fb8da..6e5859e7 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/MacroForwardDefineTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/MacroForwardDefineTestCase.java
@@ -59,7 +59,7 @@ public class MacroForwardDefineTestCase
/**
* Collects the log messages.
*/
- private TestLogger logger = new TestLogger(false, true);
+ private TestLogger logger = new TestLogger(false, true);
/**
* Default constructor.
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/OldPropertiesTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/OldPropertiesTestCase.java
index b0dad04e..ff5a4eb7 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/OldPropertiesTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/OldPropertiesTestCase.java
@@ -47,7 +47,7 @@ import java.util.regex.Pattern;
public class OldPropertiesTestCase extends TestCase implements TemplateTestBase
{
private VelocityEngine ve = null;
- private TestLogger logger = null;
+ private TestLogger logger = null;
/**
* Default constructor.
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/TestBaseTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/TestBaseTestCase.java
index ee4afe7c..c9490ac7 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/TestBaseTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/TestBaseTestCase.java
@@ -44,7 +44,7 @@ public class TestBaseTestCase
throws Exception
{
String fs = System.getProperty("file.separator");
- String pwd = System.getProperty("user.dir");
+ String pwd = System.getProperty("user.dir");
String root = new File("/").getCanonicalPath();
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/sql/DataSourceResourceLoaderTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/sql/DataSourceResourceLoaderTestCase.java
index 757b6e84..8e4caa4d 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/sql/DataSourceResourceLoaderTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/sql/DataSourceResourceLoaderTestCase.java
@@ -217,13 +217,13 @@ public class DataSourceResourceLoaderTestCase
public static final class DSRLTCTool
{
public int add(final int a, final int b)
- {
- return a + b;
- }
-
- public String getMessage()
- {
- return "And the result is:";
- }
+ {
+ return a + b;
+ }
+
+ public String getMessage()
+ {
+ return "And the result is:";
+ }
}
}
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ChainedUberspectorsTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ChainedUberspectorsTestCase.java
index 2687d662..80887cb1 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ChainedUberspectorsTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ChainedUberspectorsTestCase.java
@@ -58,7 +58,7 @@ public class ChainedUberspectorsTestCase extends BaseTestCase
{
Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.util.introspection.UberspectImpl");
Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.test.util.introspection.ChainedUberspectorsTestCase$ChainedUberspector");
Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.test.util.introspection.ChainedUberspectorsTestCase$LinkedUberspector");
- Velocity.init();
+ Velocity.init();
}
@Override
diff --git
a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ClassMapTestCase.java
b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ClassMapTestCase.java
index c4f87dcc..43388032 100644
---
a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ClassMapTestCase.java
+++
b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ClassMapTestCase.java
@@ -49,7 +49,7 @@ public class ClassMapTestCase
throws Exception
{
Velocity.setProperty(Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());
- Velocity.init();
+ Velocity.init();
}
@Override
diff --git
a/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
b/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
index 469ca45d..09a7b475 100644
---
a/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
+++
b/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
@@ -172,10 +172,10 @@ public class VelocityScriptEngine extends
AbstractScriptEngine implements Compil
{
synchronized (this)
{
- if (factory == null)
+ if (factory == null)
{
- factory = new VelocityScriptEngineFactory();
- }
+ factory = new VelocityScriptEngineFactory();
+ }
}
}
return factory;