KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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