KickJava   Java API By Example, From Geeks To Geeks.

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


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.Date 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.FormatDateSupport;
25
26 /**
27  * <p>A handler for &lt;formatDate&gt; that accepts attributes as Strings
28  * and evaluates them as expressions at runtime.</p>
29  *
30  * @author Jan Luehe
31  */

32
33 public class FormatDateTag extends FormatDateSupport {
34
35     //*********************************************************************
36
// 'Private' state (implementation details)
37

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

45
46     //*********************************************************************
47
// Constructor
48

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

54     public FormatDateTag() {
55         super();
56         init();
57     }
58
59
60     //*********************************************************************
61
// Tag logic
62

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

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

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

132
133     // 'value' attribute (mandatory)
134
value = (Date JavaDoc) ExpressionEvaluatorManager.evaluate(
135         "value", value_, Date JavaDoc.class, this, pageContext);
136
137     // 'type' attribute
138
if (type_ != null) {
139         type = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
140             "type", type_, String JavaDoc.class, this, pageContext);
141     }
142
143     // 'dateStyle' attribute
144
if (dateStyle_ != null) {
145         dateStyle = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
146             "dateStyle", dateStyle_, String JavaDoc.class, this, pageContext);
147     }
148
149     // 'timeStyle' attribute
150
if (timeStyle_ != null) {
151         timeStyle = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
152             "timeStyle", timeStyle_, String JavaDoc.class, this, pageContext);
153     }
154
155     // 'pattern' attribute
156
if (pattern_ != null) {
157         pattern = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
158             "pattern", pattern_, String JavaDoc.class, this, pageContext);
159     }
160
161     // 'timeZone' attribute
162
if (timeZone_ != null) {
163         timeZone = ExpressionEvaluatorManager.evaluate(
164             "timeZone", timeZone_, Object JavaDoc.class, this, pageContext);
165     }
166     }
167 }
168
Popular Tags