01: package org.andromda.templateengines.velocity;
02:
03: import java.io.InputStream;
04:
05: import org.apache.velocity.exception.ResourceNotFoundException;
06:
07: /**
08: * Extends the default ClasspathResourceLoader in order
09: * to override getResourceAsStream(String) so that we can correctly
10: * search the ContextClassLoader instead of the system class loader.
11: * This class should be removed whenever the regular ClasspathResourceLoader
12: * in the velocity releases searches the context class loader.
13: *
14: * @author Chad Brandon
15: */
16: public class ClasspathResourceLoader
17: extends
18: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader {
19: public synchronized InputStream getResourceStream(String name)
20: throws ResourceNotFoundException {
21: InputStream result = super .getResourceStream(name);
22: if (result == null) {
23: final ClassLoader classLoader = Thread.currentThread()
24: .getContextClassLoader();
25: if (classLoader != null) {
26: result = classLoader.getResourceAsStream(name);
27: }
28: }
29: return result;
30: }
31: }
|