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