geirm       01/03/20 09:28:42

  Modified:    src/java/org/apache/velocity/runtime/resource
                        ResourceManager.java
               src/java/org/apache/velocity/runtime/resource/loader
                        FileResourceLoader.java ResourceLoader.java
  Log:
  ResourceManager.java :
  
  Changed the algorithm for first-time load -
  1) We don't note which classloader we are trying - we only log which
  loader we found it in (for reference) or note failure if we
  don't find it.
  
  2) It's ok if resource.process() throws a ResourceNotFoundException -
  that doesn't indicate failure of the resource finding process - only
  when done, and no loader was able to provide the resource, is it
  considered failure, so we log as such and throw the RNFE.
  
  FileResourceLoader.java :
  
  1) Removed logging - the ResourceManager will log appropriately now.
  
  ResourceLoader.java :
  
  1) Removed the assumption that each loader will have a cache and
  modCheckInterval prop associated with it.  (Classpath loader has
  neither).  So replaced with 'safe' defaults.
  
  Revision  Changes    Path
  1.19      +39 -16    
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/ResourceManager.java
  
  Index: ResourceManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/ResourceManager.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ResourceManager.java      2001/03/17 19:19:53     1.18
  +++ ResourceManager.java      2001/03/20 17:28:26     1.19
  @@ -77,7 +77,8 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Paulo Gaspar</a>
  - * @version $Id: ResourceManager.java,v 1.18 2001/03/17 19:19:53 jvanzyl Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  + * @version $Id: ResourceManager.java,v 1.19 2001/03/20 17:28:26 geirm Exp $
    */
   public class ResourceManager
   {
  @@ -148,10 +149,12 @@
           {
               Configuration configuration = (Configuration) 
sourceInitializerList.get(i);
               String loaderClass = configuration.getString("class");
  +
               resourceLoader = ResourceLoaderFactory.getLoader(loaderClass);
               resourceLoader.commonInit(configuration);
               resourceLoader.init(configuration);
               resourceLoaders.add(resourceLoader);
  +
           }
       }
   
  @@ -168,7 +171,7 @@
           {
               return;
           }            
  -        
  +
           Vector resourceLoaderNames = 
               Runtime.getConfiguration().getVector(Runtime.RESOURCE_LOADER);
   
  @@ -310,35 +313,50 @@
                   //! Bug this is being run more then once!
                   
                   long howOldItWas = 0;  // Initialize to avoid warnings
  +
                   for (int i = 0; i < resourceLoaders.size(); i++)
                   {
                       resourceLoader = (ResourceLoader) resourceLoaders.get(i);
                       resource.setResourceLoader(resourceLoader);
  -                    
  -                    Runtime.info("Attempting to find " + resourceName + 
  -                        " with " + resourceLoader.getClassName());
                       
  - 
  -                    if (resource.process())
  +                    /*
  +                     *  catch the ResourceNotFound exception
  +                     *  as that is ok in our new multi-loader environment
  +                     */
  +
  +                    try 
                       {
  +                        if (resource.process())
  +                         {
  +                             /*
  +                              *  FIXME  (gmj)
  +                              *  moved in here - technically still 
  +                              *  a problem - but the resource needs to be 
  +                              *  processed before the loader can figure 
  +                              *  it out due to to the new 
  +                              *  multi-path support - will revisit and fix
  +                              */
  +                             Runtime.info("ResourceManager : found " + resourceName 
+ 
  +                                          " with loader " + 
resourceLoader.getClassName());
  +           
  +                             howOldItWas = resourceLoader.getLastModified( resource 
);
  +                             break;
  +                         }
  +                    }
  +                    catch( ResourceNotFoundException rnfe )
  +                    {
                           /*
  -                         *  FIXME  (gmj)
  -                         *  moved in here - technically still a problem - but the 
resource needs to be 
  -                         *  processed before the loader can figure it out due to to 
the new 
  -                         *  multi-path support - will revisit and fix
  +                         *  that's ok - it's possible to fail in
  +                         *  multi-loader environment
                            */
  -
  -                        howOldItWas = resourceLoader.getLastModified( resource );
  -                        break;
                       }
  -
                   }
                   
                   /*
                    * Return null if we can't find a resource.
                    */
                   if (resource.getData() == null)
  -                    throw new ResourceNotFoundException("Can't find " + 
resourceName + "!");
  +                    throw new ResourceNotFoundException("Unable to find resource '" 
+ resourceName + "'");
   
                   resource.setLastModified( howOldItWas );
                    
  @@ -354,6 +372,11 @@
                   
                   if (resourceLoader.isCachingOn())
                       globalCache.put(resourceName, resource);
  +            }
  +            catch( ResourceNotFoundException rnfe2 )
  +            {
  +                Runtime.error("ResourceManager : unable to find resource '" + 
resourceName + "' in any resource loader.");
  +                throw rnfe2;
               }
               catch( ParseErrorException pee )
               {
  
  
  
  1.10      +21 -5     
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
  
  Index: FileResourceLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FileResourceLoader.java   2001/03/20 00:55:04     1.9
  +++ FileResourceLoader.java   2001/03/20 17:28:35     1.10
  @@ -77,7 +77,7 @@
    * That'll change once we decide how we want to do configuration
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: FileResourceLoader.java,v 1.9 2001/03/20 00:55:04 jon Exp $
  + * @version $Id: FileResourceLoader.java,v 1.10 2001/03/20 17:28:35 geirm Exp $
    */
   public class FileResourceLoader extends ResourceLoader
   {
  @@ -95,7 +95,22 @@
   
       public void init(Configuration configuration)
       {
  +        Runtime.info("FileResourceLoader : initialization starting.");
  +        
           paths = configuration.getVector("path");
  +        
  +        /*
  +         *  lets tell people what paths we will be using
  +         */
  +
  +        int sz = paths.size();
  +
  +        for( int i=0; i < sz; i++)
  +        {
  +            Runtime.info("FileResourceLoader : adding path '" + (String) 
paths.get(i) + "'");
  +        }
  +
  +        Runtime.info("FileResourceLoader : initialization complete.");
       }
   
       /**
  @@ -161,6 +176,7 @@
                    * from so that we can check its modification
                    * time.
                    */
  +
                   templatePaths.put(templateName, path);
                   return inputStream;
               }                
  @@ -171,10 +187,10 @@
            * templates and we didn't find anything so
            * throw an exception.
            */
  -        String msg = "FileResourceLoader Error: cannot find resource " +
  -            template;
  +         String msg = "FileResourceLoader Error: cannot find resource " +
  +          template;
       
  -        Runtime.error(msg);
  +        //Runtime.error(msg);
           throw new ResourceNotFoundException( msg );
       }
       
  @@ -247,7 +263,7 @@
       {
           String path = (String) templatePaths.get(resource.getName());
           File file = new File(path, resource.getName());
  -    
  +
           if (file.canRead())
           {
               return file.lastModified();
  
  
  
  1.9       +17 -3     
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
  
  Index: ResourceLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ResourceLoader.java       2001/03/20 01:39:30     1.8
  +++ ResourceLoader.java       2001/03/20 17:28:38     1.9
  @@ -68,7 +68,8 @@
    * extend.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: ResourceLoader.java,v 1.8 2001/03/20 01:39:30 jon Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  + * @version $Id: ResourceLoader.java,v 1.9 2001/03/20 17:28:38 geirm Exp $
    */
   public abstract class ResourceLoader
   {
  @@ -97,8 +98,21 @@
        */
       public void commonInit(Configuration configuration)
       {
  -        isCachingOn = configuration.getBoolean("cache");
  -        modificationCheckInterval = 
configuration.getLong("modificationCheckInterval");
  +        /*
  +         *  these two properties are not required for all loaders.
  +         *  For example, for ClasspathLoader, what would cache mean? 
  +         *  so adding default values which I think are the safest
  +         *
  +         *  don't cache, and modCheckInterval irrelevant...
  +         */
  +
  +        isCachingOn = configuration.getBoolean("cache", false);
  +        modificationCheckInterval = 
configuration.getLong("modificationCheckInterval", 0);
  +        
  +        /*
  +         * this is a must!
  +         */
  +
           className = configuration.getString("class");
       }
   
  
  
  

Reply via email to