KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PasswordTag - JSP tag <b>Password</b> is used to set the password used for
25  * authentication of the mail session.
26  *
27  * <tag>
28  * <name>from</name>
29  * <tagclass>org.apache.taglibs.PasswordTag</tagclass>
30  * <bodycontent>JSP</bodycontent>
31  * <info>Set the Password for mail authentication</info>
32  * </tag>
33  *
34  * @author Rich Catlett
35  *
36  * @version 1.2
37  *
38  */

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

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