All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.mock.web.JasperJspFactory Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
package com.mockrunner.mock.web;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.jsp.JspApplicationContext;
import javax.servlet.jsp.JspEngineInfo;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;

import org.apache.jasper.runtime.JspApplicationContextImpl;

/**
 * This implementation of JspFactory
 * provides full support of the Unified Expression Language
 * API. Expression evaluation is available only for the Unified 
 * Expression Language API, not for the pre JSP 2.1
 * javax.servlet.jsp.el Expression Language API.
 */
public class JasperJspFactory extends JspFactory
{
    private WebMockObjectFactory mockFactory;
    private JspEngineInfo engineInfo;
    private JspApplicationContextImpl applicationContext;

    public JasperJspFactory()
    {
        engineInfo = new MockJspEngineInfo();
    }
    
    /**
     * Configures this implementation for EL support.
     * Use
     * getWebMockObjectFactory().setDefaultJspFactory(new JasperJspFactory().configure(getWebMockObjectFactory()));
     * to set this implementation as the default factory.
     * @return this instance for convenience
     */
    public JasperJspFactory configure(WebMockObjectFactory mockFactory)
    {
        this.mockFactory = mockFactory;
        applicationContext = JspApplicationContextImpl.getInstance(mockFactory.getMockServletContext());
        mockFactory.getMockPageContext().setELContext(applicationContext.createELContext(mockFactory.getMockPageContext()));
        return this;
    }
    
    /**
     * Set the JspEngineInfo. Per default, 
     * {@link MockJspEngineInfo} is used.
     * @param engineInfo the JspEngineInfo
     */
    public void setEngineInfo(JspEngineInfo engineInfo)
    {
        this.engineInfo = engineInfo;
    }
    
    public JspEngineInfo getEngineInfo()
    {
        return engineInfo;
    }
    
    public JspApplicationContext getJspApplicationContext(ServletContext context)
    {
        return applicationContext;
    }

    public PageContext getPageContext(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int buffer, boolean autoflush)
    {
        return mockFactory.getMockPageContext();
    }

    public void releasePageContext(PageContext pageContext)
    {

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy