r9510 - helma/helma/trunk/src/helma/framework/core

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <[email protected]>
Author: hannes
Date: 2009-02-17 17:04:53 +0100 (Tue, 17 Feb 2009)
New Revision: 9510

Modified:
   helma/helma/trunk/src/helma/framework/core/ApplicationBean.java
Log:
Improve repository lookup code and error message.

Details at http://dev.helma.org/trac/helma/changeset/9510

Modified: helma/helma/trunk/src/helma/framework/core/ApplicationBean.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/ApplicationBean.java	2009-02-17 12:36:05 UTC (rev 9509)
+++ helma/helma/trunk/src/helma/framework/core/ApplicationBean.java	2009-02-17 16:04:53 UTC (rev 9510)
@@ -145,12 +145,12 @@
         if (obj instanceof String) {
             String path = (String) obj;
             File file = findResource(null, path);
-            if (!file.exists()) {
+            if (file == null) {
                 file = findResource(app.hopHome, path);
+                if (file == null) {
+                    throw new RuntimeException("Repository not found: " + path);
+                }
             }
-            if (!file.exists()) {
-                throw new RuntimeException("Repository path does not exist: " + file);
-            }
             if (file.isDirectory()) {
                 rep = new FileRepository(file);
             } else if (file.isFile()) {
@@ -176,20 +176,21 @@
     }
 
     /**
-     * Helper method to resolve a repository path.
+     * Helper method to resolve a repository path. Returns null if no file is found.
      * @param parent the parent file
      * @param path the repository path
-     * @return our best guess of what the file may be
+     * @return an existing file, or null
      */
     private File findResource(File parent, String path) {
         File file = new File(parent, path).getAbsoluteFile();
         if (!file.exists()) {
+            // if file does not exist, try with .zip and .js extensions appended
             file = new File(parent, path + ".zip").getAbsoluteFile();
+            if (!file.exists()) {
+                file = new File(parent, path + ".js").getAbsoluteFile();
+            }
         }
-        if (!file.exists()) {
-            file = new File(parent, path + ".js").getAbsoluteFile();
-        }
-        return file;
+        return file.exists() ? file : null;
     }
 
     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.