From 829d4ead3c29d1407d05c06558353b2847a6e481 Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 17 Feb 2009 16:04:53 +0000 Subject: [PATCH] Improve repository lookup code and error message. --- src/helma/framework/core/ApplicationBean.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/helma/framework/core/ApplicationBean.java b/src/helma/framework/core/ApplicationBean.java index 13b2bb26..1fd2ddd5 100644 --- a/src/helma/framework/core/ApplicationBean.java +++ b/src/helma/framework/core/ApplicationBean.java @@ -145,11 +145,11 @@ public class ApplicationBean implements Serializable { 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.exists()) { - throw new RuntimeException("Repository path does not exist: " + file); + if (file == null) { + throw new RuntimeException("Repository not found: " + path); + } } if (file.isDirectory()) { rep = new FileRepository(file); @@ -176,20 +176,21 @@ public class ApplicationBean implements Serializable { } /** - * 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; } /**