KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > velocity > WebWorkResourceLoader


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.velocity;
6
7 import org.apache.velocity.exception.ResourceNotFoundException;
8 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
9
10 import java.io.InputStream JavaDoc;
11
12 import com.opensymphony.webwork.util.ClassLoaderUtils;
13
14
15 /**
16  * Loads resource from the Thread's context ClassLoader.
17  *
18  * @author $Author: plightbo $
19  * @version $Revision: 1.3 $
20  */

21 public class WebWorkResourceLoader extends ClasspathResourceLoader {
22     //~ Methods ////////////////////////////////////////////////////////////////
23

24     public synchronized InputStream JavaDoc getResourceStream(String JavaDoc name) throws ResourceNotFoundException {
25         if ((name == null) || (name.length() == 0)) {
26             throw new ResourceNotFoundException("No template name provided");
27         }
28
29         if (name.startsWith("/")) {
30             name = name.substring(1);
31         }
32
33         try {
34             return ClassLoaderUtils.getResourceAsStream(name, WebWorkResourceLoader.class);
35         } catch (Exception JavaDoc e) {
36             throw new ResourceNotFoundException(e.getMessage());
37         }
38     }
39 }
40
Popular Tags