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;parseDate&gt; that supports rtexprvalue-based attributes.
28   * </p>
29   * 
30   * @author Jan Luehe
31   * @author Jim Newsham
32   */
33  
34  public class ParseDateTimeTag extends ParseDateTimeSupport {
35  
36      /**
37       * Sets the value attribute.
38       * 
39       * @param value  the value
40       */
41      public void setValue(String value) throws JspTagException {
42          this.value = value;
43          this.valueSpecified = true;
44      }
45  
46      /**
47       * Sets the style attribute.
48       * 
49       * @param style  the style
50       */
51      public void setStyle(String style) throws JspTagException {
52          this.style = style;
53      }
54  
55      /**
56       * Sets the pattern attribute.
57       * 
58       * @param pattern  the pattern
59       */
60      public void setPattern(String pattern) throws JspTagException {
61          this.pattern = pattern;
62      }
63  
64      /**
65       * Sets the zone attribute.
66       * 
67       * @param dtz  the zone
68       */
69      public void setDateTimeZone(Object dtz) throws JspTagException {
70          if (dtz == null || dtz instanceof String
71                  && ((String) dtz).length() == 0) {
72              this.dateTimeZone = null;
73          } else if (dtz instanceof DateTimeZone) {
74              this.dateTimeZone = (DateTimeZone) dtz;
75          } else {
76              try {
77                  this.dateTimeZone = DateTimeZone.forID((String) dtz);
78              } catch (IllegalArgumentException iae) {
79                  this.dateTimeZone = DateTimeZone.UTC;
80              }
81          }
82      }
83  
84      /**
85       * Sets the style attribute.
86       * 
87       * @param loc  the locale
88       */
89      public void setLocale(Object loc) throws JspTagException {
90          if (loc == null
91                  || (loc instanceof String && ((String) loc).length() == 0)) {
92              this.locale = null;
93          } else if (loc instanceof Locale) {
94              this.locale = (Locale) loc;
95          } else {
96              locale = Util.parseLocale((String) loc);
97          }
98      }
99  
100 }