KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > mailer > ReplyToTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.mailer;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
21 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
22
23 /**
24  * ReplyToTag - JSP tag <b>ReplyTo</b> is used to set the To address in an e-mail.
25  *
26  * <tag>
27  * <name>replyto</name>
28  * <tagclass>org.apache.taglibs.ReplyToTag</tagclass>
29  * <bodycontent>JSP</bodycontent>
30  * <info>Set the Reply-To address of the email</info>
31  * </tag>
32  *
33  * @author Rich Catlett
34  *
35  * @version 1.0
36  *
37  */

38
39 public class ReplyToTag extends BodyTagSupport JavaDoc {
40
41
42     /**
43      * implementation of the method from the tag interface that tells the JSP
44      * page what to do after the body of this tag
45      *
46      * @throws JspException thrown when an error occurs while processing the
47      * body of this method
48      *
49      * @return SKIP_BODY int telling the tag handler to not evaluate the body
50      * of this tag again
51      *
52      */

53     public int doAfterBody() throws JspException JavaDoc {
54
55         // parent tag must be a MailTag, gives access to methods in parent
56
MailTag myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
57
58         if (myparent == null) {
59             throw new JspException JavaDoc("replyto tag not nested within mail tag");
60         }
61
62         BodyContent JavaDoc body = getBodyContent();
63         String JavaDoc replyto = body.getString();
64         // Clear the body since we only used it as input for the email address
65
body.clearBody();
66         if (replyto != null) {
67             replyto.trim();
68             if (replyto.length() > 0) {
69                 myparent.resetReplyTo(replyto); // set replyto in the parent tag
70
return SKIP_BODY;
71             }
72         }
73         throw new JspException JavaDoc("The replyto tag is empty");
74     }
75 }
76
Popular Tags