1 16 17 package org.apache.taglibs.mailer; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.PageContext ; 23 import javax.servlet.jsp.tagext.BodyTagSupport ; 24 25 47 48 public class ErrorTag extends BodyTagSupport { 49 50 private Iterator errorlist = null; 52 private ArrayList errors = null; private String error = null; 55 65 public int doStartTag() throws JspException { 66 67 SendTag myparent = (SendTag)findAncestorWithClass(this, SendTag.class); 69 70 if (myparent == null) 71 throw new JspException ("error tag not nested within send tag"); 72 else 73 if ((errors = myparent.getError()) == null) 74 return SKIP_BODY; 75 76 errorlist = errors.iterator(); 77 if (!errorlist.hasNext()) 78 return SKIP_BODY; 79 80 error = (String )errorlist.next(); 82 83 if (error == null) 85 return SKIP_BODY; 86 87 pageContext.setAttribute(id, this, PageContext.PAGE_SCOPE); 88 return EVAL_BODY_TAG; 90 } 93 94 101 public int doAfterBody() throws JspException 102 { 103 if (!errorlist.hasNext()) 105 return SKIP_BODY; 106 error = (String )errorlist.next(); 108 if (error == null) 109 return SKIP_BODY; 110 return EVAL_BODY_TAG; 112 } 115 116 126 public int doEndTag() throws JspException { 127 try { 128 if (bodyContent != null) 129 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 130 } catch (java.io.IOException e) { 131 throw new JspException ("IO Error: " + e.getMessage()); 132 } 133 return EVAL_PAGE; 134 } 135 136 143 public String getError() 144 { 145 return error; 146 } 147 148 151 public void release() 152 { 153 if( id != null && id.length() > 0 ) 154 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 155 } 156 } 157 | Popular Tags |