KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > fmt > ParseDateTag


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.el.fmt;
18
19 import java.util.Locale JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22
23 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
24 import org.apache.taglibs.standard.tag.common.fmt.ParseDateSupport;
25 import org.apache.taglibs.standard.tag.common.fmt.SetLocaleSupport;
26
27 /**
28  * <p>A handler for &lt;parseDate&gt; that accepts attributes as Strings
29  * and evaluates them as expressions at runtime.</p>
30  *
31  * @author Jan Luehe
32  */

33
34 public class ParseDateTag extends ParseDateSupport {
35
36     //*********************************************************************
37
// 'Private' state (implementation details)
38

39     private String JavaDoc value_; // stores EL-based property
40
private String JavaDoc type_; // stores EL-based property
41
private String JavaDoc dateStyle_; // stores EL-based property
42
private String JavaDoc timeStyle_; // stores EL-based property
43
private String JavaDoc pattern_; // stores EL-based property
44
private String JavaDoc timeZone_; // stores EL-based property
45
private String JavaDoc parseLocale_; // stores EL-based property
46

47
48     //*********************************************************************
49
// Constructor
50

51     /**
52      * Constructs a new ParseDateTag. As with TagSupport, subclasses
53      * should not provide other constructors and are expected to call
54      * the superclass constructor
55      */

56     public ParseDateTag() {
57         super();
58         init();
59     }
60
61
62     //*********************************************************************
63
// Tag logic
64

65     // evaluates expression and chains to parent
66
public int doStartTag() throws JspException JavaDoc {
67
68         // evaluate any expressions we were passed, once per invocation
69
evaluateExpressions();
70
71     // chain to the parent implementation
72
return super.doStartTag();
73     }
74
75     // Releases any resources we may have (or inherit)
76
public void release() {
77         super.release();
78         init();
79     }
80
81
82     //*********************************************************************
83
// Accessor methods
84

85     // for EL-based attribute
86
public void setValue(String JavaDoc value_) {
87         this.value_ = value_;
88     this.valueSpecified = true;
89     }
90
91     // for EL-based attribute
92
public void setType(String JavaDoc type_) {
93         this.type_ = type_;
94     }
95
96     // for EL-based attribute
97
public void setDateStyle(String JavaDoc dateStyle_) {
98         this.dateStyle_ = dateStyle_;
99     }
100
101     // for EL-based attribute
102
public void setTimeStyle(String JavaDoc timeStyle_) {
103         this.timeStyle_ = timeStyle_;
104     }
105
106     // for EL-based attribute
107
public void setPattern(String JavaDoc pattern_) {
108         this.pattern_ = pattern_;
109     }
110
111     // for EL-based attribute
112
public void setTimeZone(String JavaDoc timeZone_) {
113         this.timeZone_ = timeZone_;
114     }
115
116     // for EL-based attribute
117
public void setParseLocale(String JavaDoc parseLocale_) {
118         this.parseLocale_ = parseLocale_;
119     }
120
121
122     //*********************************************************************
123
// Private (utility) methods
124

125     // (re)initializes state (during release() or construction)
126
private void init() {
127         // null implies "no expression"
128
value_ = type_ = dateStyle_ = timeStyle_ = pattern_ = timeZone_ = null;
129     parseLocale_ = null;
130     }
131
132     // Evaluates expressions as necessary
133
private void evaluateExpressions() throws JspException JavaDoc {
134         /*
135          * Note: we don't check for type mismatches here; we assume
136          * the expression evaluator will return the expected type
137          * (by virtue of knowledge we give it about what that type is).
138          * A ClassCastException here is truly unexpected, so we let it
139          * propagate up.
140          */

141
142     // 'value' attribute
143
if (value_ != null) {
144         value = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
145             "value", value_, String JavaDoc.class, this, pageContext);
146     }
147
148     // 'type' attribute
149
if (type_ != null) {
150         type = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
151             "type", type_, String JavaDoc.class, this, pageContext);
152     }
153
154     // 'dateStyle' attribute
155
if (dateStyle_ != null) {
156         dateStyle = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
157             "dateStyle", dateStyle_, String JavaDoc.class, this, pageContext);
158     }
159
160     // 'timeStyle' attribute
161
if (timeStyle_ != null) {
162         timeStyle = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
163             "timeStyle", timeStyle_, String JavaDoc.class, this, pageContext);
164     }
165
166     // 'pattern' attribute
167
if (pattern_ != null) {
168         pattern = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
169             "pattern", pattern_, String JavaDoc.class, this, pageContext);
170     }
171
172     // 'timeZone' attribute
173
if (timeZone_ != null) {
174         timeZone = ExpressionEvaluatorManager.evaluate(
175             "timeZone", timeZone_, Object JavaDoc.class, this, pageContext);
176     }
177
178     // 'parseLocale' attribute
179
if (parseLocale_ != null) {
180         Object JavaDoc obj = ExpressionEvaluatorManager.evaluate(
181             "parseLocale", parseLocale_, Object JavaDoc.class, this, pageContext);
182         if (obj != null) {
183         if (obj instanceof Locale JavaDoc) {
184             parseLocale = (Locale JavaDoc) obj;
185         } else {
186             String JavaDoc localeStr = (String JavaDoc) obj;
187             if (!"".equals(localeStr)) {
188             parseLocale = SetLocaleSupport.parseLocale(localeStr);
189             }
190         }
191         }
192     }
193     }
194 }
195
Popular Tags