View Javadoc

1   /*
2    * Copyright 1999-2004 The Apache Software Foundation.
3    * Modifications, Copyright 2005 Stephen Colebourne
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.joda.time.contrib.jsptag;
18  
19  import java.util.Locale;
20  
21  import javax.servlet.jsp.JspTagException;
22  
23  import org.joda.time.DateTimeZone;
24  
25  /**
26   * <p>
27   * A handler for &lt;format&gt; that supports rtexprvalue-based attributes.
28   * </p>
29   * 
30   * @author Jan Luehe
31   * @author Jim Newsham
32   */
33  public class FormatTag extends FormatSupport {
34  
35      /**
36       * Sets the value attribute.
37       * 
38       * @param value  the value
39       */
40      public void setValue(Object value) throws JspTagException {
41          this.value = value;
42      }
43  
44      /**
45       * Sets the style attribute.
46       * 
47       * @param style  the style
48       */
49      public void setStyle(String style) throws JspTagException {
50          this.style = style;
51      }
52  
53      /**
54       * Sets the pattern attribute.
55       * 
56       * @param pattern  the pattern
57       */
58      public void setPattern(String pattern) throws JspTagException {
59          this.pattern = pattern;
60      }
61  
62      /**
63       * Sets the zone attribute.
64       * 
65       * @param dtz  the zone
66       */
67      public void setDateTimeZone(Object dtz) throws JspTagException {
68          if (dtz == null || dtz instanceof String
69                  && ((String) dtz).length() == 0) {
70              this.dateTimeZone = null;
71          } else if (dtz instanceof DateTimeZone) {
72              this.dateTimeZone = (DateTimeZone) dtz;
73          } else {
74              try {
75                  this.dateTimeZone = DateTimeZone.forID((String) dtz);
76              } catch (IllegalArgumentException iae) {
77                  this.dateTimeZone = DateTimeZone.UTC;
78              }
79          }
80      }
81  
82      /**
83       * Sets the style attribute.
84       * 
85       * @param loc  the locale
86       */
87      public void setLocale(Object loc) throws JspTagException {
88          if (loc == null
89                  || (loc instanceof String && ((String) loc).length() == 0)) {
90              this.locale = null;
91          } else if (loc instanceof Locale) {
92              this.locale = (Locale) loc;
93          } else {
94              this.locale = Util.parseLocale((String) loc);
95          }
96      }
97  
98  }