View Javadoc

1   package ca.uhn.hl7v2.sourcegen.util;
2   
3   import java.io.InputStream;
4   
5   import org.apache.velocity.exception.ResourceNotFoundException;
6   import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
7   
8   public class ResourceLoader extends ClasspathResourceLoader {
9   
10  	/*
11  	 * (non-Javadoc)
12  	 * 
13  	 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader#
14  	 * getResourceStream(java.lang.String)
15  	 */
16  	@Override
17  	public InputStream getResourceStream(String theArg0) throws ResourceNotFoundException {
18  		InputStream resourceStream = ResourceLoader.class.getResourceAsStream(theArg0);
19  		if (resourceStream == null) {
20  			resourceStream = ResourceLoader.class.getResourceAsStream("/" + theArg0);
21  		}
22  		if (resourceStream == null) {
23  			throw new ResourceNotFoundException("Can not find: " + theArg0);
24  		}
25  
26  		return resourceStream;
27  	}
28  
29  	/*
30  	 * (non-Javadoc)
31  	 * 
32  	 * @see
33  	 * org.apache.velocity.runtime.resource.loader.ResourceLoader#resourceExists
34  	 * (java.lang.String)
35  	 */
36  	@Override
37  	public boolean resourceExists(String theArg0) {
38  		boolean resourceExists = super.resourceExists(theArg0);
39  		return resourceExists;
40  	}
41  	
42  	public static void main(String[] args) {
43  		new ResourceLoader().getResourceStream("ca/uhn/hl7v2/sourcegen/templates/messages.vsm");
44  	}
45  
46  }