KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > fmt > SetTimeZoneSupport


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.standard.tag.common.fmt;
18
19 import java.util.TimeZone JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.PageContext JavaDoc;
23 import javax.servlet.jsp.jstl.core.Config;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 import org.apache.taglibs.standard.tag.common.core.Util;
27
28 /**
29  * Support for tag handlers for <setTimeZone>, the time zone setting tag
30  * in JSTL 1.0.
31  *
32  * @author Jan Luehe
33  */

34
35 public abstract class SetTimeZoneSupport extends TagSupport JavaDoc {
36
37     
38     //*********************************************************************
39
// Protected state
40

41     protected Object JavaDoc value; // 'value' attribute
42

43
44     //*********************************************************************
45
// Private state
46

47     private int scope; // 'scope' attribute
48
private String JavaDoc var; // 'var' attribute
49

50
51     //*********************************************************************
52
// Constructor and initialization
53

54     public SetTimeZoneSupport() {
55     super();
56     init();
57     }
58
59     // resets local state
60
private void init() {
61     value = var = null;
62     scope = PageContext.PAGE_SCOPE;
63     }
64
65
66    //*********************************************************************
67
// Tag attributes known at translation time
68

69     public void setScope(String JavaDoc scope) {
70     this.scope = Util.getScope(scope);
71     }
72
73     public void setVar(String JavaDoc var) {
74         this.var = var;
75     }
76
77
78     //*********************************************************************
79
// Tag logic
80

81     public int doEndTag() throws JspException JavaDoc {
82     TimeZone JavaDoc timeZone = null;
83
84     if (value == null) {
85         timeZone = TimeZone.getTimeZone("GMT");
86     } else if (value instanceof String JavaDoc) {
87         if (((String JavaDoc) value).trim().equals("")) {
88         timeZone = TimeZone.getTimeZone("GMT");
89         } else {
90         timeZone = TimeZone.getTimeZone((String JavaDoc) value);
91         }
92     } else {
93         timeZone = (TimeZone JavaDoc) value;
94     }
95
96     if (var != null) {
97         pageContext.setAttribute(var, timeZone, scope);
98     } else {
99         Config.set(pageContext, Config.FMT_TIME_ZONE, timeZone, scope);
100     }
101
102     return EVAL_PAGE;
103     }
104
105     // Releases any resources we may have (or inherit)
106
public void release() {
107     init();
108     }
109 }
110
Popular Tags