geirm       01/12/09 11:28:24

  Modified:    src/java/org/apache/velocity/app Tag: VEL_1_2_BRANCH
                        Velocity.java VelocityEngine.java
  Log:
  Fix (backporting the 1.3 fix) - its clear that these aren't being used,
  but want them to be right..
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.23.2.1  +21 -60    jakarta-velocity/src/java/org/apache/velocity/app/Velocity.java
  
  Index: Velocity.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/app/Velocity.java,v
  retrieving revision 1.23
  retrieving revision 1.23.2.1
  diff -u -r1.23 -r1.23.2.1
  --- Velocity.java     2001/09/07 05:05:14     1.23
  +++ Velocity.java     2001/12/09 19:28:24     1.23.2.1
  @@ -108,7 +108,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
    * @author <a href="[EMAIL PROTECTED]">Christoph Reck</a>
    * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: Velocity.java,v 1.23 2001/09/07 05:05:14 geirm Exp $
  + * @version $Id: Velocity.java,v 1.23.2.1 2001/12/09 19:28:24 geirm Exp $
    */
   
   public class Velocity implements RuntimeConstants
  @@ -376,13 +376,14 @@
        *  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 identify as 'template' in logging
        *  @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 static  boolean invokeVelocimacro( String vmName, String namespace, 
  +    public static  boolean invokeVelocimacro( String vmName, String logTag, 
                                                 String params[], Context context, 
                                                 Writer writer )
       {
  @@ -391,7 +392,7 @@
            */
   
           if ( vmName == null ||  params == null ||  context == null 
  -             || writer == null || namespace == null)
  +             || writer == null || logTag == null)
           {
               RuntimeSingleton.error( "Velocity.invokeVelocimacro() : invalid 
parameter");
               return false;
  @@ -401,7 +402,7 @@
            * does the VM exist?
            */
             
  -        if (!RuntimeSingleton.isVelocimacro( vmName, namespace ))
  +        if (!RuntimeSingleton.isVelocimacro( vmName, logTag ))
           {
               RuntimeSingleton.error( "Velocity.invokeVelocimacro() : VM '"+ vmName 
                              + "' not registered.");
  @@ -409,75 +410,35 @@
           }
   
           /*
  -         * apparently.  Ok, make one..
  +         *  now just create the VM call, and use evaluate
            */
  -           
  -        VelocimacroProxy vp = 
  -            (VelocimacroProxy) RuntimeSingleton.getVelocimacro( vmName, namespace );
  -        
  -        if ( vp == null )
  -        {
  -            RuntimeSingleton.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 )
  -        {
  -            RuntimeSingleton.error( "Velocity.invokeVelocimacro() : VM '" 
  -                           + vmName + "' : invalid # of args.  Needed " 
  -                           + vp.getNumArgs() 
  -                           + " but called with " + params.length);
  -            return false;
  -        }
  -
  -        /*
  -         *  ok.  setup the vm
  -         */
   
  -        /*
  -         *  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] );
           }
   
  -        vp.setupMacro( p, types  );
  -      
  +        construct.append(" )");
  +
           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 )
           {
  -            RuntimeSingleton.error("Velocity.invokeVelocimacro() : " + e );
  -            return false;
  +            RuntimeSingleton.error( "Velocity.invokeVelocimacro() : error " + e );
           }
           
  -        return true;
  +        return false;
       }
   
       /**
  
  
  
  1.2.2.1   +23 -62    
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.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- VelocityEngine.java       2001/09/07 05:05:14     1.2
  +++ VelocityEngine.java       2001/12/09 19:28:24     1.2.2.1
  @@ -106,7 +106,7 @@
    * </p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
  - * @version $Id: VelocityEngine.java,v 1.2 2001/09/07 05:05:14 geirm Exp $
  + * @version $Id: VelocityEngine.java,v 1.2.2.1 2001/12/09 19:28:24 geirm Exp $
    */
   public class VelocityEngine implements RuntimeConstants
   {
  @@ -375,13 +375,14 @@
        *  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 use to indentify 'template' in logs
        *  @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 +391,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 +401,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..
  +         *  now just create the VM call, and use evaluate
            */
  -           
  -        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
  -         */
   
  -        /*
  -         *  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] );
           }
   
  -        vp.setupMacro( p, types  );
  -      
  +        construct.append(" )");
  +
           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]>

Reply via email to