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