View Javadoc

1   /*
2    * Copyright 2002,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  package org.apache.commons.jelly.tags.fmt;
17  
18  import org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.XMLOutput;
20  import org.apache.commons.jelly.Tag;
21  import org.apache.commons.jelly.TagSupport;
22  import org.apache.commons.jelly.expression.Expression;
23  import java.util.TimeZone;
24  
25  /***
26   * Support for tag handlers for <setTimeZone>, the time zone setting
27   * tag in JSTL.
28   * @author <a href="mailto:willievu@yahoo.com">Willie Vu</a>
29   * @version $Revision: 155420 $
30   *
31   */
32  public class SetTimeZoneTag extends TagSupport {
33  
34      private Expression value;
35  
36      private String var;
37  
38      private String scope;
39  
40      /*** Creates a new instance of SetLocaleTag */
41      public SetTimeZoneTag() {
42      }
43  
44      /***
45       * Evaluates this tag after all the tags properties have been initialized.
46       *
47       */
48      public void doTag(XMLOutput output) throws JellyTagException {
49          TimeZone timeZone = null;
50  
51          Object valueInput = null;
52          if (this.value != null) {
53              valueInput = this.value.evaluate(context);
54          }
55  
56  
57          if (valueInput == null) {
58              timeZone = TimeZone.getTimeZone("GMT");
59          }
60          else if (valueInput instanceof String) {
61              if (((String) valueInput).trim().equals("")) {
62                  timeZone = TimeZone.getTimeZone("GMT");
63              } else {
64                  timeZone = TimeZone.getTimeZone((String) valueInput);
65              }
66          } else {
67              timeZone = (TimeZone) valueInput;
68          }
69  
70          if (scope != null) {
71              context.setVariable(Config.FMT_TIME_ZONE, scope, timeZone);
72          }
73          else {
74              context.setVariable(Config.FMT_TIME_ZONE, timeZone);
75          }
76      }
77  
78      public void setValue(Expression value) {
79          this.value = value;
80      }
81  
82      public void setVar(String var) {
83          this.var = var;
84      }
85  
86      public void setScope(String scope) {
87          this.scope = scope;
88      }
89  }