01: package freemarker.ext.jsp;
02:
03: import freemarker.template.TemplateModelException;
04:
05: import javax.servlet.jsp.el.ExpressionEvaluator;
06: import javax.servlet.jsp.el.VariableResolver;
07: import javax.servlet.jsp.el.ELException;
08: import javax.servlet.jsp.PageContext;
09: import javax.servlet.ServletException;
10: import java.io.IOException;
11:
12: /**
13: * Implementation of PageContext that contains JSP 2.0 specific methods.
14: *
15: * @author Attila Szegedi
16: * @version $Id: FreeMarkerPageContext2.java,v 1.1.2.1 2006/07/08 14:45:34 ddekany Exp $
17: */
18: class FreeMarkerPageContext2 extends FreeMarkerPageContext {
19:
20: private FreeMarkerPageContext2() throws TemplateModelException {
21: super ();
22: }
23:
24: static FreeMarkerPageContext create() throws TemplateModelException {
25: return new FreeMarkerPageContext2();
26: }
27:
28: /**
29: * Attempts to locate and manufacture an expression evaulator instance. For this
30: * to work you <b>must</b> have the Apache Commons-EL package in the classpath. If
31: * Commons-EL is not available, this method will throw an UnsupportedOperationException.
32: */
33: public ExpressionEvaluator getExpressionEvaluator() {
34: try {
35: Class type = Thread
36: .currentThread()
37: .getContextClassLoader()
38: .loadClass(
39: "org.apache.commons.el.ExpressionEvaluatorImpl");
40: return (ExpressionEvaluator) type.newInstance();
41: } catch (Exception e) {
42: throw new UnsupportedOperationException(
43: "In order for the getExpressionEvaluator() "
44: + "method to work, you must have downloaded the apache commons-el jar and "
45: + "made it available in the classpath.");
46: }
47: }
48:
49: /**
50: * Returns a variable resolver that will resolve variables by searching through
51: * the page scope, request scope, session scope and application scope for an
52: * attribute with a matching name.
53: */
54: public VariableResolver getVariableResolver() {
55: final PageContext ctx = this ;
56:
57: return new VariableResolver() {
58: public Object resolveVariable(String name)
59: throws ELException {
60: return ctx.findAttribute(name);
61: }
62: };
63: }
64:
65: /**
66: * Includes the specified path. The flush argument is ignored!
67: */
68: public void include(String path, boolean flush) throws IOException,
69: ServletException {
70: super.include(path);
71: }
72: }
|