Author: nbubna
Date: Thu Dec 31 23:47:33 2009
New Revision: 894954
URL: http://svn.apache.org/viewvc?rev=894954&view=rev
Log:
merge recent changes from the trunk
(VELOCITY-731,VELOCITY-742,VELOCITY-727,VELOCITY-728,VELOCITY-744)
Added:
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
- copied unchanged from r894953,
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
- copied unchanged from r894953,
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity742TestCase.java
- copied unchanged from r894953,
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity742TestCase.java
Modified:
velocity/engine/branches/2.0_Exp/src/changes/changes.xml
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/Velocity.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/VelocityEngine.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeInstance.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeSingleton.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt
Modified: velocity/engine/branches/2.0_Exp/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/changes/changes.xml?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/changes/changes.xml (original)
+++ velocity/engine/branches/2.0_Exp/src/changes/changes.xml Thu Dec 31
23:47:33 2009
@@ -26,6 +26,11 @@
<body>
<release version="2.0" date="In Subversion">
+ <action type="add" dev="nbubna" issue="VELOCITY-731">
+ Remove directive.if.tostring.nullcheck crutch with intent
+ to replace testing of toString() null status with support for
+ toBoolean() (or similar) method on objects being "#if'd".
+ </action>
<action type="add" dev="nbubna">
Remove directive.set.null.allowed and instead always allow null to be
@@ -64,6 +69,21 @@
</release>
<release version="1.7" date="In Subversion">
+ <action type="add" dev="nbubna" issue="VELOCITY-744">
+ Log Velocimacro additions at debug level, as in pre-1.6 versions.
+ </action>
+
+ <action type="add" dev="nbubna" issue="VELOCITY-742" due-to="Jarkko
Viinamäki">
+ Add removeDirective(name) and loadDirective(classname) methods to allow
runtime changes to the directive set.
+ </action>
+
+ <action type="fix" dev="nbubna" issue="VELOCITY-727" due-to="Jarkko
Viinamäki">
+ Throw an informative VelocityException when #define is given no parameter
(instead of an ArrayIndexOutOfBoundsException).
+ </action>
+
+ <action type="fix" dev="nbubna" issue="VELOCITY-728" due-to="Jarkko
Viinamäki">
+ Throw an informative VelocityException when #parse is given no args
(instead of an NPE).
+ </action>
<action type="add" dev="nbubna" issue="VELOCITY-704">
Changed #stop to a directive implementation (get it out of the parser)
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/Velocity.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/Velocity.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/Velocity.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/Velocity.java
Thu Dec 31 23:47:33 2009
@@ -367,4 +367,24 @@
RuntimeSingleton.getRuntimeServices().setApplicationAttribute( key,
value);
}
+
+ /**
+ * Remove a directive.
+ *
+ * @param name name of the directive.
+ */
+ public void removeDirective(String name)
+ {
+ RuntimeSingleton.removeDirective(name);
+ }
+
+ /**
+ * Instantiates and loads the directive with some basic checks.
+ *
+ * @param directiveClass classname of directive to load
+ */
+ public void loadDirective(String directiveClass)
+ {
+ RuntimeSingleton.loadDirective(directiveClass);
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/VelocityEngine.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/VelocityEngine.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/VelocityEngine.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/VelocityEngine.java
Thu Dec 31 23:47:33 2009
@@ -395,4 +395,22 @@
return ri.getApplicationAttribute(key);
}
+ /**
+ * Remove a directive.
+ * @param name name of the directive.
+ */
+ public void removeDirective(String name)
+ {
+ ri.removeDirective(name);
+ }
+
+ /**
+ * Instantiates and loads the directive with some basic checks.
+ *
+ * @param directiveClass classname of directive to load
+ */
+ public void loadDirective(String directiveClass)
+ {
+ ri.loadDirective(directiveClass);
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeInstance.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeInstance.java
Thu Dec 31 23:47:33 2009
@@ -157,10 +157,16 @@
* This is a hashtable of initialized directives.
* The directives that populate this hashtable are
* taken from the RUNTIME_DEFAULT_DIRECTIVES
- * property file. This hashtable is passed
- * to each parser that is created.
+ * property file.
*/
- private Hashtable runtimeDirectives;
+ private Map runtimeDirectives = new Hashtable();
+ /**
+ * Copy of the actual runtimeDirectives that is shared between
+ * parsers. Whenever directives are updated, the synchronized
+ * runtimeDirectives is first updated and then an unsynchronized
+ * copy of it is passed to parsers.
+ */
+ private Map runtimeDirectivesShared;
/**
* Object that houses the configuration options for
@@ -873,12 +879,6 @@
*/
private void initializeDirectives()
{
- /*
- * Initialize the runtime directive table.
- * This will be used for creating parsers.
- */
- runtimeDirectives = new Hashtable();
-
Properties directiveProperties = new Properties();
/*
@@ -964,9 +964,10 @@
* Programatically add a directive.
* @param directive
*/
- public void addDirective(Directive directive)
+ public synchronized void addDirective(Directive directive)
{
runtimeDirectives.put(directive.getName(), directive);
+ updateSharedDirectivesMap();
}
/**
@@ -976,16 +977,31 @@
*/
public Directive getDirective(String name)
{
- return (Directive) runtimeDirectives.get(name);
+ return (Directive) runtimeDirectivesShared.get(name);
}
/**
* Remove a directive.
* @param name name of the directive.
*/
- public void removeDirective(String name)
+ public synchronized void removeDirective(String name)
{
runtimeDirectives.remove(name);
+ updateSharedDirectivesMap();
+ }
+
+ /**
+ * Makes an unsynchronized copy of the directives map
+ * that is used for Directive lookups by all parsers.
+ *
+ * This follows Copy-on-Write pattern. The cost of creating
+ * a new map is acceptable since directives are typically
+ * set and modified only during Velocity setup phase.
+ */
+ private void updateSharedDirectivesMap()
+ {
+ Map tmp = new HashMap(runtimeDirectives);
+ runtimeDirectivesShared = tmp;
}
/**
@@ -993,7 +1009,7 @@
*
* @param directiveClass classname of directive to load
*/
- private void loadDirective(String directiveClass)
+ public void loadDirective(String directiveClass)
{
try
{
@@ -1105,7 +1121,6 @@
requireInitialization();
Parser parser = new Parser(this);
- parser.setDirectives(runtimeDirectives);
return parser;
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeSingleton.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeSingleton.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeSingleton.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/RuntimeSingleton.java
Thu Dec 31 23:47:33 2009
@@ -579,4 +579,24 @@
return ri.getUberspect();
}
+
+ /**
+ * Remove a directive.
+ *
+ * @param name name of the directive.
+ */
+ public static void removeDirective(String name)
+ {
+ ri.removeDirective(name);
+ }
+
+ /**
+ * Instantiates and loads the directive with some basic checks.
+ *
+ * @param directiveClass classname of directive to load
+ */
+ public static void loadDirective(String directiveClass)
+ {
+ ri.loadDirective(directiveClass);
+ }
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/VelocimacroFactory.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
Thu Dec 31 23:47:33 2009
@@ -464,7 +464,11 @@
{
vmManager.addVM(name, macroBody, macroArgs, sourceTemplate,
replaceAllowed);
}
- return(true);
+ if (log.isDebugEnabled())
+ {
+ log.debug("added VM "+name+": source="+sourceTemplate);
+ }
+ return true;
}
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Define.java
Thu Dec 31 23:47:33 2009
@@ -24,6 +24,8 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.ParseException;
@@ -58,6 +60,13 @@
{
super.init(rs, context, node);
+ // the first child is the block name (key), the second child is the
block AST body
+ if ( node.jjtGetNumChildren() != 2 )
+ {
+ throw new VelocityException("parameter missing: block name at "
+ + Log.formatFileString(this));
+ }
+
/*
* first token is the name of the block. We don't even check the
format,
* just assume it looks like this: $block_name. Should we check if it
has
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
Thu Dec 31 23:47:33 2009
@@ -137,6 +137,15 @@
MethodInvocationException
{
/*
+ * did we get an argument?
+ */
+ if ( node.jjtGetNumChildren() == 0 )
+ {
+ throw new VelocityException("parameter missing: template name at "
+ + Log.formatFileString(this));
+ }
+
+ /*
* does it have a value? If you have a null reference, then no.
*/
Object value = node.jjtGetChild(0).value( context );
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/Parser.java
Thu Dec 31 23:47:33 2009
@@ -29,11 +29,6 @@
*/
public class Parser/*...@bgen(jjtree)*/implements ParserTreeConstants,
ParserConstants {/*...@bgen(jjtree)*/
protected JJTParserState jjtree = new JJTParserState();/**
- * This Map contains a list of all of the dynamic directives.
- */
- private Map directives = new HashMap();
-
- /**
* Keep track of defined macros, used for escape processing
*/
private Map macroNames = new HashMap();
@@ -153,28 +148,19 @@
}
/**
- * This method sets the directives Hashtable
- */
- public void setDirectives(Hashtable directives)
- {
- this.directives = new HashMap(directives);
- }
-
- /**
* This method gets a Directive from the directives Hashtable
*/
public Directive getDirective(String directive)
{
- return (Directive) directives.get(directive);
+ return (Directive) rsvc.getDirective(directive);
}
/**
- * This method finds out of the directive exists in the directives
- * Hashtable.
+ * This method finds out of the directive exists in the directives Map.
*/
public boolean isDirective(String directive)
{
- return directives.containsKey(directive);
+ return rsvc.getDirective(directive) != null;
}
@@ -797,7 +783,7 @@
directiveName = t.image.substring(1);
}
- d = (Directive) directives.get(directiveName);
+ d = getDirective(directiveName);
/*
* Velocimacro support : if the directive is macro directive
@@ -2840,6 +2826,46 @@
finally { jj_save(12, xla); }
}
+ private boolean jj_3R_62() {
+ if (jj_3R_70()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_61() {
+ if (jj_3R_24()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_60() {
+ if (jj_3R_74()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_59() {
+ if (jj_3R_73()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_58() {
+ if (jj_3R_72()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_57() {
+ if (jj_3R_71()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_56() {
+ if (jj_3R_69()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_55() {
+ if (jj_3R_42()) return true;
+ return false;
+ }
+
private boolean jj_3R_54() {
if (jj_3R_68()) return true;
return false;
@@ -3554,46 +3580,6 @@
return false;
}
- private boolean jj_3R_62() {
- if (jj_3R_70()) return true;
- return false;
- }
-
- private boolean jj_3R_61() {
- if (jj_3R_24()) return true;
- return false;
- }
-
- private boolean jj_3R_60() {
- if (jj_3R_74()) return true;
- return false;
- }
-
- private boolean jj_3R_59() {
- if (jj_3R_73()) return true;
- return false;
- }
-
- private boolean jj_3R_58() {
- if (jj_3R_72()) return true;
- return false;
- }
-
- private boolean jj_3R_57() {
- if (jj_3R_71()) return true;
- return false;
- }
-
- private boolean jj_3R_56() {
- if (jj_3R_69()) return true;
- return false;
- }
-
- private boolean jj_3R_55() {
- if (jj_3R_42()) return true;
- return false;
- }
-
/** Generated Token Manager. */
public ParserTokenManager token_source;
/** Current token. */
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Thu Dec 31 23:47:33 2009
@@ -167,7 +167,7 @@
*/
logOnNull =
rsvc.getBoolean(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID, true);
-
+
/**
* In the case we are referencing a variable with #if($foo) or
* #if( ! $foo) then we allow variables to be undefined and we
Modified: velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt?rev=894954&r1=894953&r2=894954&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt (original)
+++ velocity/engine/branches/2.0_Exp/src/parser/Parser.jjt Thu Dec 31 23:47:33
2009
@@ -106,11 +106,6 @@
public class Parser
{
/**
- * This Map contains a list of all of the dynamic directives.
- */
- private Map directives = new HashMap();
-
- /**
* Keep track of defined macros, used for escape processing
*/
private Map macroNames = new HashMap();
@@ -230,28 +225,19 @@
}
/**
- * This method sets the directives Hashtable
- */
- public void setDirectives(Hashtable directives)
- {
- this.directives = new HashMap(directives);
- }
-
- /**
* This method gets a Directive from the directives Hashtable
*/
public Directive getDirective(String directive)
{
- return (Directive) directives.get(directive);
+ return (Directive) rsvc.getDirective(directive);
}
/**
- * This method finds out of the directive exists in the directives
- * Hashtable.
+ * This method finds out of the directive exists in the directives Map.
*/
public boolean isDirective(String directive)
{
- return directives.containsKey(directive);
+ return rsvc.getDirective(directive) != null;
}
@@ -1494,7 +1480,7 @@
directiveName = t.image.substring(1);
}
- d = (Directive) directives.get(directiveName);
+ d = getDirective(directiveName);
/*
* Velocimacro support : if the directive is macro directive