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
12
13
14
15
16 @Override
17 public InputStream getResourceStream(String theArg0) throws ResourceNotFoundException {
18 System.out.println("** Trying to load: " + theArg0);
19
20 InputStream resourceStream = ResourceLoader.class.getResourceAsStream(theArg0);
21 if (resourceStream == null) {
22 resourceStream = ResourceLoader.class.getResourceAsStream("/" + theArg0);
23 }
24 if (resourceStream == null) {
25 throw new ResourceNotFoundException("Can not find: " + theArg0);
26 }
27
28 return resourceStream;
29 }
30
31
32
33
34
35
36
37
38 @Override
39 public boolean resourceExists(String theArg0) {
40 System.out.println("** Checking Exists: " + theArg0);
41 boolean resourceExists = super.resourceExists(theArg0);
42 System.out.println("** Exists: " + resourceExists);
43 return resourceExists;
44 }
45
46 public static void main(String[] args) {
47 new ResourceLoader().getResourceStream("ca/uhn/hl7v2/sourcegen/templates/group.vsm");
48 }
49
50 }