1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.builders;
12
13 import org.mule.config.ConfigurationException;
14 import org.mule.util.FileUtils;
15
16 import java.io.File;
17 import java.io.InputStream;
18
19 import javax.servlet.ServletContext;
20
21
22
23
24
25
26 public class WebappMuleXmlConfigurationBuilder extends MuleXmlConfigurationBuilder
27 {
28 private ServletContext context;
29
30
31
32
33
34 private String webappClasspath;
35
36 public WebappMuleXmlConfigurationBuilder(ServletContext context, String webappClasspath)
37 throws ConfigurationException
38 {
39 super();
40 this.context = context;
41 this.webappClasspath = webappClasspath;
42 }
43
44
45
46
47 protected InputStream loadResource(String resource) throws ConfigurationException
48 {
49 String resourcePath = resource;
50 InputStream is = null;
51 if (webappClasspath != null)
52 {
53 resourcePath = new File(webappClasspath, resource).getPath();
54 is = context.getResourceAsStream(resourcePath);
55 }
56 if (is == null)
57 {
58 is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
59 }
60 if (logger.isDebugEnabled())
61 {
62 if (is != null)
63 {
64 logger.debug("Resource " + resource + " is found in Servlet Context.");
65 }
66 else
67 {
68 logger.debug("Resource " + resourcePath + " is not found in Servlet Context, loading from classpath or as external file");
69 }
70 }
71 if (is == null && webappClasspath != null)
72 {
73 resourcePath = FileUtils.newFile(webappClasspath, resource).getPath();
74 try
75 {
76 is = super.loadResource(resourcePath);
77 }
78 catch (ConfigurationException ex)
79 {
80 logger.debug("Resource " + resourcePath + " is not found in filesystem");
81 }
82 }
83 if (is == null)
84 {
85 is = super.loadResource(resource);
86
87 }
88 return is;
89 }
90 }