001 package com.khubla.pragmatach.plugin.jsp; 002 003 import java.util.Map; 004 005 import org.apache.jasper.runtime.HttpJspBase; 006 007 import com.khubla.pragmatach.framework.api.PragmatachException; 008 import com.khubla.pragmatach.framework.api.Response; 009 import com.khubla.pragmatach.framework.controller.impl.template.AbstractTemplateEngineController; 010 011 /** 012 * @author tome 013 */ 014 public class JSPController extends AbstractTemplateEngineController { 015 /** 016 * ctor 017 */ 018 public JSPController() { 019 } 020 021 /** 022 * render 023 */ 024 public Response render() throws PragmatachException { 025 try { 026 /* 027 * get the template name from the annotation 028 */ 029 final String templateName = getTemplateName(); 030 /* 031 * get the servlet 032 */ 033 final JSPCompiler jspCompiler = new JSPCompiler(templateName, getRequest().getServletConfig(), getRequest().getServletContext()); 034 final HttpJspBase httpServlet = jspCompiler.getServlet(); 035 httpServlet.init(getRequest().getServletConfig()); 036 /* 037 * add the context info into the request 038 */ 039 final Map<String, Object> ctx = getTemplateContext(); 040 for (final String s : ctx.keySet()) { 041 getRequest().getServletContext().setAttribute(s, ctx.get(s)); 042 } 043 /* 044 * go for it 045 */ 046 return new JSPResponse(getCacheHeaders(), httpServlet, getRequest().getHttpServletRequest()); 047 } catch (final Exception e) { 048 throw new PragmatachException("Exception in render", e); 049 } 050 } 051 }