KickJava   Java API By Example, From Geeks To Geeks.

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


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

49
50 public class MessageTag extends BodyTagSupport JavaDoc {
51
52     /**
53      * can be "text" or "html" (otherwise text is default)
54      */

55     private String JavaDoc type = "text";
56
57     /**
58      * character set to be used (default is unspecified)
59      */

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

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

100     public void setType(String JavaDoc value) {
101     type = value;
102     }
103
104     /**
105      * set the character set for this email
106      *
107      * @param value string that is the character set for this email
108      *
109      */

110     public void setCharset(String JavaDoc value) {
111     charset = value;
112     }
113 }
114
Popular Tags