KickJava   Java API By Example, From Geeks To Geeks.

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


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  * HeaderTag - JSP tag <b>Header</b> is used to set headers in an e-mail message.
25  *
26  * <tag>
27  * <name>header</name>
28  * <tagclass>org.apache.taglibs.mailer.HeaderTag</tagclass>
29  * <bodycontent>JSP</bodycontent>
30  * <info>Set the To address of the email</info>
31  *
32  * <attribute>
33  * <name>name</name>
34  * <required>true</required>
35  * <rtexprval>false</rtexprval>
36  * </attribute>
37  * <attribute>
38  * <name>value</name>
39  * <required>false</required>
40  * <rtexprval>false</rtexprval>
41  * </attribute>
42  * </tag>
43  *
44  * @author Rich Catlett
45  *
46  * @version 1.0
47  *
48  */

49
50 public class HeaderTag extends BodyTagSupport JavaDoc {
51
52     /**
53      * name of header to be set
54      */

55     String JavaDoc name;
56     /**
57      * value of header to be set
58      */

59     String JavaDoc value = null;
60
61     /**
62      * implementation of the method from the tag interface that tells the JSP
63      * page what to do after the body of this tag
64      *
65      * @throws JspException thrown when an error occurs while processing the
66      * body of this method
67      *
68      * @return SKIP_BODY int telling the tag handler to not evaluate the body
69      * of this tag again
70      *
71      */

72     public int doAfterBody() throws JspException JavaDoc {
73
74     // parent tag must be a MailTag, gives access to methods in parent
75
MailTag myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
76
77     if (myparent == null) {
78         throw new JspException JavaDoc("header tag not nested within mail tag");
79         }
80         BodyContent JavaDoc body = getBodyContent();
81         String JavaDoc valueStr = value;
82         if (valueStr == null ) {
83             valueStr = body.getString();
84         }
85         // Clear the body since we only used it as input for the header value
86
body.clearBody();
87         if (valueStr == null) {
88             throw new JspException JavaDoc("The header tag is empty");
89         }
90         myparent.setHeader(name,valueStr); // set header in parent tag
91
return SKIP_BODY;
92     }
93
94     /**
95      * set the name of the header to be set
96      *
97      * @param value string that is the name of the header to be set
98      *
99      */

100     public void setName(String JavaDoc value) {
101     name = value;
102     }
103
104     /**
105      * set the value of the header to be set
106      *
107      * @param value string that the value of the header to be set
108      *
109      */

110     public void setValue(String JavaDoc value) {
111     this.value = value;
112     }
113 }
114
Popular Tags