diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-02-13 20:49:32 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-02-13 20:49:32 +0100 |
| commit | d111135842cca119505bed1744050b7e90579314 (patch) | |
| tree | 52388298c15bc29cc14c7409e70ebbceecbd6404 | |
| parent | f805cb7753435fa9c288b18bafb6a4791b59d071 (diff) | |
getAllTextResources finds all matching in kernel and modules
getAllBaseURLs returns all modules and kernel
findTextResource searches kernel first - no overriding
| -rw-r--r-- | src/main/java/com/c2kernel/utils/Resource.java | 35 |
1 files changed, 24 insertions, 11 deletions
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<String, String> txtCache = new Hashtable<String, String>();
static private URL baseURL;
static private HashMap<String, URL> moduleBaseURLs = new HashMap<String, URL>();
+ static private HashMap<String, URL> allBaseURLs = new HashMap<String, URL>();
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<String, URL> getModuleBaseURLs() {
return moduleBaseURLs;
}
+
+ public static HashMap<String, URL> 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<String, String> getAllTextResources(String resName) {
+ HashMap<String, String> results = new HashMap<String, String>();
+ 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
|
