1 16 package org.apache.cocoon.components.jsp; 17 18 import java.io.IOException ; 19 20 import javax.servlet.Servlet ; 21 import javax.servlet.ServletContext ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.apache.avalon.framework.logger.AbstractLogEnabled; 27 import org.apache.avalon.framework.parameters.Parameterizable; 28 import org.apache.avalon.framework.parameters.Parameters; 29 import org.apache.avalon.framework.thread.ThreadSafe; 30 31 37 public class JSPEngineImpl extends AbstractLogEnabled 38 implements JSPEngine, Parameterizable, ThreadSafe { 39 40 41 public static final String DEFAULT_SERVLET_CLASS = "org.apache.jasper.servlet.JspServlet"; 42 43 44 public String jspServletClass = DEFAULT_SERVLET_CLASS; 45 46 49 public void parameterize(Parameters params) { 50 this.jspServletClass = params.getParameter("servlet-class", DEFAULT_SERVLET_CLASS); 51 } 52 53 56 public byte[] executeJSP(String url, 57 HttpServletRequest servletRequest, 58 HttpServletResponse servletResponse, 59 ServletContext context) 60 throws IOException , ServletException , Exception { 61 62 JSPEngineServletOutputStream output = new JSPEngineServletOutputStream(); 63 JSPEngineServletRequest request = new JSPEngineServletRequest(servletRequest, url); 64 JSPEngineServletResponse response = new JSPEngineServletResponse(servletResponse,output); 65 66 byte[] bytes = null; 67 68 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(this.jspServletClass); 70 Servlet servlet = (Servlet ) clazz.newInstance(); 71 servlet.init(new JSPEngineServletConfig(context,"JSPEngineImpl")); 72 73 try { 74 servlet.service(request, response); 75 bytes = output.toByteArray(); 76 } finally { 77 servlet.destroy(); 79 } 80 81 return bytes; 82 } 83 } 84 | Popular Tags |