01: package org.romaframework.aspect.view.echo2;
02:
03: import java.io.File;
04: import java.util.HashMap;
05:
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08: import org.romaframework.core.Utility;
09: import org.romaframework.core.config.RomaApplicationContext;
10:
11: public class WebResourseResolver {
12: private HashMap<String, String> cache = new HashMap<String, String>();
13: public static String BASE_FOLDER_NAME = "base";
14: public static String CUSTOM_FOLDER_NAME = "custom";
15: public static final char SEPARATOR = '/';
16: private String basePath;
17: private static Log log = LogFactory
18: .getLog(WebResourseResolver.class);
19:
20: public String getResource(String iName) {
21: String path = cache.get(iName);
22: if (path != null)
23: return path;
24:
25: synchronized (cache) {
26: if (basePath == null) {
27: basePath = RomaApplicationContext.getApplicationPath();
28:
29: if (basePath.charAt(basePath.length() - 1) != SEPARATOR)
30: // APPEND THE SEPARATOR
31: basePath += SEPARATOR;
32: }
33:
34: int pos = iName.indexOf(SEPARATOR);
35: String first = pos > -1 ? iName.substring(0, pos) : "";
36: String second = pos > -1 ? iName.substring(pos + 1) : iName;
37:
38: File file = new File(basePath + first + "/"
39: + CUSTOM_FOLDER_NAME + "/" + second);
40:
41: log
42: .info("[WebResourseResolver.getResource] Try to resolving path: "
43: + iName + " to: " + file.getAbsolutePath());
44:
45: if (!file.exists()) {
46: file = new File(basePath + first + "/"
47: + BASE_FOLDER_NAME + "/" + second);
48: log
49: .info("[WebResourseResolver.getResource] Try to resolving path: "
50: + iName
51: + " to: "
52: + file.getAbsolutePath());
53: if (!file.exists())
54: return null;
55: }
56:
57: log
58: .info("[WebResourseResolver.getResource] Resolved path: "
59: + iName + " to: " + file.getAbsolutePath());
60:
61: path = file.getAbsolutePath().substring(basePath.length());
62: path = Utility.getUniversalResourcePath(path);
63:
64: cache.put(iName, path);
65: }
66:
67: return path;
68: }
69: }
|