geirm       01/03/19 09:19:38

  Modified:    src/java/org/apache/velocity/app Velocity.java
  Log:
  Made changes to signatures to support the new MethodInvocationException
  and rewrote evaluate() do propogate the correct exceptions
  
  Revision  Changes    Path
  1.9       +57 -43    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Velocity.java     2001/03/19 00:57:56     1.8
  +++ Velocity.java     2001/03/19 17:19:36     1.9
  @@ -59,6 +59,7 @@
   import java.util.Properties;
   import java.io.ByteArrayInputStream;
   import java.io.InputStream;
  +import java.io.IOException;
   
   import org.apache.velocity.context.Context;
   import org.apache.velocity.Template;
  @@ -71,7 +72,11 @@
   
   import org.apache.velocity.exception.ResourceNotFoundException;
   import org.apache.velocity.exception.ParseErrorException;
  +import org.apache.velocity.exception.MethodInvocationException;
   
  +import org.apache.velocity.runtime.parser.ParseException;
  +
  +
   /**
    * This class provides  services to the application 
    * developer, such as :
  @@ -96,7 +101,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.8 2001/03/19 00:57:56 geirm Exp $
  + * @version $Id: Velocity.java,v 1.9 2001/03/19 17:19:36 geirm Exp $
    */
   
   public class Velocity implements RuntimeConstants
  @@ -182,6 +187,7 @@
        */
       public static  boolean evaluate( Context context,  Writer out,  
                                        String logTag, String instring )
  +        throws ParseErrorException, MethodInvocationException, IOException
       {
           ByteArrayInputStream inStream = 
               new ByteArrayInputStream( instring.getBytes() );
  @@ -205,37 +211,58 @@
        */
       public static boolean evaluate( Context context, Writer writer, 
                                       String logTag, InputStream instream )
  +        throws ParseErrorException, MethodInvocationException, IOException
       {
           SimpleNode nodeTree = null;
  +        
  +        /*
  +         *  first, parse - convert ParseException if thrown
  +         */
   
           try
           {
               nodeTree = Runtime.parse( instream, logTag );        
  - 
  -            if (nodeTree != null)
  +        }
  +        catch ( ParseException pex )
  +        {
  +            throw  new ParseErrorException( pex.getMessage() );
  +        }                
  +     
  +        /*
  +         * now we want to init and render
  +         */
  +
  +        if (nodeTree != null)
  +        {
  +            InternalContextAdapterImpl ica = 
  +                new InternalContextAdapterImpl( context );
  +            
  +            ica.pushCurrentTemplateName( logTag );
  +            
  +            try
               {
  -                InternalContextAdapterImpl ica = 
  -                    new InternalContextAdapterImpl( context );
  -                
  -                ica.pushCurrentTemplateName( logTag );
  -                nodeTree.init( ica, null );
  -                
                   try
                   {
  -                    nodeTree.render( ica, writer );
  +                    nodeTree.init( ica, null );
                   }
  -                finally
  +                catch( Exception e )
                   {
  -                    ica.popCurrentTemplateName();
  +                    Runtime.error("Velocity.evaluate() : init exception for tag = " 
  +                                  + logTag + " : " + e );
                   }
  -                       
  -                return true;
  +                
  +                /*
  +                 *  now render, and let any exceptions fly
  +                 */
  +
  +                nodeTree.render( ica, writer );
               }
  -        }
  -        catch( Exception e )
  -        {
  -            Runtime.error("Velocity.evaluate() : tag = " 
  -                          + logTag + " : " + e );
  +            finally
  +            {
  +                ica.popCurrentTemplateName();
  +            }
  +            
  +            return true;
           }
           
           return false;
  @@ -364,34 +391,21 @@
        */
       public static boolean mergeTemplate( String templateName, 
                                            Context context, Writer writer )
  -        throws ResourceNotFoundException, ParseErrorException, Exception
  +        throws ResourceNotFoundException, ParseErrorException, 
MethodInvocationException, Exception
       {
  -        try
  -        {
  -            Template template = Runtime.getTemplate(templateName);
  -
  -            if ( template == null )
  -            {
  -                Runtime.error("Velocity.parseTemplate() failed loading template '" 
  -                              + templateName + "'" );
  -            }
  -            else
  -            {
  -                template.merge(context, writer);
  -            }
  -
  -            return true;
  -        }
  -        catch( ResourceNotFoundException rnfe )
  +        Template template = Runtime.getTemplate(templateName);
  +        
  +        if ( template == null )
           {
  +            Runtime.error("Velocity.parseTemplate() failed loading template '" 
  +                          + templateName + "'" );
  +            return false;
           }
  -        catch( Exception e )
  +        else
           {
  -            Runtime.error("Velocity.parseTemplate() with " 
  -                          + templateName + " : " + e );
  -        }
  -
  -        return false;
  +            template.merge(context, writer);
  +            return true;
  +         }
       }
   
       /**
  
  
  

Reply via email to