01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.velocity;
06:
07: import com.opensymphony.webwork.util.ClassLoaderUtils;
08: import org.apache.velocity.exception.ResourceNotFoundException;
09: import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
10:
11: import java.io.InputStream;
12:
13: /**
14: * Loads resource from the Thread's context ClassLoader.
15: *
16: * @author $Author: plightbo $
17: * @version $Revision: 1282 $
18: */
19: public class WebWorkResourceLoader extends ClasspathResourceLoader {
20:
21: public synchronized InputStream getResourceStream(String name)
22: throws ResourceNotFoundException {
23: if ((name == null) || (name.length() == 0)) {
24: throw new ResourceNotFoundException(
25: "No template name provided");
26: }
27:
28: if (name.startsWith("/")) {
29: name = name.substring(1);
30: }
31:
32: try {
33: return ClassLoaderUtils.getResourceAsStream(name,
34: WebWorkResourceLoader.class);
35: } catch (Exception e) {
36: throw new ResourceNotFoundException(e.getMessage());
37: }
38: }
39: }
|