aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/main/java/org/apache/velocity/runtime
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2016-07-17 23:33:09 +0000
committerClaude Brisson <cbrisson@apache.org>2016-07-17 23:33:09 +0000
commit92d42e6fadb5e554b5223c93169bb4850da31b4c (patch)
tree0c9d5af4d90e69cfcbb594af5f4adcba9a582777 /velocity-engine-core/src/main/java/org/apache/velocity/runtime
parentafe506bb4b3c93d331072e0d2814e8d01cf09eac (diff)
downloadapache-velocity-engine-92d42e6fadb5e554b5223c93169bb4850da31b4c.tar.gz
[engine] keep macros in defining templates (applied reviewed patch from VELOCITY-797, fixes VELOCITY-797 and VELOCITY-776); plus some code cleaning that was in the patch
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1753137 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/main/java/org/apache/velocity/runtime')
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/Renderable.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java176
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java87
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java100
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java161
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java259
-rwxr-xr-xvelocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java11
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java8
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Break.java5
-rwxr-xr-xvelocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java26
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java16
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java12
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java12
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java16
-rwxr-xr-xvelocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java3
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java9
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/contrib/For.java8
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/TemplateParseException.java1
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java12
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscape.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java9
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java28
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java3
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java5
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java5
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java16
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserVisitor.java2
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PublicFieldExecutor.java9
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PutExecutor.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetExecutor.java4
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPropertyExecutor.java7
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPublicFieldExecutor.java11
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java22
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java8
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCache.java3
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java6
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManager.java5
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java8
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java19
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java17
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java20
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java22
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java13
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/util/StringResourceRepositoryImpl.java3
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/BaseVisitor.java47
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java42
76 files changed, 472 insertions, 995 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java
index 76e04a28..e007d826 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java
@@ -19,9 +19,9 @@ package org.apache.velocity.runtime;
* under the License.
*/
+import org.apache.velocity.runtime.parser.CharStream;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.util.SimplePool;
-import org.apache.velocity.runtime.parser.CharStream;
/**
* This wraps the original parser SimplePool class. It also handles
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/Renderable.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/Renderable.java
index b4ca71cb..18ddff98 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/Renderable.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/Renderable.java
@@ -24,8 +24,8 @@ import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
-import java.io.Writer;
import java.io.IOException;
+import java.io.Writer;
/**
* This interface characterize objects other than ASTNodes that can be rendered
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
index c472c39b..908f0606 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
@@ -19,22 +19,6 @@ package org.apache.velocity.runtime;
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.Writer;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
import org.apache.velocity.app.event.EventCartridge;
@@ -52,7 +36,6 @@ import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.directive.Macro;
-import org.apache.velocity.runtime.directive.VelocimacroProxy;
import org.apache.velocity.runtime.directive.Scope;
import org.apache.velocity.runtime.directive.StopCommand;
import org.apache.velocity.runtime.parser.ParseException;
@@ -70,6 +53,21 @@ import org.apache.velocity.util.introspection.Introspector;
import org.apache.velocity.util.introspection.LinkingUberspector;
import org.apache.velocity.util.introspection.Uberspect;
import org.apache.velocity.util.introspection.UberspectLoggable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
/**
* This is the Runtime system for Velocity. It is the
@@ -539,7 +537,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* the case with Turbine.
*
* @param configuration
- * @deprecated use {@link setConfiguration(ExtProperties)}
+ * @deprecated use {@link #setConfiguration(ExtProperties)}
*/
public @Deprecated void setConfiguration( ExtendedProperties configuration)
{
@@ -1221,54 +1219,12 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* PARSER_POOL_SIZE property appropriately for their
* application. We will revisit this.
*
- * @param string String to be parsed
- * @param templateName name of the template being parsed
- * @return A root node representing the template as an AST tree.
- * @throws ParseException When the string could not be parsed as a template.
- * @since 1.6
- */
- public SimpleNode parse(String string, String templateName)
- throws ParseException
- {
- return parse(new StringReader(string), templateName);
- }
-
- /**
- * Parse the input and return the root of
- * AST node structure.
- * <br><br>
- * In the event that it runs out of parsers in the
- * pool, it will create and let them be GC'd
- * dynamically, logging that it has to do that. This
- * is considered an exceptional condition. It is
- * expected that the user will set the
- * PARSER_POOL_SIZE property appropriately for their
- * application. We will revisit this.
- *
- * @param reader Reader retrieved by a resource loader
- * @param templateName name of the template being parsed
- * @return A root node representing the template as an AST tree.
- * @throws ParseException When the template could not be parsed.
- */
- public SimpleNode parse(Reader reader, String templateName)
- throws ParseException
- {
- /*
- * do it and dump the VM namespace for this template
- */
- return parse(reader, templateName, true);
- }
-
- /**
- * Parse the input and return the root of the AST node structure.
- *
* @param reader Reader retrieved by a resource loader
- * @param templateName name of the template being parsed
- * @param dumpNamespace flag to dump the Velocimacro namespace for this template
+ * @param template template being parsed
* @return A root node representing the template as an AST tree.
* @throws ParseException When the template could not be parsed.
*/
- public SimpleNode parse(Reader reader, String templateName, boolean dumpNamespace)
+ public SimpleNode parse(Reader reader, Template template)
throws ParseException
{
requireInitialization();
@@ -1292,21 +1248,14 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
try
{
- /*
- * dump namespace if we are told to. Generally, you want to
- * do this - you don't in special circumstances, such as
- * when a VM is getting init()-ed & parsed
- */
- if (dumpNamespace)
- {
- dumpVMNamespace(templateName);
- }
- return parser.parse(reader, templateName);
+ return parser.parse(reader, template);
}
finally
{
if (keepParser)
{
+ /* drop the parser Template reference to allow garbage collection */
+ parser.currentTemplate = null;
parserPool.put(parser);
}
@@ -1323,6 +1272,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* Renders the input string using the context into the output writer.
* To be used when a template is dynamically constructed, or want to use
* Velocity as a token replacer.
+ * <br>
+ * Note! Macros defined in evaluate() calls are not persisted in memory so next evaluate() call
+ * does not know about macros defined during previous calls.
*
* @param context context to use in rendering input string
* @param out Writer in which to render the output
@@ -1347,6 +1299,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* Renders the input reader using the context into the output writer.
* To be used when a template is dynamically constructed, or want to
* use Velocity as a token replacer.
+ * <br>
+ * Note! Macros defined in evaluate() calls are not persisted in memory so next evaluate() call
+ * does not know about macros defined during previous calls.
*
* @param context context to use in rendering input string
* @param writer Writer in which to render the output
@@ -1370,9 +1325,11 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
}
SimpleNode nodeTree = null;
+ Template t = new Template();
+ t.setName(logTag);
try
{
- nodeTree = parse(reader, logTag);
+ nodeTree = parse(reader, t);
}
catch (ParseException pex)
{
@@ -1504,6 +1461,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* and places the rendered stream into the writer.
* <br>
* Note : currently only accepts args to the VM if they are in the context.
+ * <br>
+ * Note: only macros in the global context can be called. This method doesn't find macros defined by
+ * templates during previous mergeTemplate calls if Velocity.VM_PERM_INLINE_LOCAL has been enabled.
*
* @param vmName name of Velocimacro to call
* @param logTag string to be used for template name in case of error. if null,
@@ -1537,8 +1497,8 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
params = new String[0];
}
- /* does the VM exist? */
- if (!isVelocimacro(vmName, logTag))
+ /* does the VM exist? (only global scope is scanned so this doesn't find inline macros in templates) */
+ if (!isVelocimacro(vmName, null))
{
String msg = "RuntimeInstance.invokeVelocimacro() : VM '" + vmName
+ "' is not registered.";
@@ -1713,91 +1673,49 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
* Returns the appropriate VelocimacroProxy object if vmName
* is a valid current Velocimacro.
*
- * @param vmName Name of velocimacro requested
- * @param templateName Name of the template that contains the velocimacro.
- * @return The requested VelocimacroProxy.
- * @since 1.6
- */
- public Directive getVelocimacro(String vmName, String templateName)
- {
- return vmFactory.getVelocimacro( vmName, templateName );
- }
-
- /**
- * Returns the appropriate VelocimacroProxy object if vmName
- * is a valid current Velocimacro.
- *
* @param vmName Name of velocimacro requested
- * @param templateName Name of the namespace.
- * @param renderingTemplate Name of the template we are currently rendering. This
+ * @param renderingTemplate Template we are currently rendering. This
* information is needed when VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL setting is true
* and template contains a macro with the same name as the global macro library.
- *
- * @since Velocity 1.6
+ * @param template Template which acts as the host for the macro
*
* @return VelocimacroProxy
*/
- public Directive getVelocimacro(String vmName, String templateName, String renderingTemplate)
+ public Directive getVelocimacro(String vmName, Template renderingTemplate, Template template)
{
- return vmFactory.getVelocimacro( vmName, templateName, renderingTemplate );
+ return vmFactory.getVelocimacro(vmName, renderingTemplate, template);
}
/**
- * Return a list of VelocimacroProxies that are defined by the given
- * template name.
- */
- public List<VelocimacroProxy> getVelocimacros(String templateName)
- {
- return vmFactory.getVelocimacros(templateName);
- }
-
-
- /**
* Adds a new Velocimacro. Usually called by Macro only while parsing.
*
- * Called by org.apache.velocity.runtime.directive.processAndRegister
- *
* @param name Name of velocimacro
* @param macro root AST node of the parsed macro
* @param macroArgs Array of macro arguments, containing the
* #macro() arguments and default values. the 0th is the name.
- * @param sourceTemplate
- *
- * @since Velocity 1.6
+ * @param definingTemplate Template containing the source of the macro
*
* @return boolean True if added, false if rejected for some
* reason (either parameters or permission settings)
*/
public boolean addVelocimacro( String name,
- Node macro,
- List<Macro.MacroArg> macroArgs,
- String sourceTemplate )
+ Node macro,
+ List<Macro.MacroArg> macroArgs,
+ Template definingTemplate)
{
- return vmFactory.addVelocimacro(name.intern(), macro, macroArgs, sourceTemplate);
+ return vmFactory.addVelocimacro(name.intern(), macro, macroArgs, definingTemplate);
}
-
/**
* Checks to see if a VM exists
*
* @param vmName Name of the Velocimacro.
- * @param templateName Template on which to look for the Macro.
+ * @param template Template on which to look for the Macro.
* @return True if VM by that name exists, false if not
*/
- public boolean isVelocimacro( String vmName, String templateName )
- {
- return vmFactory.isVelocimacro(vmName.intern(), templateName);
- }
-
- /**
- * tells the vmFactory to dump the specified namespace. This is to support
- * clearing the VM list when in inline-VM-local-scope mode
- * @param namespace Namespace to dump.
- * @return True if namespace was dumped successfully.
- */
- public boolean dumpVMNamespace(String namespace)
+ public boolean isVelocimacro(String vmName, Template template)
{
- return vmFactory.dumpVMNamespace( namespace );
+ return vmFactory.isVelocimacro(vmName.intern(), template);
}
/* --------------------------------------------------------------------
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
index a8513d67..acb4ac8b 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
@@ -19,14 +19,6 @@ package org.apache.velocity.runtime;
* under the License.
*/
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.List;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
import org.apache.velocity.app.event.EventCartridge;
@@ -44,6 +36,13 @@ import org.apache.velocity.runtime.resource.ContentResource;
import org.apache.velocity.util.ExtProperties;
import org.apache.velocity.util.introspection.Introspector;
import org.apache.velocity.util.introspection.Uberspect;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.List;
+import java.util.Properties;
/**
@@ -166,14 +165,6 @@ public interface RuntimeServices
public void init(String configurationFile);
/**
- * Wraps the String in a StringReader and passes it off to
- * {@link #parse(Reader,String)}.
- * @since 1.6
- */
- public SimpleNode parse(String string, String templateName)
- throws ParseException;
-
- /**
* Parse the input and return the root of
* AST node structure.
* <br><br>
@@ -186,23 +177,11 @@ public interface RuntimeServices
* application. We will revisit this.
*
* @param reader inputstream retrieved by a resource loader
- * @param templateName name of the template being parsed
- * @return The AST representing the template.
- * @throws ParseException
- */
- public SimpleNode parse( Reader reader, String templateName )
- throws ParseException;
-
- /**
- * Parse the input and return the root of the AST node structure.
- *
- * @param reader inputstream retrieved by a resource loader
- * @param templateName name of the template being parsed
- * @param dumpNamespace flag to dump the Velocimacro namespace for this template
+ * @param template template being parsed
* @return The AST representing the template.
* @throws ParseException
*/
- public SimpleNode parse( Reader reader, String templateName, boolean dumpNamespace )
+ public SimpleNode parse( Reader reader, Template template )
throws ParseException;
/**
@@ -353,26 +332,14 @@ public interface RuntimeServices
* is a valid current Velocimacro.
*
* @param vmName Name of velocimacro requested
- * @param templateName Name of the namespace.
- * @return VelocimacroProxy
- */
- public Directive getVelocimacro( String vmName, String templateName );
-
- /**
- * Returns the appropriate VelocimacroProxy object if strVMname
- * is a valid current Velocimacro.
- *
- * @param vmName Name of velocimacro requested
- * @param templateName Name of the namespace.
- * @param renderingTemplate Name of the template we are currently rendering. This
+ * @param renderingTemplate Template we are currently rendering. This
* information is needed when VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL setting is true
* and template contains a macro with the same name as the global macro library.
- *
- * @since Velocity 1.6
- *
+ * @param template current template
+ *
* @return VelocimacroProxy
*/
- public Directive getVelocimacro( String vmName, String templateName, String renderingTemplate );
+ public Directive getVelocimacro(String vmName, Template renderingTemplate, Template template);
/**
* Adds a new Velocimacro. Usually called by Macro only while parsing.
@@ -381,35 +348,25 @@ public interface RuntimeServices
* @param macro root AST node of the parsed macro
* @param macroArgs Array of macro arguments, containing the
* #macro() arguments and default values. the 0th is the name.
- * @param sourceTemplate
- *
- * @since Velocity 1.6
- *
+ * @param definingTemplate template containing macro definition
+ *
* @return boolean True if added, false if rejected for some
* reason (either parameters or permission settings)
*/
public boolean addVelocimacro( String name,
- Node macro,
- List<Macro.MacroArg> macroArgs,
- String sourceTemplate );
-
-
+ Node macro,
+ List<Macro.MacroArg> macroArgs,
+ Template definingTemplate );
+
+
/**
* Checks to see if a VM exists
*
* @param vmName Name of velocimacro
- * @param templateName
+ * @param template Template "namespace"
* @return boolean True if VM by that name exists, false if not
*/
- public boolean isVelocimacro( String vmName, String templateName );
-
- /**
- * tells the vmFactory to dump the specified namespace. This is to support
- * clearing the VM list when in inline-VM-local-scope mode
- * @param namespace
- * @return True if the Namespace was dumped.
- */
- public boolean dumpVMNamespace( String namespace );
+ public boolean isVelocimacro(String vmName, Template template);
/**
* String property accessor method to hide the configuration implementation
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java
index 244b3908..a9bd538b 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeSingleton.java
@@ -19,12 +19,6 @@ package org.apache.velocity.runtime;
* under the License.
*/
-import java.io.Reader;
-import java.util.List;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
import org.apache.velocity.app.event.EventCartridge;
@@ -39,6 +33,11 @@ import org.apache.velocity.runtime.resource.ContentResource;
import org.apache.velocity.util.ExtProperties;
import org.apache.velocity.util.introspection.Introspector;
import org.apache.velocity.util.introspection.Uberspect;
+import org.slf4j.Logger;
+
+import java.io.Reader;
+import java.util.List;
+import java.util.Properties;
/**
* This is the Runtime system for Velocity. It is the
@@ -144,7 +143,7 @@ public class RuntimeSingleton implements RuntimeConstants
*/
public static void setProperty(String key, Object value)
{
- ri.setProperty( key, value );
+ ri.setProperty(key, value);
}
/**
@@ -177,7 +176,7 @@ public class RuntimeSingleton implements RuntimeConstants
*/
public static void setConfiguration( ExtProperties configuration)
{
- ri.setConfiguration( configuration );
+ ri.setConfiguration(configuration);
}
/**
@@ -202,7 +201,7 @@ public class RuntimeSingleton implements RuntimeConstants
*/
public static void addProperty(String key, Object value)
{
- ri.addProperty( key, value );
+ ri.addProperty(key, value);
}
/**
@@ -268,35 +267,18 @@ public class RuntimeSingleton implements RuntimeConstants
* application. We will revisit this.
*
* @param reader Reader retrieved by a resource loader
- * @param templateName name of the template being parsed
+ * @param template Template being parsed
* @return A root node representing the template as an AST tree.
* @throws ParseException When the template could not be parsed.
- * @see RuntimeInstance#parse(Reader, String)
+ * @see RuntimeInstance#parse(Reader, Template)
*/
- public static SimpleNode parse( Reader reader, String templateName )
+ public static SimpleNode parse( Reader reader, Template template )
throws ParseException
{
- return ri.parse( reader, templateName );
+ return ri.parse(reader, template);
}
/**
- * Parse the input and return the root of the AST node structure.
- *
- * @param reader Reader retrieved by a resource loader
- * @param templateName name of the template being parsed
- * @param dumpNamespace flag to dump the Velocimacro namespace for this template
- * @return A root node representing the template as an AST tree.
- * @throws ParseException When the template could not be parsed.
- * @see RuntimeInstance#parse(Reader, String, boolean)
- */
- public static SimpleNode parse( Reader reader, String templateName, boolean dumpNamespace )
- throws ParseException
- {
- return ri.parse( reader, templateName, dumpNamespace );
- }
-
-
- /**
* Returns a <code>Template</code> from the resource manager.
* This method assumes that the character encoding of the
* template is set by the <code>input.encoding</code>
@@ -313,7 +295,7 @@ public class RuntimeSingleton implements RuntimeConstants
public static Template getTemplate(String name)
throws ResourceNotFoundException, ParseErrorException
{
- return ri.getTemplate( name );
+ return ri.getTemplate(name);
}
/**
@@ -331,7 +313,7 @@ public class RuntimeSingleton implements RuntimeConstants
public static Template getTemplate(String name, String encoding)
throws ResourceNotFoundException, ParseErrorException
{
- return ri.getTemplate( name, encoding );
+ return ri.getTemplate(name, encoding);
}
/**
@@ -349,7 +331,7 @@ public class RuntimeSingleton implements RuntimeConstants
public static ContentResource getContent(String name)
throws ResourceNotFoundException, ParseErrorException
{
- return ri.getContent( name );
+ return ri.getContent(name);
}
/**
@@ -367,7 +349,7 @@ public class RuntimeSingleton implements RuntimeConstants
public static ContentResource getContent( String name, String encoding )
throws ResourceNotFoundException, ParseErrorException
{
- return ri.getContent( name, encoding );
+ return ri.getContent(name, encoding);
}
@@ -383,7 +365,7 @@ public class RuntimeSingleton implements RuntimeConstants
*/
public static String getLoaderNameForResource( String resourceName )
{
- return ri.getLoaderNameForResource( resourceName );
+ return ri.getLoaderNameForResource(resourceName);
}
@@ -411,7 +393,7 @@ public class RuntimeSingleton implements RuntimeConstants
*/
public static String getString( String key, String defaultValue)
{
- return ri.getString( key, defaultValue );
+ return ri.getString(key, defaultValue);
}
/**
@@ -423,9 +405,22 @@ public class RuntimeSingleton implements RuntimeConstants
* @return The requested VelocimacroProxy.
* @see RuntimeInstance#getVelocimacro(String, String)
*/
- public static Directive getVelocimacro( String vmName, String templateName )
+
+ /**
+ * Returns the appropriate VelocimacroProxy object if strVMname
+ * is a valid current Velocimacro.
+ *
+ * @param vmName Name of velocimacro requested
+ * @param renderingTemplate Template we are currently rendering. This
+ * information is needed when VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL setting is true
+ * and template contains a macro with the same name as the global macro library.
+ * @param template current template
+ *
+ * @return VelocimacroProxy
+ */
+ public static Directive getVelocimacro(String vmName, Template renderingTemplate, Template template)
{
- return ri.getVelocimacro( vmName, templateName );
+ return ri.getVelocimacro(vmName, renderingTemplate, template);
}
/**
@@ -435,41 +430,24 @@ public class RuntimeSingleton implements RuntimeConstants
* @param macro root AST node of the parsed macro
* @param macroArgs Array of macro arguments, containing the
* #macro() arguments and default values. the 0th is the name.
- * @param sourceTemplate The template from which the macro is requested.
- * @return boolean True if added, false if rejected for some
- * reason (either parameters or permission settings)
- * @see RuntimeInstance#addVelocimacro(String, Node, List, String)
- * @since 1.6
+ * @param definingTemplate Templaite containing the definition of the macro.
*/
public static boolean addVelocimacro(String name, Node macro,
- List<Macro.MacroArg> macroArgs, String sourceTemplate)
+ List<Macro.MacroArg> macroArgs, Template definingTemplate)
{
- return ri.addVelocimacro(name, macro, macroArgs, sourceTemplate);
+ return ri.addVelocimacro(name, macro, macroArgs, definingTemplate);
}
/**
* Checks to see if a VM exists
*
* @param vmName Name of the Velocimacro.
- * @param templateName Template on which to look for the Macro.
+ * @param template Template on which to look for the Macro.
* @return True if VM by that name exists, false if not
- * @see RuntimeInstance#isVelocimacro(String, String)
- */
- public static boolean isVelocimacro( String vmName, String templateName )
- {
- return ri.isVelocimacro( vmName, templateName );
- }
-
- /**
- * tells the vmFactory to dump the specified namespace. This is to support
- * clearing the VM list when in inline-VM-local-scope mode
- * @param namespace Namespace to dump.
- * @return True if namespace was dumped successfully.
- * @see RuntimeInstance#dumpVMNamespace(String)
*/
- public static boolean dumpVMNamespace( String namespace )
+ public static boolean isVelocimacro(String vmName, Template template)
{
- return ri.dumpVMNamespace( namespace );
+ return ri.isVelocimacro(vmName, template);
}
/* --------------------------------------------------------------------
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
index 27f03015..fdf2a085 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java
@@ -19,23 +19,20 @@ package org.apache.velocity.runtime;
* under the License.
*/
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import org.slf4j.Logger;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.directive.Macro;
import org.apache.velocity.runtime.directive.VelocimacroProxy;
-import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.node.Node;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
/**
* VelocimacroFactory.java
@@ -318,101 +315,16 @@ public class VelocimacroFactory
/**
* Adds a macro to the factory.
*
- * addVelocimacro(String, Node, String[] argArray, String) should be used internally
- * instead of this.
- *
- * @param name Name of the Macro to add.
- * @param macroBody String representation of the macro.
- * @param macroArgs Array of macro arguments, containing the
- * #macro() arguments and default values. the 0th is the name.
- * @param sourceTemplate Source template from which the macro gets registered.
- *
- * @return true if Macro was registered successfully.
- */
- public boolean addVelocimacro(String name, String macroBody,
- List<Macro.MacroArg> macroArgs, String sourceTemplate)
- {
- /*
- * maybe we should throw an exception, maybe just tell
- * the caller like this...
- *
- * I hate this : maybe exceptions are in order here...
- * They definitely would be if this was only called by directly
- * by users, but Velocity calls this internally.
- */
- if (name == null || macroBody == null || macroArgs == null ||
- sourceTemplate == null)
- {
- String msg = "VM '"+name+"' addition rejected : ";
- if (name == null)
- {
- msg += "name";
- }
- else if (macroBody == null)
- {
- msg += "macroBody";
- }
- else if (macroArgs == null)
- {
- msg += "argArray";
- }
- else
- {
- msg += "sourceTemplate";
- }
- msg += " argument was null";
- log.error(msg);
- throw new NullPointerException(msg);
- }
-
- /*
- * see if the current ruleset allows this addition
- */
-
- if (!canAddVelocimacro(name, sourceTemplate))
- {
- return false;
- }
-
- synchronized (this)
- {
- try
- {
- Node macroRootNode = rsvc.parse(new StringReader(macroBody), sourceTemplate);
-
- vmManager.addVM(name, macroRootNode, macroArgs, sourceTemplate, replaceAllowed);
- }
- catch (ParseException ex)
- {
- // to keep things 1.3 compatible call toString() here
- throw new RuntimeException(ex.toString());
- }
- }
-
- if (log.isDebugEnabled())
- {
- StringBuffer msg = new StringBuffer("added ");
- Macro.macroToString(msg, macroArgs);
- msg.append(" : source = ").append(sourceTemplate);
- log.debug(msg.toString());
- }
-
- return true;
- }
-
- /**
- * Adds a macro to the factory.
- *
* @param name Name of the Macro to add.
* @param macroBody root node of the parsed macro AST
* @param macroArgs Array of macro arguments, containing the
* #macro() arguments and default values. the 0th is the name.
- * @param sourceTemplate Source template from which the macro gets registered.
+ * @param definingTemplate template containing the macro definition
* @return true if Macro was registered successfully.
* @since 1.6
*/
public boolean addVelocimacro(String name, Node macroBody,
- List<Macro.MacroArg> macroArgs, String sourceTemplate)
+ List<Macro.MacroArg> macroArgs, Template definingTemplate)
{
// Called by RuntimeInstance.addVelocimacro
@@ -425,7 +337,7 @@ public class VelocimacroFactory
* by users, but Velocity calls this internally.
*/
if (name == null || macroBody == null || macroArgs == null ||
- sourceTemplate == null)
+ definingTemplate == null)
{
String msg = "VM '"+name+"' addition rejected : ";
if (name == null)
@@ -453,18 +365,18 @@ public class VelocimacroFactory
* see if the current ruleset allows this addition
*/
- if (!canAddVelocimacro(name, sourceTemplate))
+ if (!canAddVelocimacro(name, definingTemplate))
{
return false;
}
synchronized(this)
{
- vmManager.addVM(name, macroBody, macroArgs, sourceTemplate, replaceAllowed);
+ vmManager.addVM(name, macroBody, macroArgs, definingTemplate, replaceAllowed);
}
if (log.isDebugEnabled())
{
- log.debug("added VM {}: source={}", name, sourceTemplate);
+ log.debug("added VM {}: source={}", name, definingTemplate);
}
return true;
}
@@ -475,10 +387,10 @@ public class VelocimacroFactory
* to be added
*
* @param name Name of VM to add
- * @param sourceTemplate Source template that contains the defintion of the VM
+ * @param definingTemplate template containing the source of the macro
* @return true if it is allowed to be added, false otherwise
*/
- private synchronized boolean canAddVelocimacro(String name, String sourceTemplate)
+ private synchronized boolean canAddVelocimacro(String name, Template definingTemplate)
{
/*
* short circuit and do it if autoloader is on, and the
@@ -487,7 +399,7 @@ public class VelocimacroFactory
if (autoReloadLibrary && (macroLibVec != null))
{
- if( macroLibVec.contains(sourceTemplate) )
+ if( macroLibVec.contains(definingTemplate.getName()) )
return true;
}
@@ -516,7 +428,7 @@ public class VelocimacroFactory
*
* so if we have it, and we aren't allowed to replace, bail
*/
- if (!replaceAllowed && isVelocimacro(name, sourceTemplate))
+ if (!replaceAllowed && isVelocimacro(name, definingTemplate))
{
/*
* Concurrency fix: the log entry was changed to debug scope because it
@@ -535,13 +447,13 @@ public class VelocimacroFactory
/**
* Tells the world if a given directive string is a Velocimacro
* @param vm Name of the Macro.
- * @param sourceTemplate Source template from which the macro should be loaded.
+ * @param template Source template from which the macro should be loaded.
* @return True if the given name is a macro.
*/
- public boolean isVelocimacro(String vm, String sourceTemplate)
+ public boolean isVelocimacro(String vm, Template template)
{
// synchronization removed
- return(vmManager.get(vm, sourceTemplate) != null);
+ return(vmManager.get(vm, null, template) != null);
}
/**
@@ -549,31 +461,15 @@ public class VelocimacroFactory
* behave correctly wrt getting the framework to
* dig out the correct # of args
* @param vmName Name of the Macro.
+ * @param renderingTemplate destination template
* @param sourceTemplate Source template from which the macro should be loaded.
* @return A directive representing the Macro.
*/
- public Directive getVelocimacro(String vmName, String sourceTemplate)
- {
- return(getVelocimacro(vmName, sourceTemplate, null));
- }
-
- /**
- * Return a list of VelocimacroProxies that are defined by the given
- * template name.
- */
- public List<VelocimacroProxy> getVelocimacros(String sourceTemplate)
- {
- return vmManager.getVelocimacros(sourceTemplate);
- }
-
- /**
- * @since 1.6
- */
- public Directive getVelocimacro(String vmName, String sourceTemplate, String renderingTemplate)
+ public Directive getVelocimacro(String vmName, Template renderingTemplate, Template sourceTemplate)
{
VelocimacroProxy vp = null;
- vp = vmManager.get(vmName, sourceTemplate, renderingTemplate);
+ vp = vmManager.get(vmName, renderingTemplate, sourceTemplate);
/*
* if this exists, and autoload is on, we need to check where this VM came from
@@ -660,17 +556,6 @@ public class VelocimacroFactory
}
/**
- * tells the vmManager to dump the specified namespace
- *
- * @param namespace Namespace to dump.
- * @return True if namespace has been dumped successfully.
- */
- public boolean dumpVMNamespace(String namespace)
- {
- return vmManager.dumpNamespace(namespace);
- }
-
- /**
* sets permission to have VMs local in scope to their declaring template note that this is
* really taken care of in the VMManager class, but we need it here for gating purposes in addVM
* eventually, I will slide this all into the manager, maybe.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
index b835b3df..3096d43a 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroManager.java
@@ -19,18 +19,15 @@ package org.apache.velocity.runtime;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import org.apache.velocity.Template;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.directive.Macro;
import org.apache.velocity.runtime.directive.VelocimacroProxy;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
+
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -51,18 +48,13 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class VelocimacroManager
{
- private static String GLOBAL_NAMESPACE = "";
-
private boolean registerFromLib = false;
- /** Hash of namespace hashes. */
- private final Map namespaceHash = new ConcurrentHashMap(17, 0.5f, 20);
-
/** reference to global namespace hash */
private final Map globalNamespace;
/** set of names of library tempates/namespaces */
- private final Set libraries = Collections.synchronizedSet(new HashSet());
+ private final Map libraries = new ConcurrentHashMap(17, 0.5f, 20);
private RuntimeServices rsvc = null;
@@ -83,31 +75,11 @@ public class VelocimacroManager
* add the global namespace to the namespace hash. We always have that.
*/
- globalNamespace = addNamespace(GLOBAL_NAMESPACE);
+ globalNamespace = new ConcurrentHashMap(101, 0.5f, 20);
this.rsvc = rsvc;
}
/**
- * Return a list of VelocimacroProxies that are defined by the given
- * template name.
- */
- public List<VelocimacroProxy> getVelocimacros(String templateName)
- {
- Map local = getNamespace(templateName, false);
- ArrayList<VelocimacroProxy> macros = new ArrayList<VelocimacroProxy>(16);
- if (local != null)
- {
- for (Object mo : local.values())
- {
- MacroEntry me = (MacroEntry)mo;
- macros.add(me.vp);
- }
- }
-
- return macros;
- }
-
- /**
* Adds a VM definition to the cache.
*
* Called by VelocimacroFactory.addVelociMacro (after parsing and discovery in Macro directive)
@@ -116,20 +88,21 @@ public class VelocimacroManager
* @param macroBody String representation of the macro body.
* @param macroArgs Array of macro arguments, containing the
* #macro() arguments and default values. the 0th is the name.
- * @param namespace The namespace/template from which this macro has been loaded.
+ * @param definingTemplate The template from which this macro has been loaded.
+ * @param canReplaceGlobalMacro whether this macro can replace a global macro
* @return Whether everything went okay.
*/
public boolean addVM(final String vmName, final Node macroBody, List<Macro.MacroArg> macroArgs,
- final String namespace, boolean canReplaceGlobalMacro)
+ final Template definingTemplate, boolean canReplaceGlobalMacro)
{
if (macroBody == null)
{
// happens only if someone uses this class without the Macro directive
// and provides a null value as an argument
- throw new VelocityException("Null AST for "+vmName+" in "+namespace);
+ throw new VelocityException("Null AST for "+vmName+" in " + definingTemplate.getName());
}
- MacroEntry me = new MacroEntry(vmName, macroBody, macroArgs, namespace, rsvc);
+ MacroEntry me = new MacroEntry(vmName, macroBody, macroArgs, definingTemplate.getName(), rsvc);
me.setFromLibrary(registerFromLib);
@@ -146,7 +119,7 @@ public class VelocimacroManager
if (registerFromLib)
{
- libraries.add(namespace);
+ libraries.put(definingTemplate.getName(), definingTemplate);
}
else
{
@@ -158,19 +131,12 @@ public class VelocimacroManager
* global
*/
- isLib = libraries.contains(namespace);
+ isLib = libraries.containsKey(definingTemplate.getName());
}
- if ( !isLib && usingNamespaces(namespace) )
+ if ( !isLib && usingNamespaces() )
{
- /*
- * first, do we have a namespace hash already for this namespace?
- * if not, add it to the namespaces, and add the VM
- */
-
- Map local = getNamespace(namespace, true);
- local.put(vmName, me);
-
+ definingTemplate.getMacros().put(vmName, me);
return true;
}
else
@@ -195,30 +161,17 @@ public class VelocimacroManager
return true;
}
}
-
+
/**
* Gets a VelocimacroProxy object by the name / source template duple.
- *
+ *
* @param vmName Name of the VelocityMacro to look up.
- * @param namespace Namespace in which to look up the macro.
+ * @param renderingTemplate Template we are currently rendering.
+ * @param template Source Template.
* @return A proxy representing the Macro.
*/
- public VelocimacroProxy get(final String vmName, final String namespace)
- {
- return(get(vmName, namespace, null));
- }
-
- /**
- * Gets a VelocimacroProxy object by the name / source template duple.
- *
- * @param vmName Name of the VelocityMacro to look up.
- * @param namespace Namespace in which to look up the macro.
- * @param renderingTemplate Name of the template we are currently rendering.
- * @return A proxy representing the Macro.
- * @since 1.6
- */
- public VelocimacroProxy get(final String vmName, final String namespace, final String renderingTemplate)
- {
+ public VelocimacroProxy get(final String vmName, final Template renderingTemplate, final Template template)
+ {
if( inlineReplacesGlobal && renderingTemplate != null )
{
/*
@@ -227,83 +180,34 @@ public class VelocimacroManager
* moment, check if local namespace contains a macro we are looking for
* if so, return it instead of the global one
*/
- Map local = getNamespace(renderingTemplate, false);
- if (local != null)
- {
- MacroEntry me = (MacroEntry) local.get(vmName);
- if (me != null)
- {
- return me.getProxy(namespace);
- }
+ MacroEntry me = (MacroEntry)renderingTemplate.getMacros().get(vmName);
+ if( me != null )
+ {
+ return me.getProxy();
}
}
-
- if (usingNamespaces(namespace))
- {
- Map local = getNamespace(namespace, false);
- /*
- * if we have macros defined for this template
- */
-
- if (local != null)
+ if( usingNamespaces() && template != null )
+ {
+ MacroEntry me = (MacroEntry)template.getMacros().get(vmName);
+ if( template.getMacros().size() > 0 && me != null )
{
- MacroEntry me = (MacroEntry) local.get(vmName);
-
- if (me != null)
- {
- return me.getProxy(namespace);
- }
+ return me.getProxy();
}
}
- /*
- * if we didn't return from there, we need to simply see
- * if it's in the global namespace
- */
-
MacroEntry me = (MacroEntry) globalNamespace.get(vmName);
if (me != null)
{
- return me.getProxy(namespace);
+ return me.getProxy();
}
return null;
}
/**
- * Removes the VMs and the namespace from the manager.
- * Used when a template is reloaded to avoid
- * losing memory.
- *
- * @param namespace namespace to dump
- * @return boolean representing success
- */
- public boolean dumpNamespace(final String namespace)
- {
- synchronized(this)
- {
- if (usingNamespaces(namespace))
- {
- Map h = (Map) namespaceHash.remove(namespace);
-
- if (h == null)
- {
- return false;
- }
-
- h.clear();
-
- return true;
- }
-
- return false;
- }
- }
-
- /**
* public switch to let external user of manager to control namespace
* usage indep of properties. That way, for example, at startup the
* library files are loaded into global namespace
@@ -335,63 +239,11 @@ public class VelocimacroManager
}
/**
- * returns the hash for the specified namespace, and if it doesn't exist
- * will create a new one and add it to the namespaces
- *
- * @param namespace name of the namespace :)
- * @param addIfNew flag to add a new namespace if it doesn't exist
- * @return namespace Map of VMs or null if doesn't exist
- */
- private Map getNamespace(final String namespace, final boolean addIfNew)
- {
- Map h = (Map) namespaceHash.get(namespace);
-
- if (h == null && addIfNew)
- {
- h = addNamespace(namespace);
- }
-
- return h;
- }
-
- /**
- * adds a namespace to the namespaces
- *
- * @param namespace name of namespace to add
- * @return Hash added to namespaces, ready for use
- */
- private Map addNamespace(final String namespace)
- {
- Map h = new ConcurrentHashMap(17, 0.5f, 20);
- Object oh;
-
- if ((oh = namespaceHash.put(namespace, h)) != null)
- {
- /*
- * There was already an entry on the table, restore it!
- * This condition should never occur, given the code
- * and the fact that this method is private.
- * But just in case, this way of testing for it is much
- * more efficient than testing before hand using get().
- */
- namespaceHash.put(namespace, oh);
- /*
- * Should't we be returning the old entry (oh)?
- * The previous code was just returning null in this case.
- */
- return null;
- }
-
- return h;
- }
-
- /**
* determines if currently using namespaces.
*
- * @param namespace currently ignored
* @return true if using namespaces, false if not
*/
- private boolean usingNamespaces(final String namespace)
+ private boolean usingNamespaces()
{
/*
* if the big switch turns of namespaces, then ignore the rules
@@ -417,37 +269,23 @@ public class VelocimacroManager
/**
* Return the library name for a given macro.
* @param vmName Name of the Macro to look up.
- * @param namespace Namespace to look the macro up.
+ * @param template Template
* @return The name of the library which registered this macro in a namespace.
*/
- public String getLibraryName(final String vmName, final String namespace)
+ public String getLibraryName(final String vmName, Template template)
{
- if (usingNamespaces(namespace))
+ if (usingNamespaces())
{
- Map local = getNamespace(namespace, false);
-
/*
* if we have this macro defined in this namespace, then
* it is masking the global, library-based one, so
* just return null
*/
-
- if ( local != null)
- {
- MacroEntry me = (MacroEntry) local.get(vmName);
-
- if (me != null)
- {
- return null;
- }
- }
+ MacroEntry me = (MacroEntry)template.getMacros().get(vmName);
+ if( me != null )
+ return null;
}
- /*
- * if we didn't return from there, we need to simply see
- * if it's in the global namespace
- */
-
MacroEntry me = (MacroEntry) globalNamespace.get(vmName);
if (me != null)
@@ -492,7 +330,7 @@ public class VelocimacroManager
vp.setName(this.vmName);
vp.setMacroArgs(this.macroArgs);
vp.setNodeTree(this.nodeTree);
- vp.setLocation(macro.getLine(), macro.getColumn(), macro.getTemplateName());
+ vp.setLocation(macro.getLine(), macro.getColumn(), macro.getTemplate());
vp.init(rsvc);
}
@@ -514,30 +352,13 @@ public class VelocimacroManager
return fromLibrary;
}
- /**
- * Returns the node tree for this macro.
- * @return The node tree for this macro.
- */
- public SimpleNode getNodeTree()
- {
- return nodeTree;
- }
-
- /**
- * Returns the source template name for this macro.
- * @return The source template name for this macro.
- */
public String getSourceTemplate()
{
return sourceTemplate;
}
- VelocimacroProxy getProxy(final String namespace)
+ VelocimacroProxy getProxy()
{
- /*
- * FIXME: namespace data is omitted, this probably
- * breaks some error reporting?
- */
return vp;
}
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java
index 71ac3dd1..50e9e78c 100755
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java
@@ -19,18 +19,17 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import org.slf4j.Logger;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.Renderable;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.util.StringUtils;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
/**
* Directive that puts an unrendered AST block in the context
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java
index 71556c72..f263c886 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java
@@ -19,15 +19,15 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.Node;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* BlockMacro directive is used to invoke Velocity macros with normal parameters and a macro body.
* <p>
@@ -102,7 +102,7 @@ public class BlockMacro extends Block
maxDepth = rs.getInt(RuntimeConstants.VM_MAX_DEPTH);
macro = new RuntimeMacro(name);
- macro.setLocation(getLine(), getColumn(), getTemplateName());
+ macro.setLocation(getLine(), getColumn(), getTemplate());
macro.init(rs, context, node);
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Break.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Break.java
index bff06199..5583667c 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Break.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Break.java
@@ -19,8 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.Writer;
-import java.util.ArrayList;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeServices;
@@ -29,6 +27,9 @@ import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.util.StringUtils;
+import java.io.Writer;
+import java.util.ArrayList;
+
/**
* Break directive used for interrupting scopes.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java
index cbebd0ad..8786cb18 100755
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java
@@ -19,9 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.Writer;
-import java.util.ArrayList;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
@@ -33,6 +30,9 @@ import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.util.StringUtils;
+import java.io.Writer;
+import java.util.ArrayList;
+
/**
* Directive that puts an unrendered AST block in the context
* under the specified key, postponing rendering until the
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
index c9631168..13c783ff 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java
@@ -19,10 +19,7 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -34,6 +31,10 @@ import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+
/**
* Base class for all directives used in Velocity.
@@ -47,7 +48,7 @@ public abstract class Directive implements DirectiveConstants, Cloneable
private int line = 0;
private int column = 0;
private boolean provideScope = false;
- private String templateName;
+ private Template template;
/**
*
@@ -82,10 +83,19 @@ public abstract class Directive implements DirectiveConstants, Cloneable
* @param line
* @param column
*/
- public void setLocation(int line, int column, String templateName)
+ public void setLocation(int line, int column, Template template)
{
setLocation(line, column);
- this.templateName = templateName;
+ this.template = template;
+ }
+
+ /**
+ * returns the template in which this directive appears
+ * @return template
+ */
+ public Template getTemplate()
+ {
+ return template;
}
/**
@@ -112,7 +122,7 @@ public abstract class Directive implements DirectiveConstants, Cloneable
*/
public String getTemplateName()
{
- return templateName;
+ return template.getName();
}
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java
index 89d8a51d..19c2943e 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Evaluate.java
@@ -19,9 +19,7 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.Writer;
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -34,6 +32,10 @@ import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.util.introspection.Info;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.Writer;
+
/**
* Evaluates the directive argument as a VTL string, using the existing
* context.
@@ -151,11 +153,17 @@ public class Evaluate extends Directive
* The new string needs to be parsed since the text has been dynamically generated.
*/
String templateName = context.getCurrentTemplateName();
+ Template template = (Template)context.getCurrentResource();
+ if (template == null)
+ {
+ template = new Template();
+ template.setName(templateName);
+ }
SimpleNode nodeTree = null;
try
{
- nodeTree = rsvc.parse(new StringReader(sourceText), templateName, false);
+ nodeTree = rsvc.parse(new StringReader(sourceText), template);
}
catch (ParseException pex)
{
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java
index bd70f1e0..d17654f6 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java
@@ -19,12 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Iterator;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
@@ -39,6 +33,12 @@ import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.util.StringUtils;
import org.apache.velocity.util.introspection.Info;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+
/**
* Foreach directive used for moving through arrays,
* or objects that provide an Iterator.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java
index 41725185..ef59e2e5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java
@@ -19,9 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
@@ -35,6 +32,9 @@ import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.util.StringUtils;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* <p>Pluggable directive that handles the #include() statement in VTL.
* This #include() can take multiple arguments of either
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java
index ce082d5c..03256d51 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java
@@ -19,11 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.RuntimeServices;
@@ -32,6 +27,11 @@ import org.apache.velocity.runtime.parser.ParserTreeConstants;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Macro implements the macro definition directive of VTL.
*
@@ -115,7 +115,7 @@ public class Macro extends Directive
List<MacroArg> macroArgs = getArgArray(node, rs);
int numArgs = node.jjtGetNumChildren();
rs.addVelocimacro(macroArgs.get(0).name, node.jjtGetChild(numArgs - 1),
- macroArgs, node.getTemplateName());
+ macroArgs, node.getTemplate());
}
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java
index 2153a4d6..b440d201 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java
@@ -19,11 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.velocity.Template;
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.InternalContextAdapter;
@@ -41,6 +36,11 @@ import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.util.StringUtils;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Pluggable directive that handles the <code>#parse()</code>
* statement in VTL.
@@ -266,7 +266,8 @@ public class Parse extends InputBase
context.setMacroLibraries(macroLibraries);
- macroLibraries.add(arg);
+ /* instead of adding the name of the template, add the Template reference */
+ macroLibraries.add(t);
/*
* and render it
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
index 85c9c7be..83efcef0 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
@@ -19,10 +19,7 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -37,6 +34,10 @@ import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.util.StringUtils;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
/**
* This class acts as a proxy for potential macros. When the AST is built
* this class is inserted as a placeholder for the macro (whether or not
@@ -247,12 +248,12 @@ public class RuntimeMacro extends Directive
ParseErrorException, MethodInvocationException
{
VelocimacroProxy vmProxy = null;
- String renderingTemplate = context.getCurrentTemplateName();
+ Template renderingTemplate = (Template)context.getCurrentResource();
/**
* first look in the source template
*/
- Object o = rsvc.getVelocimacro(macroName, getTemplateName(), renderingTemplate);
+ Object o = rsvc.getVelocimacro(macroName, renderingTemplate, getTemplate());
if( o != null )
{
@@ -271,8 +272,7 @@ public class RuntimeMacro extends Directive
{
for (int i = macroLibraries.size() - 1; i >= 0; i--)
{
- o = rsvc.getVelocimacro(macroName,
- (String)macroLibraries.get(i), renderingTemplate);
+ o = rsvc.getVelocimacro(macroName, renderingTemplate, (Template)macroLibraries.get(i));
// get the first matching macro
if (o != null)
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java
index 04c4f1bb..940c1187 100755
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java
@@ -19,11 +19,12 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
+import org.apache.velocity.Template;
+
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import org.apache.velocity.Template;
/**
* This handles context scoping and metadata for directives.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java
index 76786192..9550bbad 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java
@@ -19,15 +19,15 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.Writer;
-import java.util.ArrayList;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.ParseException;
-import org.apache.velocity.runtime.parser.ParserTreeConstants;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.Node;
+import java.io.Writer;
+import java.util.ArrayList;
+
/**
* This class implements the #stop directive which allows
* a user to stop the merging and rendering process. The #stop directive
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
index ee5ee793..92152083 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
@@ -19,10 +19,6 @@ package org.apache.velocity.runtime.directive;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MacroOverflowException;
import org.apache.velocity.exception.VelocityException;
@@ -34,6 +30,10 @@ import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.util.StringUtils;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
/**
* VelocimacroProxy.java
*
@@ -274,7 +274,6 @@ public class VelocimacroProxy extends Directive
{
if (maxCallDepth > 0 && maxCallDepth == context.getCurrentMacroCallDepth())
{
- String templateName = context.getCurrentTemplateName();
String[] stack = context.getMacroNameStack();
StringBuffer out = new StringBuffer(100)
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/contrib/For.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/contrib/For.java
index 7ee16600..6e491911 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/contrib/For.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/contrib/For.java
@@ -18,10 +18,6 @@
*/
package org.apache.velocity.runtime.directive.contrib;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.RuntimeServices;
@@ -33,6 +29,10 @@ import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.runtime.parser.node.ASTReference;
import org.apache.velocity.runtime.parser.node.Node;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+
/**
* The #for directive provides the behavior of the #foreach directive but also
* provides an 'index' keyword that allows the user to define an optional index variable
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/TemplateParseException.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/TemplateParseException.java
index f497fecb..ade1a1b5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/TemplateParseException.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/TemplateParseException.java
@@ -20,7 +20,6 @@ package org.apache.velocity.runtime.parser;
*/
import org.apache.velocity.exception.ExtendedParseException;
-
import org.apache.velocity.util.StringUtils;
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
index e97ca8e5..08687ae7 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
@@ -69,8 +69,6 @@ public class ASTAndNode extends SimpleNode
public Object value(InternalContextAdapter context)
throws MethodInvocationException
{
- // TODO: JDK 1.4+ -> valueOf()
- // return new Boolean(evaluate(context));
return evaluate(context) ? Boolean.TRUE : Boolean.FALSE;
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
index 142dcf7d..339d8e58 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
@@ -19,15 +19,15 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java
index c04121ef..3a235543 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java
@@ -19,9 +19,6 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -29,6 +26,9 @@ import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* Represents all comments...
*
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 4564d643..408a0163 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
@@ -19,9 +19,6 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -34,6 +31,9 @@ import org.apache.velocity.runtime.directive.RuntimeMacro;
import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This class is responsible for handling the pluggable
* directives in VTL.
@@ -121,7 +121,7 @@ public class ASTDirective extends SimpleNode
e);
}
- directive.setLocation(getLine(), getColumn(), getTemplateName());
+ directive.setLocation(getLine(), getColumn(), getTemplate());
directive.init(rsvc, context,this);
}
else if( directiveName.startsWith("@") )
@@ -132,7 +132,7 @@ public class ASTDirective extends SimpleNode
directiveName = directiveName.substring(1);
directive = new BlockMacro(directiveName);
- directive.setLocation(getLine(), getColumn(), getTemplateName());
+ directive.setLocation(getLine(), getColumn(), getTemplate());
try
{
@@ -161,7 +161,7 @@ public class ASTDirective extends SimpleNode
* Create a new RuntimeMacro
*/
directive = new RuntimeMacro(directiveName);
- directive.setLocation(getLine(), getColumn(), getTemplateName());
+ directive.setLocation(getLine(), getColumn(), getTemplate());
/**
* Initialize it
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
index 8961f428..5d0de2e3 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
@@ -19,15 +19,15 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This class is responsible for handling the ElseIf VTL control statement.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscape.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
index fcc0a73f..12d31638 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
@@ -19,12 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This class is responsible for handling Escapes
* in VTL.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java
index 923e8e6b..5bc2cd91 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java
@@ -19,12 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This class is responsible for handling EscapedDirectives
* in VTL.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
index da0eb2e1..d6804e8e 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
@@ -19,12 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.math.BigDecimal;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.parser.Parser;
+import java.math.BigDecimal;
+
/**
* Handles floating point numbers. The value will be either a Double
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
index 3030c039..50b46988 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
@@ -19,8 +19,6 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
@@ -32,6 +30,8 @@ import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.IntrospectionCacheData;
import org.apache.velocity.util.introspection.VelPropertyGet;
+import java.lang.reflect.InvocationTargetException;
+
/**
* ASTIdentifier.java
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
index a3167d09..9b2c2b58 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
@@ -29,15 +29,15 @@ package org.apache.velocity.runtime.parser.node;
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.parser.Parser;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
index a111e839..75fe6902 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
@@ -19,12 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.math.BigInteger;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.parser.Parser;
+import java.math.BigInteger;
+
/**
* Handles integer numbers. The value will be either an Integer, a Long, or a BigInteger.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
index 437fb658..24843e95 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
@@ -19,14 +19,14 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.util.StringUtils;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* handles the range 'operator' [ n .. m ]
*
@@ -136,7 +136,6 @@ public class ASTIntegerRange extends SimpleNode
for (int i = 0; i < nbrElements; i++)
{
- // TODO: JDK 1.4+ -> valueOf()
elements.add(new Integer(value));
value += delta;
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java
index 3c25cff0..1b3607d5 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java
@@ -19,13 +19,13 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.util.LinkedHashMap;
-import java.util.Map;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.parser.Parser;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
/**
* AST Node for creating a map / dictionary.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
index 99d08b12..225f9925 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
@@ -19,8 +19,6 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.InternalContextAdapter;
@@ -35,6 +33,8 @@ import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.IntrospectionCacheData;
import org.apache.velocity.util.introspection.VelMethod;
+import java.lang.reflect.InvocationTargetException;
+
/**
* ASTMethod.java
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
index 6e1e329b..c035931a 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
@@ -19,13 +19,13 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.parser.Parser;
+import java.util.ArrayList;
+import java.util.List;
+
/**
*
*/
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
index b32a634c..8a25aaf3 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
@@ -69,8 +69,6 @@ public class ASTOrNode extends SimpleNode
public Object value(InternalContextAdapter context )
throws MethodInvocationException
{
- // TODO: JDK 1.4+ -> valueOf()
- // return new Boolean(evaluate(context));
return evaluate(context) ? Boolean.TRUE : Boolean.FALSE;
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java
index ef24e7d6..2b311e04 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java
@@ -19,12 +19,7 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.lang.reflect.InvocationTargetException;
-
import org.apache.velocity.app.event.EventHandlerUtil;
-import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.TemplateInitException;
@@ -42,6 +37,10 @@ import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.VelMethod;
import org.apache.velocity.util.introspection.VelPropertySet;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
+
/**
* This class is responsible for handling the references in
* VTL ($foo).
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
index 560a231a..4ba478b3 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
@@ -19,9 +19,6 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
@@ -30,6 +27,9 @@ import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.util.introspection.Info;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* Node for the #set directive
*
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 d1899dc2..468e97bf 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
@@ -17,10 +17,7 @@ package org.apache.velocity.runtime.parser.node;
* the License.
*/
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
@@ -30,6 +27,10 @@ import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.util.StringUtils;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
/**
* ASTStringLiteral support. Will interpolate!
*
@@ -163,17 +164,25 @@ public class ASTStringLiteral extends SimpleNode
* Also, do *not* dump the VM namespace for this template
*/
- String templateName =
- (context != null) ? context.getCurrentTemplateName() : "StringLiteral";
+ Template template = null;
+ if (context != null)
+ {
+ template = (Template)context.getCurrentResource();
+ }
+ if (template == null)
+ {
+ template = new Template();
+ template.setName("StringLiteral");
+ }
try
{
- nodeTree = rsvc.parse(br, templateName, false);
+ nodeTree = rsvc.parse(br, template);
}
catch (ParseException e)
{
String msg = "Failed to parse String literal at "+
- StringUtils.formatFileString(templateName, getLine(), getColumn());
- throw new TemplateInitException(msg, e, templateName, getColumn(), getLine());
+ StringUtils.formatFileString(template.getName(), getLine(), getColumn());
+ throw new TemplateInitException(msg, e, template.getName(), getColumn(), getLine());
}
adjTokenLineNums(nodeTree);
@@ -233,7 +242,6 @@ public class ASTStringLiteral extends SimpleNode
}
StringBuilder result = new StringBuilder(s.length());
- char prev = ' ';
for(int i = 0, is = s.length(); i < is; i++)
{
char c = s.charAt(i);
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java
index 4a4cdea9..c9f316f2 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java
@@ -19,14 +19,14 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
+import java.io.IOException;
+import java.io.Writer;
+
/**
*
*/
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java
index 2358e77a..83357c23 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java
@@ -19,14 +19,14 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This node holds the "Textblock" data which should not be interpreted by Velocity.
*
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
index b7048a50..40df8d53 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
@@ -19,11 +19,11 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
+import org.slf4j.Logger;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.slf4j.Logger;
-
/**
* Abstract class that is used to execute an arbitrary
* method that is in introspected. This is the superclass
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
index fab3bd3a..15465e80 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
@@ -19,10 +19,9 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import org.slf4j.Logger;
-
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
/**
* Handles discovery and valuation of a
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java
index 5d1bbd06..5569274c 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java
@@ -19,12 +19,11 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.InvocationTargetException;
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java
index 23d6c6ab..36ab3287 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java
@@ -19,11 +19,10 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.util.Map;
-
+import org.apache.velocity.exception.VelocityException;
import org.slf4j.Logger;
-import org.apache.velocity.exception.VelocityException;
+import java.util.Map;
/**
* GetExecutor that is smart about Maps. If it detects one, it does not
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java
index 915064d9..506dcc39 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java
@@ -19,11 +19,10 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.util.Map;
-
+import org.apache.velocity.exception.VelocityException;
import org.slf4j.Logger;
-import org.apache.velocity.exception.VelocityException;
+import java.util.Map;
/**
* SetExecutor that is smart about Maps. If it detects one, it does not
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java
index b2430c4a..8aac3889 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java
@@ -21,10 +21,10 @@ package org.apache.velocity.runtime.parser.node;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Map;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
/**
* Utility-class for all arithmetic-operations.<br><br>
@@ -184,8 +184,7 @@ public abstract class MathUtils
}
else
{
- // TODO: JDK 1.4+ -> valueOf()
- return new Byte ((byte)value);
+ return Byte.valueOf((byte)value);
}
}
if (type == Short.class)
@@ -196,8 +195,7 @@ public abstract class MathUtils
}
else
{
- // TODO: JDK 1.4+ -> valueOf()
- return new Short((short)value);
+ return Short.valueOf((short)value);
}
}
if (type == Integer.class)
@@ -208,14 +206,12 @@ public abstract class MathUtils
}
else
{
- // TODO: JDK 1.4+ -> valueOf()
- return new Integer ((int)value);
+ return Integer.valueOf((int)value);
}
}
if (type == Long.class)
{
- // TODO: JDK 1.4+ -> valueOf()
- return new Long (value);
+ return Long.valueOf(value);
}
return BigInteger.valueOf( value);
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java
index 4225eeab..d725004f 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java
@@ -19,9 +19,7 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -30,6 +28,9 @@ import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.Renderable;
import org.apache.velocity.runtime.parser.Token;
+import java.io.IOException;
+import java.io.Writer;
+
/**
* This file describes the interface between the Velocity code
* and the JavaCC generated code.
@@ -205,4 +206,10 @@ public interface Node extends Renderable
* @return the file name of the template
*/
public String getTemplateName();
+
+ /**
+ * @return the template this node belongs to
+ */
+ public Template getTemplate();
+
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserVisitor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserVisitor.java
index f57d0f81..562f4979 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserVisitor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ParserVisitor.java
@@ -1,7 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-import org.apache.velocity.runtime.directive.Stop;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
index 1cd8f28f..915e24d4 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
@@ -19,13 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.InvocationTargetException;
/**
* Returned the value of object property when executed.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PublicFieldExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PublicFieldExecutor.java
index fe528e21..1935dd38 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PublicFieldExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PublicFieldExecutor.java
@@ -19,14 +19,13 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
/**
* Returns the value of a public field when executed.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PutExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PutExecutor.java
index 94375e42..4b5ca5da 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PutExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PutExecutor.java
@@ -19,12 +19,11 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.InvocationTargetException;
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetExecutor.java
index 8ba98c62..06a042bc 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetExecutor.java
@@ -19,11 +19,11 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
+import org.slf4j.Logger;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.slf4j.Logger;
-
/**
* Abstract class that is used to execute an arbitrary
* method that is in introspected. This is the superclass
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPropertyExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPropertyExecutor.java
index 74ed4a7b..2ebcb638 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPropertyExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPropertyExecutor.java
@@ -19,13 +19,12 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-
-import org.slf4j.Logger;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.InvocationTargetException;
/**
* Executor for looking up property names in the passed in class
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPublicFieldExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPublicFieldExecutor.java
index 2d374b0b..117a8412 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPublicFieldExecutor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SetPublicFieldExecutor.java
@@ -19,15 +19,14 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-
-import org.slf4j.Logger;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.util.introspection.Introspector;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
/**
* Executor for setting public fields in objects
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
index 4f829ebf..ab8bc27c 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
@@ -19,12 +19,7 @@ package org.apache.velocity.runtime.parser.node;
* under the License.
*/
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Arrays;
-
-import org.slf4j.Logger;
-
+import org.apache.velocity.Template;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
@@ -34,6 +29,11 @@ import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.Token;
import org.apache.velocity.util.StringUtils;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
/**
*
@@ -74,9 +74,7 @@ public class SimpleNode implements Node
/** */
protected Token last;
-
- protected String templateName;
-
+ protected Template template;
public RuntimeServices getRuntimeServices()
{
@@ -99,7 +97,7 @@ public class SimpleNode implements Node
{
this(i);
parser = p;
- templateName = parser.currentTemplateName;
+ template = parser.currentTemplate;
}
/**
@@ -441,7 +439,9 @@ public class SimpleNode implements Node
public String getTemplateName()
{
- return templateName;
+ return template.getName();
}
+
+ public Template getTemplate() { return template; }
}
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java
index 66147949..6b6c172d 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ContentResource.java
@@ -19,12 +19,12 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
-import java.io.StringWriter;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
+import java.io.BufferedReader;
+import java.io.StringWriter;
+
/**
* This class represent a general text resource that may have been
* retrieved from any number of possible sources.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java
index d089fa6b..ec49e7fa 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/Resource.java
@@ -19,14 +19,12 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
-import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.RuntimeConstants;
-
+import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.resource.loader.ResourceLoader2;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
-
/**
* This class represent a general text resource that
* may have been retrieved from any number of possible
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCache.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCache.java
index d01e1c93..03cf7eec 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCache.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceCache.java
@@ -19,9 +19,10 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
-import java.util.Iterator;
import org.apache.velocity.runtime.RuntimeServices;
+import java.util.Iterator;
+
/**
* Interface that defines the shape of a pluggable resource cache
* for the included ResourceManager
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 44827a3d..87f9fcee 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
@@ -19,15 +19,15 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.RuntimeServices;
+
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
-
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.RuntimeServices;
import java.util.concurrent.ConcurrentHashMap;
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManager.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManager.java
index 685790db..d0cc7bcc 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManager.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManager.java
@@ -19,10 +19,9 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
-import org.apache.velocity.runtime.RuntimeServices;
-
-import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeServices;
/**
* Class to manage the text resource for the Velocity
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
index 21b85fdb..7dc5af8f 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
@@ -19,13 +19,6 @@ package org.apache.velocity.runtime.resource;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.slf4j.Logger;
-
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
@@ -36,6 +29,12 @@ import org.apache.velocity.runtime.resource.loader.ResourceLoaderFactory;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.ExtProperties;
import org.apache.velocity.util.StringUtils;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
/**
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
index f4f6ca54..94814d3c 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
@@ -19,16 +19,16 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.ExtProperties;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
/**
* ClasspathResourceLoader is a simple loader that will load
* templates from the classpath.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
index 660c5122..fc7d51a1 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
@@ -19,6 +19,15 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.util.ExtProperties;
+import org.apache.velocity.util.StringUtils;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
@@ -28,16 +37,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
-
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.util.ExtProperties;
-import org.apache.velocity.util.StringUtils;
-
/**
* <P>This is a simple template file loader that loads templates
* from a DataSource instead of plain files.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
index 10d4067e..1d98d128 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
@@ -19,6 +19,12 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.util.ExtProperties;
+import org.apache.velocity.util.StringUtils;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -31,13 +37,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.io.UnicodeInputStream;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.util.ExtProperties;
-import org.apache.velocity.util.StringUtils;
-
/**
* A loader for templates stored on the file system. Treats the template
* as relative to the configured root path. If the root path is empty
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
index fa7e0476..f66c54f8 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
@@ -19,20 +19,19 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.RuntimeServices;
+import org.slf4j.Logger;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import java.util.Hashtable;
-
-import org.slf4j.Logger;
-
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.VelocityException;
/**
* A small wrapper around a Jar
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
index 6df46dae..5a2064a4 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
@@ -19,20 +19,19 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.util.ExtProperties;
+import org.apache.velocity.util.StringUtils;
+
import java.io.IOException;
import java.io.InputStream;
-
import java.io.Reader;
+import java.util.HashMap;
import java.util.Hashtable;
-import java.util.Vector;
import java.util.Map;
-import java.util.HashMap;
-
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.util.StringUtils;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.util.ExtProperties;
+import java.util.Vector;
/**
* <p>
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
index a51d2d67..526c05bb 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
@@ -19,23 +19,15 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.velocity.io.UnicodeInputStream;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.slf4j.Logger;
-
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.runtime.resource.ResourceCacheImpl;
+import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.util.ExtProperties;
-import org.apache.commons.collections.ExtendedProperties;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
/**
* This is abstract class the all text resource loaders should
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java
index 7296df85..3439f208 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java
@@ -19,26 +19,26 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-
+import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.util.StringResource;
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
import org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl;
-import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.ExtProperties;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Resource loader that works with Strings. Users should manually add
* resources to the repository that is used by the resource loader instance.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
index 85fb0a9c..e00789f4 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
@@ -19,18 +19,19 @@ package org.apache.velocity.runtime.resource.loader;
* under the License.
*/
-import java.io.InputStream;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.util.ExtProperties;
+
import java.io.IOException;
+import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.util.ExtProperties;
-import org.apache.commons.lang3.StringUtils;
/**
* This is a simple URL-based loader.
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 7032ece1..58de8a4d 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
@@ -19,10 +19,11 @@ package org.apache.velocity.runtime.resource.util;
* under the License.
*/
+import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
/**
* Default implementation of StringResourceRepository.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/BaseVisitor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
index f5adc506..45fe49e1 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/BaseVisitor.java
@@ -19,51 +19,10 @@ package org.apache.velocity.runtime.visitor;
* under the License.
*/
-import java.io.Writer;
-
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.directive.Stop;
-import org.apache.velocity.runtime.parser.node.ASTAddNode;
-import org.apache.velocity.runtime.parser.node.ASTAndNode;
-import org.apache.velocity.runtime.parser.node.ASTAssignment;
-import org.apache.velocity.runtime.parser.node.ASTBlock;
-import org.apache.velocity.runtime.parser.node.ASTComment;
-import org.apache.velocity.runtime.parser.node.ASTDirective;
-import org.apache.velocity.runtime.parser.node.ASTDivNode;
-import org.apache.velocity.runtime.parser.node.ASTEQNode;
-import org.apache.velocity.runtime.parser.node.ASTElseIfStatement;
-import org.apache.velocity.runtime.parser.node.ASTElseStatement;
-import org.apache.velocity.runtime.parser.node.ASTEscape;
-import org.apache.velocity.runtime.parser.node.ASTEscapedDirective;
-import org.apache.velocity.runtime.parser.node.ASTExpression;
-import org.apache.velocity.runtime.parser.node.ASTFalse;
-import org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral;
-import org.apache.velocity.runtime.parser.node.ASTGENode;
-import org.apache.velocity.runtime.parser.node.ASTGTNode;
-import org.apache.velocity.runtime.parser.node.ASTIdentifier;
-import org.apache.velocity.runtime.parser.node.ASTIfStatement;
-import org.apache.velocity.runtime.parser.node.ASTIntegerLiteral;
-import org.apache.velocity.runtime.parser.node.ASTIntegerRange;
-import org.apache.velocity.runtime.parser.node.ASTLENode;
-import org.apache.velocity.runtime.parser.node.ASTLTNode;
-import org.apache.velocity.runtime.parser.node.ASTMap;
-import org.apache.velocity.runtime.parser.node.ASTMethod;
-import org.apache.velocity.runtime.parser.node.ASTModNode;
-import org.apache.velocity.runtime.parser.node.ASTMulNode;
-import org.apache.velocity.runtime.parser.node.ASTNENode;
-import org.apache.velocity.runtime.parser.node.ASTNotNode;
-import org.apache.velocity.runtime.parser.node.ASTObjectArray;
-import org.apache.velocity.runtime.parser.node.ASTOrNode;
-import org.apache.velocity.runtime.parser.node.ASTReference;
-import org.apache.velocity.runtime.parser.node.ASTSetDirective;
-import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
-import org.apache.velocity.runtime.parser.node.ASTSubtractNode;
-import org.apache.velocity.runtime.parser.node.ASTText;
-import org.apache.velocity.runtime.parser.node.ASTTrue;
-import org.apache.velocity.runtime.parser.node.ASTWord;
-import org.apache.velocity.runtime.parser.node.ASTprocess;
-import org.apache.velocity.runtime.parser.node.ParserVisitor;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
+import org.apache.velocity.runtime.parser.node.*;
+
+import java.io.Writer;
/**
* This is the base class for all visitors.
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
index 68e0e3f2..89f09ab9 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
@@ -19,48 +19,8 @@ package org.apache.velocity.runtime.visitor;
* under the License.
*/
-import org.apache.velocity.runtime.directive.Stop;
import org.apache.velocity.runtime.parser.Token;
-import org.apache.velocity.runtime.parser.node.ASTAddNode;
-import org.apache.velocity.runtime.parser.node.ASTAndNode;
-import org.apache.velocity.runtime.parser.node.ASTAssignment;
-import org.apache.velocity.runtime.parser.node.ASTBlock;
-import org.apache.velocity.runtime.parser.node.ASTDirective;
-import org.apache.velocity.runtime.parser.node.ASTDivNode;
-import org.apache.velocity.runtime.parser.node.ASTEQNode;
-import org.apache.velocity.runtime.parser.node.ASTElseIfStatement;
-import org.apache.velocity.runtime.parser.node.ASTElseStatement;
-import org.apache.velocity.runtime.parser.node.ASTEscape;
-import org.apache.velocity.runtime.parser.node.ASTEscapedDirective;
-import org.apache.velocity.runtime.parser.node.ASTExpression;
-import org.apache.velocity.runtime.parser.node.ASTFalse;
-import org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral;
-import org.apache.velocity.runtime.parser.node.ASTGENode;
-import org.apache.velocity.runtime.parser.node.ASTGTNode;
-import org.apache.velocity.runtime.parser.node.ASTIdentifier;
-import org.apache.velocity.runtime.parser.node.ASTIfStatement;
-import org.apache.velocity.runtime.parser.node.ASTIntegerLiteral;
-import org.apache.velocity.runtime.parser.node.ASTIntegerRange;
-import org.apache.velocity.runtime.parser.node.ASTLENode;
-import org.apache.velocity.runtime.parser.node.ASTLTNode;
-import org.apache.velocity.runtime.parser.node.ASTMap;
-import org.apache.velocity.runtime.parser.node.ASTMethod;
-import org.apache.velocity.runtime.parser.node.ASTModNode;
-import org.apache.velocity.runtime.parser.node.ASTMulNode;
-import org.apache.velocity.runtime.parser.node.ASTNENode;
-import org.apache.velocity.runtime.parser.node.ASTNotNode;
-import org.apache.velocity.runtime.parser.node.ASTObjectArray;
-import org.apache.velocity.runtime.parser.node.ASTOrNode;
-import org.apache.velocity.runtime.parser.node.ASTReference;
-import org.apache.velocity.runtime.parser.node.ASTSetDirective;
-import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
-import org.apache.velocity.runtime.parser.node.ASTSubtractNode;
-import org.apache.velocity.runtime.parser.node.ASTText;
-import org.apache.velocity.runtime.parser.node.ASTTrue;
-import org.apache.velocity.runtime.parser.node.ASTWord;
-import org.apache.velocity.runtime.parser.node.ASTprocess;
-import org.apache.velocity.runtime.parser.node.Node;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
+import org.apache.velocity.runtime.parser.node.*;
/**
* This class is simply a visitor implementation