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

com.khubla.pragmatach.plugin.jsp.JSPController Maven / Gradle / Ivy

package com.khubla.pragmatach.plugin.jsp;

import java.util.Map;

import org.apache.jasper.runtime.HttpJspBase;

import com.khubla.pragmatach.framework.api.PragmatachException;
import com.khubla.pragmatach.framework.api.Response;
import com.khubla.pragmatach.framework.controller.impl.template.AbstractTemplateEngineController;

/**
 * @author tome
 */
public class JSPController extends AbstractTemplateEngineController {
   /**
    * ctor
    */
   public JSPController() {
   }

   /**
    * render
    */
   public Response render() throws PragmatachException {
      try {
         /*
          * get the template name from the annotation
          */
         final String templateName = getTemplateName();
         if (null != templateName) {
            /*
             * get the servlet
             */
            final JSPCompiler jspCompiler = new JSPCompiler(templateName, getRequest().getServletConfig(), getRequest().getServletContext());
            final HttpJspBase httpServlet = jspCompiler.getServlet();
            httpServlet.init(getRequest().getServletConfig());
            /*
             * add the context info into the request
             */
            final Map ctx = getTemplateContext();
            for (final String s : ctx.keySet()) {
               getRequest().getServletContext().setAttribute(s, ctx.get(s));
            }
            /*
             * go for it
             */
            return new JSPResponse(getCacheHeaders(), httpServlet, getRequest().getHttpServletRequest());
         } else {
            throw new PragmatachException("Unable to get template name");
         }
      } catch (final Exception e) {
         throw new PragmatachException("Exception in render", e);
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy