01: /**
02: *
03: */package ru.emdev.EmForge.email.velocity.resourceloaders;
04:
05: import java.io.InputStream;
06:
07: import org.apache.commons.collections.ExtendedProperties;
08: import org.apache.velocity.exception.ResourceNotFoundException;
09: import org.apache.velocity.runtime.RuntimeServices;
10: import org.apache.velocity.runtime.resource.Resource;
11: import org.apache.velocity.runtime.resource.loader.ResourceLoader;
12:
13: /**
14: * This wrapper used to cheat velocity.
15: * It gets resourceLoader from RuntimeServices
16: * and use this loader to load template.
17: * We can put our custom loader to specify source
18: * @author alasarenko
19: */
20: public class WrapperResourceLoader extends ResourceLoader {
21:
22: private ru.emdev.EmForge.email.velocity.resourceloaders.ResourceLoader resourceLoader;
23:
24: @Override
25: public long getLastModified(Resource resource) {
26: return 0;
27: }
28:
29: @Override
30: public InputStream getResourceStream(String source)
31: throws ResourceNotFoundException {
32: return getResourceLoader().getInputStreamFromResource(source);
33: }
34:
35: @Override
36: public void commonInit(RuntimeServices rs,
37: ExtendedProperties configuration) {
38: super .commonInit(rs, configuration);
39:
40: // get resourceLoader object from RuntimeServices
41: resourceLoader = (ru.emdev.EmForge.email.velocity.resourceloaders.ResourceLoader) rs
42: .getProperty("resourceLoaderImpl");
43: }
44:
45: @Override
46: public void init(ExtendedProperties configuration) {
47:
48: }
49:
50: @Override
51: public boolean isSourceModified(Resource resource) {
52: return false;
53: }
54:
55: /**
56: * @return the resourceLoader
57: */
58: private ru.emdev.EmForge.email.velocity.resourceloaders.ResourceLoader getResourceLoader() {
59: return resourceLoader;
60: }
61: }
|