1 16 17 package org.apache.taglibs.mailer; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.JspTagException ; 21 import javax.servlet.jsp.tagext.BodyContent ; 22 import javax.servlet.jsp.tagext.BodyTagSupport ; 23 24 56 57 public class AddRecipientTag extends BodyTagSupport { 58 59 62 private String type_string = null; 63 private int type = 0; 64 65 68 private String address = null; 69 70 83 public int doStartTag() throws JspException { 84 if (address != null && address.length() > 0 ) { 85 addToParent(address); 86 return SKIP_BODY; 87 } 88 return EVAL_BODY_TAG; 89 } 90 91 92 103 public int doAfterBody() throws JspException { 104 BodyContent body = getBodyContent(); 105 String addr = body.getString(); 106 body.clearBody(); 108 if (addr != null && addr.length() > 0 ) { 109 addToParent(addr); 110 return SKIP_BODY; 111 } else { 112 throw new JspException ("addrecpient tag could not find an email address. set " + 113 " the address attribute, or place the address in" + 114 " the body of the tag."); 115 } 116 } 117 118 124 public void setType(String type) throws JspTagException { 125 this.type_string = type.trim(); 126 if (type_string.equalsIgnoreCase(MailTag.TO_ADDRESS_STRING)) { 127 this.type = MailTag.TO_ADDRESS; 128 } else if (type_string.equalsIgnoreCase(MailTag.CC_ADDRESS_STRING)) { 129 this.type = MailTag.CC_ADDRESS; 130 } else if (type_string.equalsIgnoreCase(MailTag.BCC_ADDRESS_STRING)) { 131 this.type = MailTag.BCC_ADDRESS; 132 } else { 133 throw new JspTagException 134 ("addrecipient tag type attribute must be \"to\", \"cc\", or \"bcc\""); 135 } 136 } 137 138 144 public void setAddress(String address) { 145 this.address = address.trim(); 146 } 147 148 protected void addToParent(String addr) throws JspTagException { 149 MailTag myparent = 151 (MailTag)findAncestorWithClass 152 (this, MailTag.class); 153 154 if (myparent == null) { 155 throw new JspTagException ("addrecipient tag not nested within mail tag"); 156 } 157 158 switch (type) { 160 case MailTag.TO_ADDRESS: 161 myparent.addTo(addr); 163 break; 164 case MailTag.CC_ADDRESS: 165 myparent.addCc(addr); 167 break; 168 case MailTag.BCC_ADDRESS: 169 myparent.addBcc(addr); 171 break; 172 default: 173 throw new JspTagException ("addrecipient tag type attribute is not set. " + 174 " Specify either \"to\", \"cc\", or \"bcc\"."); 175 } 176 } 177 178 } 179 | Popular Tags |