1 package com.opensymphony.webwork.components.template; 2 3 import com.opensymphony.webwork.ServletActionContext; 4 import com.opensymphony.webwork.components.Include; 5 import com.opensymphony.webwork.components.UIBean; 6 import com.opensymphony.xwork.util.OgnlValueStack; 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 import javax.servlet.http.HttpServletResponse ; 11 import javax.servlet.jsp.PageContext ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 21 public class JspTemplateEngine extends BaseTemplateEngine { 22 private static final Log LOG = LogFactory.getLog(JspTemplateEngine.class); 23 24 public void renderTemplate(TemplateRenderingContext templateContext) throws Exception { 25 Template template = templateContext.getTemplate(); 26 27 if (LOG.isDebugEnabled()) { 28 LOG.debug("Trying to render template " + template + ", repeating through parents until we succeed"); 29 } 30 UIBean tag = templateContext.getTag(); 31 OgnlValueStack stack = templateContext.getStack(); 32 stack.push(tag); 33 PageContext pageContext = (PageContext ) stack.getContext().get(ServletActionContext.PAGE_CONTEXT); 34 List templates = template.getPossibleTemplates(this); 35 Exception exception = null; 36 boolean success = false; 37 for (Iterator iterator = templates.iterator(); iterator.hasNext();) { 38 Template t = (Template) iterator.next(); 39 try { 40 Include.include(getFinalTemplateName(t), pageContext.getOut(), 41 pageContext.getRequest(), (HttpServletResponse ) pageContext.getResponse()); 42 success = true; 43 break; 44 } catch (Exception e) { 45 if (exception == null) { 46 exception = e; 47 } 48 } 49 } 50 51 if (!success) { 52 LOG.error("Could not render JSP template " + templateContext.getTemplate()); 53 54 if (exception != null) { 55 throw exception; 56 } else { 57 return; 58 } 59 } 60 61 stack.pop(); 62 } 63 64 protected String getSuffix() { 65 return "jsp"; 66 } 67 } 68 | Popular Tags |