| 1 | |
package org.webslinger; |
| 2 | |
|
| 3 | |
import org.apache.commons.vfs.FileObject; |
| 4 | |
|
| 5 | |
import org.webslinger.commons.vfs.CachingLister; |
| 6 | |
import org.webslinger.commons.vfs.ReloadingCachingLister; |
| 7 | |
import org.webslinger.lang.ConcurrentCache; |
| 8 | |
|
| 9 | 0 | public final class StandardThemingCachingLister implements ThemingFactory<CachingLister> { |
| 10 | |
private final String themeSubDir; |
| 11 | |
private final FileObject root; |
| 12 | 0 | private final ConcurrentCache<String, CachingLister> listers = new ConcurrentCache<String, CachingLister>(StandardThemingCachingLister.class, "listers", null, ConcurrentCache.SOFT) { |
| 13 | |
protected CachingLister createValue(String key) throws Exception { |
| 14 | 0 | return new ReloadingCachingLister(root.resolveFile(key + "/" + themeSubDir)); |
| 15 | |
} |
| 16 | |
}; |
| 17 | |
|
| 18 | 0 | public StandardThemingCachingLister(FileObject root, String themeSubDir) { |
| 19 | 0 | this.root = root; |
| 20 | 0 | this.themeSubDir = themeSubDir; |
| 21 | 0 | } |
| 22 | |
|
| 23 | |
public CachingLister getThemedObject(String themePath) { |
| 24 | |
try { |
| 25 | 0 | return listers.get(themePath); |
| 26 | 0 | } catch (RuntimeException e) { |
| 27 | 0 | throw e; |
| 28 | 0 | } catch (Exception e) { |
| 29 | 0 | throw (InternalError) new InternalError(e.getMessage()).initCause(e); |
| 30 | |
} |
| 31 | |
} |
| 32 | |
} |