KickJava   Java API By Example, From Geeks To Geeks.

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


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  * FromTag - JSP tag <b>From</b> is used to set the from address in an email.
25  *
26  * <tag>
27  * <name>from</name>
28  * <tagclass>org.apache.taglibs.FromTag</tagclass>
29  * <bodycontent>JSP</bodycontent>
30  * <info>Set the To address of the email</info>
31  * </tag>
32  *
33  * @author Rich Catlett
34  *
35  * @version 1.0
36  *
37  */

38
39 public class FromTag 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("from tag not nested within mail tag");
60         }
61
62         BodyContent JavaDoc body = getBodyContent();
63         String JavaDoc from = body.getString();
64         // Clear the body since we only used it as input for the email address
65
body.clearBody();
66         if (from != null) {
67             from.trim();
68             if (from.length() > 0) {
69             myparent.resetFrom(from); // set from in the parent tag
70
return SKIP_BODY;
71             }
72     }
73     throw new JspException JavaDoc("The from tag is empty");
74     }
75 }
76
Popular Tags