Author: nbubna
Date: Tue Aug  7 16:02:18 2007
New Revision: 563695

URL: http://svn.apache.org/viewvc?view=rev&rev=563695
Log:
fix some classpath resource loading issues

Modified:
    
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
    
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
    
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityView.java

Modified: 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java?view=diff&rev=563695&r1=563694&r2=563695
==============================================================================
--- 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
 (original)
+++ 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
 Tue Aug  7 16:02:18 2007
@@ -321,6 +321,15 @@
     }
 
     /**
+     * @see #findInClasspath(String path, Object caller)
+     */
+    public static FactoryConfiguration findInClasspath(String path)
+    {
+        // pretend this was called by a non-static ConfigurationUtils
+        return findInClasspath(path, new ConfigurationUtils());
+    }
+
+    /**
      * Searches the classpath for a configuration file matching the
      * specified path.  If found, it will read and return it as a
      * [EMAIL PROTECTED] FactoryConfiguration}.  If not found, this will return
@@ -329,10 +338,10 @@
      * (i.e. the last one will have precedence).
      * @see ClassUtils#getResources(String path)
      */
-    public static FactoryConfiguration findInClasspath(String path)
+    public static FactoryConfiguration findInClasspath(String path, Object 
caller)
     {
         // find all resources at this path
-        List<URL> found = ClassUtils.getResources(path);
+        List<URL> found = ClassUtils.getResources(path, caller);
         if (found.isEmpty())
         {
             return null;

Modified: 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java?view=diff&rev=563695&r1=563694&r2=563695
==============================================================================
--- 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
 (original)
+++ 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
 Tue Aug  7 16:02:18 2007
@@ -91,25 +91,14 @@
         }
         else
         {
-            // try and get the stream straight from this class
-            // as this seems to work with our ant-driven junit tests and 
-            // the other methods do not
-            InputStream is = getClass().getResourceAsStream(path);
-            if (is != null)
+            String msg = "Could not find configuration file at: "+path;
+            if (log != null)
             {
-                read(path, is, required, log);
+                log.debug(msg);
             }
-            else
+            if (required)
             {
-                String msg = "Could not find configuration file at: "+path;
-                if (log != null)
-                {
-                    log.debug(msg);
-                }
-                if (required)
-                {
-                    throw new ResourceNotFoundException(msg);
-                }
+                throw new ResourceNotFoundException(msg);
             }
         }
     }
@@ -134,7 +123,7 @@
         }
         
         // then search the classpath
-        URL url = ClassUtils.getResource(path);
+        URL url = ClassUtils.getResource(path, this);
         if (url != null)
         {
             return url;

Modified: 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityView.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityView.java?view=diff&rev=563695&r1=563694&r2=563695
==============================================================================
--- 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityView.java
 (original)
+++ 
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityView.java
 Tue Aug  7 16:02:18 2007
@@ -104,7 +104,6 @@
  *
  * @version $Id: VelocityView.java 511959 2007-02-26 19:24:39Z nbubna $
  */
-
 public class VelocityView
 {
     /** The HTTP content type context key. */
@@ -469,6 +468,13 @@
                               : "."));
         }
 
+        // this gets the auto loaded config from the classpath
+        // this doesn't include defaults since they're handled already
+        // and it could theoretically pick up an auto-loaded config from the
+        // filesystem, but that is highly unlikely to happen in a webapp env
+        FactoryConfiguration autoLoaded = 
ConfigurationUtils.getAutoLoaded(false);
+        factoryConfig.addConfiguration(autoLoaded);
+
         // check for application-wide user config in the context init params
         String appToolsPath = servletContext.getInitParameter(TOOLS_KEY);
         setConfig(factoryConfig, appToolsPath, true);
@@ -553,7 +559,7 @@
     protected InputStream getInputStream(String path, boolean required)
     {
         // first, search the classpath
-        InputStream inputStream = ClassUtils.getResourceAsStream(path);
+        InputStream inputStream = ClassUtils.getResourceAsStream(path, this);
         if (inputStream == null)
         {
             // then, try the servlet context
@@ -582,7 +588,7 @@
         // if we still haven't found one
         if (inputStream == null)
         {
-            String msg = "Could not find file at: "+path;
+            String msg = "Could not find resource at: "+path;
             getLog().debug(msg);
             if (required)
             {


Reply via email to