01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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: return new JellyServletContext(this, ctx);
69: }
70: }
|