geirm 01/11/21 22:29:19
Modified: src/java/org/apache/velocity/app VelocityEngine.java
Log:
Same as the Velocity fix, invokeVelocimacro() just didn't work anymore
after the VM reworking about 8 months or so ago. I guess no one uses this
method. Time to deprecate ?
Revision Changes Path
1.4 +25 -63
jakarta-velocity/src/java/org/apache/velocity/app/VelocityEngine.java
Index: VelocityEngine.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/app/VelocityEngine.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- VelocityEngine.java 2001/11/02 03:28:49 1.3
+++ VelocityEngine.java 2001/11/22 06:29:19 1.4
@@ -106,7 +106,7 @@
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: VelocityEngine.java,v 1.3 2001/11/02 03:28:49 geirm Exp $
+ * @version $Id: VelocityEngine.java,v 1.4 2001/11/22 06:29:19 geirm Exp $
*/
public class VelocityEngine implements RuntimeConstants
{
@@ -368,20 +368,22 @@
return false;
}
- /**
+
+ /**
* Invokes a currently registered Velocimacro with the parms provided
* and places the rendered stream into the writer.
*
* Note : currently only accepts args to the VM if they are in the context.
*
* @param vmName name of Velocimacro to call
+ * @param logTag string to be used for template name in case of error
* @param params[] args used to invoke Velocimacro. In context key format :
* eg "foo","bar" (rather than "$foo","$bar")
* @param context Context object containing data/objects used for rendering.
* @param writer Writer for output stream
* @return true if Velocimacro exists and successfully invoked, false
otherwise.
*/
- public boolean invokeVelocimacro( String vmName, String namespace,
+ public boolean invokeVelocimacro( String vmName, String logTag,
String params[], Context context,
Writer writer )
{
@@ -390,9 +392,9 @@
*/
if ( vmName == null || params == null || context == null
- || writer == null || namespace == null)
+ || writer == null || logTag == null)
{
- ri.error( "Velocity.invokeVelocimacro() : invalid parameter");
+ ri.error( "VelocityEngine.invokeVelocimacro() : invalid parameter");
return false;
}
@@ -400,83 +402,43 @@
* does the VM exist?
*/
- if (!ri.isVelocimacro( vmName, namespace ))
+ if (!ri.isVelocimacro( vmName, logTag ))
{
- ri.error( "Velocity.invokeVelocimacro() : VM '"+ vmName
+ ri.error( "VelocityEngine.invokeVelocimacro() : VM '"+ vmName
+ "' not registered.");
return false;
}
- /*
- * apparently. Ok, make one..
- */
-
- VelocimacroProxy vp =
- (VelocimacroProxy) ri.getVelocimacro( vmName, namespace );
-
- if ( vp == null )
- {
- ri.error( "Velocity.invokeVelocimacro() : VM '"
- + vmName
- + "' : severe error. Unable to get VM from factory.");
- return false;
- }
-
- /*
- * if we get enough args?
- */
-
- if ( vp.getNumArgs() > params.length )
- {
- ri.error( "Velocity.invokeVelocimacro() : VM '"
- + vmName + "' : invalid # of args. Needed "
- + vp.getNumArgs()
- + " but called with " + params.length);
- return false;
- }
-
/*
- * ok. setup the vm
+ * now just create the VM call, and use evaluate
*/
- /*
- * fix the parms : since we don't require the $ from the caller,
- * we need to add it
- */
+ StringBuffer construct = new StringBuffer("#");
- int [] types = new int[vp.getNumArgs()];
- String[] p = new String[vp.getNumArgs()];
+ construct.append( vmName );
+ construct.append( "(" );
- for( int i = 0; i < types.length; i++)
+ for( int i = 0; i < params.length; i++)
{
- types[i] = ParserTreeConstants.JJTREFERENCE;
- p[i] = "$" + params[i];
+ construct.append( " $" );
+ construct.append( params[i] );
}
+
+ construct.append(" )");
- vp.setupMacro( p, types );
-
try
{
- InternalContextAdapterImpl ica
- = new InternalContextAdapterImpl( context );
-
- try
- {
- ica.pushCurrentTemplateName( namespace );
- vp.render( ica, writer, null);
- }
- finally
- {
- ica.popCurrentTemplateName();
- }
+ boolean retval = evaluate( context, writer,
+ logTag, construct.toString() );
+
+ return retval;
}
- catch (Exception e )
+ catch( Exception e )
{
- ri.error("Velocity.invokeVelocimacro() : " + e );
- return false;
+ ri.error( "VelocityEngine.invokeVelocimacro() : error " + e );
}
- return true;
+ return false;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>