From d111135842cca119505bed1744050b7e90579314 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 13 Feb 2013 20:49:32 +0100 Subject: getAllTextResources finds all matching in kernel and modules getAllBaseURLs returns all modules and kernel findTextResource searches kernel first - no overriding --- src/main/java/com/c2kernel/utils/Resource.java | 35 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/c2kernel/utils/Resource.java b/src/main/java/com/c2kernel/utils/Resource.java index 541c2dc..5a3a038 100644 --- a/src/main/java/com/c2kernel/utils/Resource.java +++ b/src/main/java/com/c2kernel/utils/Resource.java @@ -18,9 +18,11 @@ public class Resource { static private Hashtable txtCache = new Hashtable(); static private URL baseURL; static private HashMap moduleBaseURLs = new HashMap(); + static private HashMap allBaseURLs = new HashMap(); public static void initKernelBaseURL() throws InvalidDataException { baseURL = getURLorResURL("com/c2kernel/utils/resources/"); + allBaseURLs.put(null, baseURL); } public static URL getKernelBaseURL() { @@ -33,6 +35,7 @@ public class Resource { public static void addModuleBaseURL(String ns, URL newBaseURL) { moduleBaseURLs.put(ns, newBaseURL); + allBaseURLs.put(ns, newBaseURL); Logger.msg("Adding resource URL for "+ns+": "+newBaseURL.toString()); } @@ -47,6 +50,10 @@ public class Resource { public static HashMap getModuleBaseURLs() { return moduleBaseURLs; } + + public static HashMap getAllBaseURLs() { + return allBaseURLs; + } static public URL getModuleResourceURL(String ns, String resName) throws MalformedURLException { return new URL(moduleBaseURLs.get(ns), resName); @@ -72,17 +79,23 @@ public class Resource { **************************************************************************/ static public String findTextResource(String resName) { - try { - for (String ns : getModuleBaseURLs().keySet()) { - try { - return getTextResource(ns, resName); - } catch (ObjectNotFoundException ex) { } - } - return getTextResource(null, resName); - } catch (ObjectNotFoundException ex) { - Logger.warning("Text resource '"+resName+"' not found."); - return null; - } + for (String ns : getAllBaseURLs().keySet()) { + try { + return getTextResource(ns, resName); + } catch (ObjectNotFoundException ex) { } + } + Logger.warning("Text resource '"+resName+"' not found."); + return null; + } + + static public HashMap getAllTextResources(String resName) { + HashMap results = new HashMap(); + for (String ns : getAllBaseURLs().keySet()) { + try { + results.put(ns, getTextResource(ns, resName)); + } catch (ObjectNotFoundException ex) { } + } + return results; } static public String getTextResource(String ns, String resName) throws ObjectNotFoundException -- cgit v1.2.3