01: package com.mockrunner.mock.web;
02:
03: import javax.servlet.Servlet;
04: import javax.servlet.ServletContext;
05: import javax.servlet.ServletRequest;
06: import javax.servlet.ServletResponse;
07: import javax.servlet.jsp.JspApplicationContext;
08: import javax.servlet.jsp.JspEngineInfo;
09: import javax.servlet.jsp.JspFactory;
10: import javax.servlet.jsp.PageContext;
11:
12: import org.apache.jasper.runtime.JspApplicationContextImpl;
13:
14: /**
15: * This implementation of <code>JspFactory</code>
16: * provides full support of the <b>Unified Expression Language</b>
17: * API. Expression evaluation is available only for the <b>Unified
18: * Expression Language</b> API, not for the pre JSP 2.1
19: * <code>javax.servlet.jsp.el</code> Expression Language API.
20: */
21: public class JasperJspFactory extends JspFactory {
22: private WebMockObjectFactory mockFactory;
23: private JspEngineInfo engineInfo;
24: private JspApplicationContextImpl applicationContext;
25:
26: public JasperJspFactory() {
27: engineInfo = new MockJspEngineInfo();
28: }
29:
30: /**
31: * Configures this implementation for EL support.
32: * Use
33: * <code>getWebMockObjectFactory().setDefaultJspFactory(new JasperJspFactory().configure(getWebMockObjectFactory()));</code>
34: * to set this implementation as the default factory.
35: * @return this instance for convenience
36: */
37: public JasperJspFactory configure(WebMockObjectFactory mockFactory) {
38: this .mockFactory = mockFactory;
39: applicationContext = JspApplicationContextImpl
40: .getInstance(mockFactory.getMockServletContext());
41: mockFactory.getMockPageContext().setELContext(
42: applicationContext.createELContext(mockFactory
43: .getMockPageContext()));
44: return this ;
45: }
46:
47: /**
48: * Set the <code>JspEngineInfo</code>. Per default,
49: * {@link MockJspEngineInfo} is used.
50: * @param engineInfo the <code>JspEngineInfo</code>
51: */
52: public void setEngineInfo(JspEngineInfo engineInfo) {
53: this .engineInfo = engineInfo;
54: }
55:
56: public JspEngineInfo getEngineInfo() {
57: return engineInfo;
58: }
59:
60: public JspApplicationContext getJspApplicationContext(
61: ServletContext context) {
62: return applicationContext;
63: }
64:
65: public PageContext getPageContext(Servlet servlet,
66: ServletRequest request, ServletResponse response,
67: String errorPageURL, boolean needsSession, int buffer,
68: boolean autoflush) {
69: return mockFactory.getMockPageContext();
70: }
71:
72: public void releasePageContext(PageContext pageContext) {
73:
74: }
75: }
|