jvanzyl     00/11/15 17:55:43

  Modified:    src/java/org/apache/velocity/runtime/directive Include.java
  Log:
  - made the include work with the new include.path property. you can
    now set multiple include paths. i would like to have a caching property
    set for each path so that you selectively cache templates based on
    where they are located.
  
  Revision  Changes    Path
  1.3       +25 -5     
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Include.java
  
  Index: Include.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Include.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Include.java      2000/11/12 06:38:47     1.2
  +++ Include.java      2000/11/16 01:55:43     1.3
  @@ -91,7 +91,8 @@
    *    special separator.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Include.java,v 1.2 2000/11/12 06:38:47 geirm Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  + * @version $Id: Include.java,v 1.3 2000/11/16 01:55:43 jvanzyl Exp $
    */
   public class Include extends Directive
   {
  @@ -186,7 +187,8 @@
            *  everything must be under the template root TEMPLATE_PATH
            */
           
  -        String strTemplatePath = Runtime.getString(Runtime.TEMPLATE_PATH);
  +        //String strTemplatePath = Runtime.getString(Runtime.TEMPLATE_PATH);
  +        String[] includePaths = Runtime.getIncludePaths();
           
           /*
            *  for security, we will not accept anything with .. in the path
  @@ -209,7 +211,25 @@
            *  we will put caching here in the future...
            */
   
  -        File file = new File(strTemplatePath, strArg);
  +        // Try to locate the file in all of the possible
  +        // locations. If we can't even find a trace of existence
  +        // report the problem and leave.
  +        File file = null;
  +        for (int i = 0; i < includePaths.length; i++)
  +        {
  +            file = new File(includePaths[i], strArg);
  +            
  +            if (file.exists())
  +                break;
  +            else
  +                file = null;
  +        }
  +    
  +        if (file == null)
  +        {
  +            Runtime.error("#include() : " + strArg + " doesn't exist!");
  +            return false;
  +        }            
           
           try
           {
  @@ -221,12 +241,12 @@
               while ( ( iLen = reader.read( buf, 0, 1024 )) != -1)
                   writer.write( buf,0,iLen );
           }
  -        catch ( FileNotFoundException e ) 
  +        catch ( Exception e ) 
           {
               Runtime.error( new String("#include() : " + e ));
               return false;
           }
  -
  +    
           return true;
       }    
   
  
  
  

Reply via email to