KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > datetime > TimeZoneTag


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.datetime;
18
19 import java.util.*;
20 import java.text.*;
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23 import javax.servlet.jsp.*;
24 import javax.servlet.jsp.tagext.*;
25
26 /**
27  * JSP Tag <b>timeZone</b>, used to set the client timeZone for
28  * the SESSION as a script variable.
29  * <p>
30  * The TimeZone ID String is obtained from the body of the tag.
31  * If there is no TimeZone ID String, the server default timeZone is used.
32  * <p>
33  * JSP Tag Lib Descriptor
34  * <p><pre>
35  * &lt;name&gt;timeZone&lt;/name&gt;
36  * &lt;tagclass&gt;org.apache.taglibs.datetime.TimeZoneTag&lt;/tagclass&gt;
37  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
38  * &lt;info&gt;Creates a SESSION script variable for clients time zone.&lt;/info&gt;
39  * &lt;attribute&gt;
40  * &lt;name&gt;id&lt;/name&gt;
41  * &lt;required&gt;true&lt;/required&gt;
42  * &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
43  * &lt;/attribute&gt;
44  * </pre>
45  *
46  * @author Glenn Nielsen
47  */

48
49 public class TimeZoneTag extends BodyTagSupport
50 {
51
52     /**
53      * Method called at start of tag, always returns EVAL_BODY_TAG
54      *
55      * @return EVAL_BODY_TAG
56      */

57     public final int doStartTag() throws JspException
58     {
59     return EVAL_BODY_TAG;
60     }
61
62     /**
63      * Method called at end of timeZone tag body.
64      *
65      * @return SKIP_BODY
66      */

67     public final int doAfterBody() throws JspException
68     {
69     // Use the body of the tag as input for the timeZone
70
BodyContent body = getBodyContent();
71     String JavaDoc s = body.getString().trim();
72     // Clear the body since we only use it to set the timeZone
73
body.clearBody();
74
75     TimeZone tz = TimeZone.getTimeZone(s);
76     if( tz == null )
77         tz = TimeZone.getDefault();
78
79     pageContext.setAttribute(id,tz,PageContext.SESSION_SCOPE);
80     return SKIP_BODY;
81     }
82
83     /**
84      * Method called at end of Tag
85      *
86      * @return EVAL_PAGE
87      */

88     public final int doEndTag() throws JspException
89     {
90     return EVAL_PAGE;
91     }
92
93 }
94
Popular Tags