1 9 10 package com.opensymphony.module.sitemesh.taglib; 11 12 import com.opensymphony.module.sitemesh.Page; 13 import com.opensymphony.module.sitemesh.RequestConstants; 14 import com.opensymphony.module.sitemesh.util.OutputConverter; 15 16 import javax.servlet.jsp.JspException ; 17 import javax.servlet.jsp.PageContext ; 18 import javax.servlet.jsp.tagext.Tag ; 19 import javax.servlet.jsp.tagext.BodyTagSupport ; 20 import java.io.Writer ; 21 22 29 public abstract class AbstractTag extends BodyTagSupport implements RequestConstants { 30 protected PageContext pageContext; 31 protected Tag parent; 32 33 34 public abstract int doEndTag() throws JspException ; 35 36 37 public int doStartTag() { 38 return SKIP_BODY; 39 } 40 41 public void release() { 42 } 43 44 public Tag getParent() { 45 return parent; 46 } 47 48 public void setParent(Tag parent) { 49 this.parent = parent; 50 } 51 52 public void setPageContext(PageContext pageContext) { 53 this.pageContext = pageContext; 54 } 55 56 60 protected Page getPage() { 61 Page p = (Page)pageContext.getAttribute(PAGE, PageContext.PAGE_SCOPE); 62 63 if (p == null) { 64 p = (Page)pageContext.getAttribute(PAGE, PageContext.REQUEST_SCOPE); 65 if (p == null) { 66 pageContext.removeAttribute(PAGE, PageContext.PAGE_SCOPE); 67 } 68 else { 69 pageContext.setAttribute(PAGE, p, PageContext.PAGE_SCOPE); 70 } 71 pageContext.removeAttribute(PAGE, PageContext.REQUEST_SCOPE); 72 } 73 return p; 74 } 75 76 77 protected static void trace(Exception e) { 78 e.printStackTrace(); 79 } 80 81 87 protected Writer getOut() { 88 return OutputConverter.getWriter(pageContext.getOut()); 89 } 90 } | Popular Tags |