1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.velocity;
22
23 import java.io.InputStream;
24
25 import org.apache.struts2.util.ClassLoaderUtils;
26 import org.apache.velocity.exception.ResourceNotFoundException;
27 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
28
29
30 /***
31 * Loads resource from the Thread's context ClassLoader.
32 *
33 */
34 public class StrutsResourceLoader extends ClasspathResourceLoader {
35
36 public synchronized InputStream getResourceStream(String name) throws ResourceNotFoundException {
37 if ((name == null) || (name.length() == 0)) {
38 throw new ResourceNotFoundException("No template name provided");
39 }
40
41 if (name.startsWith("/")) {
42 name = name.substring(1);
43 }
44
45 try {
46 return ClassLoaderUtils.getResourceAsStream(name, StrutsResourceLoader.class);
47 } catch (Exception e) {
48 throw new ResourceNotFoundException(e.getMessage());
49 }
50 }
51 }