KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > el > SetTimeZoneTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.el;
30
31 import com.caucho.el.Expr;
32 import com.caucho.jsp.PageContextImpl;
33 import com.caucho.util.L10N;
34
35 import javax.el.ELException;
36 import javax.servlet.jsp.JspException JavaDoc;
37 import javax.servlet.jsp.jstl.core.Config;
38 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
39 import java.util.TimeZone JavaDoc;
40
41 /**
42  * Sets the time zone for the current page.
43  */

44 public class SetTimeZoneTag extends TagSupport JavaDoc {
45   private static L10N L = new L10N(SetTimeZoneTag.class);
46   
47   private Expr _valueExpr;
48   private String JavaDoc _var;
49   private String JavaDoc _scope;
50
51   /**
52    * Sets the JSP-EL expression for the locale value.
53    */

54   public void setValue(Expr value)
55   {
56     _valueExpr = value;
57   }
58
59   /**
60    * Sets the variable containing the time zone.
61    */

62   public void setVar(String JavaDoc var)
63   {
64     _var = var;
65   }
66
67   /**
68    * Sets the scope to store the bundle.
69    */

70   public void setScope(String JavaDoc scope)
71   {
72     _scope = scope;
73   }
74
75   /**
76    * Process the tag.
77    */

78   public int doStartTag()
79     throws JspException JavaDoc
80   {
81     try {
82       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
83
84       Object JavaDoc valueObj = _valueExpr.evalString(pageContext.getELContext());
85       TimeZone JavaDoc timeZone = null;
86
87       if (valueObj instanceof TimeZone JavaDoc) {
88     timeZone = (TimeZone JavaDoc) valueObj;
89       }
90       else if (valueObj instanceof String JavaDoc) {
91     String JavaDoc string = (String JavaDoc) valueObj;
92     string = string.trim();
93
94     if (string.equals(""))
95       timeZone = TimeZone.getTimeZone("GMT");
96     else
97       timeZone = TimeZone.getTimeZone(string);
98       }
99       else
100     timeZone = TimeZone.getTimeZone("GMT");
101
102       String JavaDoc var = _var;
103       if (var == null)
104     var = Config.FMT_TIME_ZONE;
105     
106       CoreSetTag.setValue(pageContext, var, _scope, timeZone);
107
108       return SKIP_BODY;
109     } catch (ELException e) {
110       throw new JspException JavaDoc(e);
111     }
112   }
113 }
114
Popular Tags