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