1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.apache.commons.jelly.servlet;
18  
19  import org.apache.commons.jelly.JellyContext;
20  
21  import javax.servlet.ServletContext;
22  import java.io.InputStream;
23  import java.net.MalformedURLException;
24  import java.net.URL;
25  
26  /***
27   *
28   * @author <a href="mailto:kelvint@apache.org">Kelvin Tan</a>
29   * @version 1.1
30   */
31  public class JellyServletContext extends JellyContext {
32  
33      private ServletContext ctx;
34  
35      public JellyServletContext() {
36      }
37  
38      public JellyServletContext(ServletContext ctx) {
39          super();
40          this.ctx = ctx;
41      }
42  
43      public JellyServletContext(JellyContext parent, ServletContext ctx) {
44          super(parent);
45          this.ctx = ctx;
46      }
47  
48      /***
49       * Allow access of relative URIs when performing <j:include>.
50       * @param s
51       * @return
52       * @throws MalformedURLException
53       */
54      public URL getResource(String s) throws MalformedURLException {
55          return ctx.getResource(s);
56      }
57  
58      /***
59       * Allow access of relative URIs when performing <j:include>.
60       * @param s
61       * @return
62       */
63      public InputStream getResourceAsStream(String s) {
64          return ctx.getResourceAsStream(s);
65      }
66  
67      protected JellyContext createChildContext()
68      {
69          return new JellyServletContext(this, ctx);
70      }
71  }