| 1 22 23 package org.cofax.taglibs; 24 25 import javax.servlet.*; 26 import javax.servlet.jsp.*; 27 import javax.servlet.jsp.tagext.*; 28 import java.io.*; 29 import org.cofax.*; 30 31 37 public class IncludeTag extends TagSupport { 38 39 private String includeFile; 40 41 private boolean hasInclude = false; 42 43 46 public void setFile(String include) { 47 this.includeFile = include; 48 hasInclude = true; 49 } 50 51 55 public int doStartTag() throws JspException { 56 ServletRequest req = pageContext.getRequest(); 57 ServletResponse res = pageContext.getResponse(); 58 59 CofaxPage page = (CofaxPage) req.getAttribute("cofaxPage"); 60 61 try { 62 String includeId = null; 63 64 if (hasInclude) { 66 if (includeFile.startsWith("/")) { 67 includeId = page.getGlossaryValue("request:templatePathInit") + includeFile; 68 } else { 69 TemplateLoader tmpLoader = page.getTemplateLoader(); 70 tmpLoader.setTemplateSearch(tmpLoader.getTemplateRoot() + "/" + page.getGlossaryValue("request:templateSearch")); 71 includeId = tmpLoader.choose(page.getGlossaryValue("request:fileNameWithExtension"), page.getGlossaryValue("request:template"), page 72 .getGlossaryValue("request:fileNameExtension")); 73 includeId = tmpLoader.getResource(includeId, (String ) req.getAttribute("applicationPath")); 74 } 75 includeResource(includeId, req, res); 76 } 77 } catch (IOException ioe) { 78 System.out.println(" Error in set Include Tag ioe : " + ioe); 79 } catch (ServletException se) { 80 System.out.println(" Error in set Include Tag se : " + se); 81 } 82 83 return (SKIP_BODY); 84 } 85 86 89 private void includeResource(String url, ServletRequest req, ServletResponse res) throws ServletException, IOException { 90 91 if ((url != null) && (!url.equals(""))) { 92 RequestDispatcher dispatcher = req.getRequestDispatcher(url); 93 dispatcher.include(req, res); 94 } 95 96 return; 97 98 } 99 100 } 102 | Popular Tags |