1 package org.apache.turbine.services.jsp.tags; 2 3 18 19 import java.io.IOException ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.PageContext ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 import org.apache.turbine.modules.ScreenLoader; 24 import org.apache.turbine.services.TurbineServices; 25 import org.apache.turbine.services.jsp.JspService; 26 import org.apache.turbine.services.template.TemplateService; 27 import org.apache.turbine.util.Log; 28 import org.apache.turbine.util.RunData; 29 import org.apache.turbine.util.template.TemplateInfo; 30 31 41 public class ScreenTag extends TagSupport 42 { 43 46 private String section; 47 53 private boolean staticContent; 54 58 private static final String FLAG = "_screen_executed_"; 59 60 63 static final String SECTION_KEY = "_layout_section_"; 64 67 static final String BODY = "body"; 68 71 static final String HEAD = "head"; 72 73 76 public void setSection(String section) 77 { 78 pageContext.setAttribute(SECTION_KEY, section, 79 PageContext.REQUEST_SCOPE); 80 this.section = section; 81 } 82 83 86 public void setStaticContent(boolean staticContent) 87 { 88 this.staticContent = staticContent; 89 } 90 91 97 public int doStartTag() throws JspException 98 { 99 RunData data = (RunData)pageContext 100 .getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE); 101 102 String module = null; 103 String template = null; 104 Boolean flag = (Boolean )pageContext 105 .getAttribute(FLAG, PageContext.REQUEST_SCOPE); 106 JspService jsp = (JspService) TurbineServices.getInstance() 107 .getService(JspService.SERVICE_NAME); 108 try 109 { 110 pageContext.getOut().flush(); 111 template = data.getTemplateInfo().getScreenTemplate(); 112 113 if ( staticContent || (flag != null && flag.booleanValue()) ) 114 { 115 jsp.handleRequest(data, "/screens/" + template, false); 116 } 117 else 118 { 119 module = ((TemplateService)TurbineServices.getInstance().getService( 120 TemplateService.SERVICE_NAME)).getScreenName(template); 121 ScreenLoader.getInstance().exec(data, module); 122 pageContext.setAttribute(FLAG, 123 Boolean.TRUE, PageContext.REQUEST_SCOPE); 124 } 125 } 126 catch (Exception e) 127 { 128 String message = "Error processing screen template:" + 129 template + " using module: " + module; 130 Log.error(message, e); 131 try 132 { 133 data.getOut().print("Error processing screen template: " 134 + template + " using module: " + module); 135 } 136 catch(java.io.IOException ioe) {} 137 } 138 return SKIP_BODY; 139 } 140 } 141 | Popular Tags |