KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PortTag - JSP tag <b>port</b> is used for dynamically setting the mail
25  * server port that is going to be used to send the mail. The tag
26  * must be nested within a <b>mail</b> tag.
27  *
28  * <p>
29  * JSP Tag Lib Descriptor
30  * <p><pre>
31  * &lt;name&gt;port&lt;/name&gt;
32  * &lt;tagclass&gt;org.apache.taglibs.mailer.PortTag&lt;/tagclass&gt;
33  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
34  * &lt;info&gt;
35  * Sets the mail server port used to send the mail
36  * &lt;/info&gt;
37  * </pre></p></p>
38  *
39  * @author Rich Catlett
40  * @author Martin Cooper
41  *
42  * @version 1.0
43  *
44  */

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

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