geirm       01/02/05 21:11:17

  Modified:    src/java/org/apache/velocity Template.java
  Log:
  Making sure the popTemplateName() is in a finally to keep the Context clean in
  case something goes 'bing'.
  
  Revision  Changes    Path
  1.24      +33 -17    jakarta-velocity/src/java/org/apache/velocity/Template.java
  
  Index: Template.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Template.java     2001/02/05 04:31:06     1.23
  +++ Template.java     2001/02/06 05:11:16     1.24
  @@ -87,7 +87,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Template.java,v 1.23 2001/02/05 04:31:06 geirm Exp $
  + * @version $Id: Template.java,v 1.24 2001/02/06 05:11:16 geirm Exp $
    */
   public class Template extends Resource
   {
  @@ -143,23 +143,30 @@
           
           InternalContextAdapterImpl ica = new InternalContextAdapterImpl(  new 
VelocityContext() );
   
  -        /*
  -         *  put the current template name on the stack
  -         */
  -
  -        ica.pushCurrentTemplateName( name );
  +        try
  +        {
  +            /*
  +             *  put the current template name on the stack
  +             */
   
  -        /*
  -         *  init the AST
  -         */
  +            ica.pushCurrentTemplateName( name );
  +            
  +            /*
  +             *  init the AST
  +             */
   
  -        ((SimpleNode)data).init( ica, null);
  +            ((SimpleNode)data).init( ica, null);
  +        }
  +        finally
  +        {
  +            /*  
  +             *  in case something blows up...
  +             *  pull it off for completeness
  +             */
   
  -        /*
  -         *  pull it off for completeness
  -         */
  +            ica.popCurrentTemplateName();
  +        }
   
  -        ica.popCurrentTemplateName();
       }
   
       /**
  @@ -184,11 +191,20 @@
   
               InternalContextAdapterImpl ica = new InternalContextAdapterImpl( 
context );
   
  -            ica.pushCurrentTemplateName( name );
  +            try
  +            {
  +                ica.pushCurrentTemplateName( name );
   
  -            ( (SimpleNode) data ).render( ica, writer);
  +                ( (SimpleNode) data ).render( ica, writer);
  +            }
  +            finally
  +            {
  +                /*
  +                 *  lets make sure that we always clean up the context 
  +                 */
   
  -            ica.popCurrentTemplateName();
  +                ica.popCurrentTemplateName();
  +            }
           }
           else
               Runtime.error("Template.merge() failure. The document is null, " + 
  
  
  

Reply via email to