catlett 01/08/13 17:02:23 Added: mailer/src/org/apache/taglibs/mailer AddRecipientTag.java Log: condensed the three add tags into one Revision Changes Path 1.1 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/AddRecipientTag.java Index: AddRecipientTag.java =================================================================== /* * $Header: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/AddRecipientTag.java,v 1.1 2001/08/14 00:02:23 catlett Exp $ * $Revision: 1.1 $ * $Date: 2001/08/14 00:02:23 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.taglibs.mailer; import java.util.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; /** * AddRecipientTag - JSP tag <b>addrecipient</b> is used to add any type of * recipient to an already existant list of recipients in an * e-mail message. Two attributes are required, type and address. * Type may be either "to", "cc", or "bcc" and address should be * a string representation of the recipients e-mail address. * * <tag> * <name>addrecipient</name> * <tagclass>org.apache.taglibs.mailer.AddRecipientTag</tagclass> * <bodycontent>JSP</bodycontent> * <info> * Append a recipient to the current recipients of the e-mail. * </info> * * <attribute> * <name>type</name> * <required>true</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * <attribute> * <name>address</name> * <required>false</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * </tag> * * @author Jayson Falkner Rich Catlett * * @version 1.0 * */ public class AddRecipientTag extends BodyTagSupport { /** * The type of address to add either to, cc, or bcc */ private String type = null; /** * The address to be added */ private String address = null; /** * implementation of the method from the tag interface that tells the JSP * page what to do after the body of this tag * * @throws JSPException thrown when an error occurs while processing the * body of this method * * @return SKIP_BODY int telling the tag handler to not evaluate the body * of this tag again * */ public final int doAfterBody() throws JspException { // parent tag must be a MailTag, gives access to methods in parent MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class); if (myparent == null) throw new JspException("addrecipient tag not nested within mail tag"); else { // Make sure type is set..either "to", "cc", or "bcc" if ((type != null) && (type.equalsIgnoreCase("to") || type.equalsIgnoreCase("cc") || type.equalsIgnoreCase("bcc"))) { if (address != null) { // Try to see if the address attribute was used. if (type.equalsIgnoreCase("to")) // set to in the parent tag myparent.addTo(address); if (type.equalsIgnoreCase("cc")) // set cc in the parent tag myparent.addCc(address); if (type.equalsIgnoreCase("bcc")) // set bcc in the parent tag myparent.addBcc(address); } else if ((address = bodyContent.getString()) != null) { // Try to see if the body was used for the address. if (type.equalsIgnoreCase("to")) // set to in the parent tag myparent.addTo(address); if (type.equalsIgnoreCase("cc")) // set cc in the parent tag myparent.addCc(address); if (type.equalsIgnoreCase("bcc")) // set bcc in the parent tag myparent.addBcc(address); } else throw new JspException("Address was not found. set " + " the address attribute, or place the address in" + " the body of the tag."); } else throw new JspException("The type attribute is not set. " + " Specify either \"to\", \"cc\", or \"bcc\"."); } return SKIP_BODY; } /** * set the type of recipient for the address * * @param type string that is the type of the address either * "to", "cc", or "bcc". * */ public final void setType(String type) { this.type = type; } /** * set the value for an address to be later added to the email * * @param address string that is an address to be added to the * "to", "cc", or "bcc" lists of addresses. * */ public final void setAddress(String address) { this.address = address; } }
