KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > resultset > GetDateTag


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 package org.apache.taglibs.dbtags.resultset;
17
18 import java.io.IOException JavaDoc;
19 import java.sql.Types JavaDoc;
20
21 import javax.servlet.jsp.JspTagException JavaDoc;
22
23 /**
24  * Translates a java.sql.Date to a readable String.
25  *
26  * <p>JSP Tag Lib Descriptor
27  * <pre>
28  * &LT;tag>
29  * &LT;name>getDate&LT;/name>
30  * &LT;tagclass>org.apache.taglibs.dbtags.resultset.GetDateTag&LT;/tagclass>
31  * &LT;teiclass>org.apache.taglibs.dbtags.resultset.BaseGetterTEI&LT;/teiclass>
32  * &LT;bodycontent>empty&LT;/bodycontent>
33  * &LT;info>
34  * Similar to getColumn, but provides more precise control over
35  * java.sql.Date formatting.
36  *
37  * The "format" attribute can be either a pattern as
38  * accepted by SimpleDateFormat or a style: "FULL",
39  * "LONG", "MEDIUM" or "SHORT".
40  *
41  * The "locale" attribute can have one to three
42  * components as accepted by the Locale constructor: language,
43  * country and variant. They are separated by "_".
44  *
45  * If neither the format nor locale attribute is set, output should be
46  * identical to getColumn.
47  * &LT;/info>
48  * &LT;attribute>
49  * &LT;name>position&LT;/name>
50  * &LT;required>false&LT;/required>
51  * &LT;rtexprvalue>false&LT;/rtexprvalue>
52  * &LT;/attribute>
53  * &LT;attribute>
54  * &LT;name>colName&LT;/name>
55  * &LT;required>false&LT;/required>
56  * &LT;rtexprvalue>false&LT;/rtexprvalue>
57  * &LT;/attribute>
58  * &LT;attribute>
59  * &LT;name>to&LT;/name>
60  * &LT;required>false&LT;/required>
61  * &LT;rtexprvalue>false&LT;/rtexprvalue>
62  * &LT;/attribute>
63  * &LT;attribute>
64  * &LT;name>scope&LT;/name>
65  * &LT;required>false&LT;/required>
66  * &LT;rtexprvalue>false&LT;/rtexprvalue>
67  * &LT;/attribute>
68  * &LT;attribute>
69  * &LT;name>locale&LT;/name>
70  * &LT;required>false&LT;/required>
71  * &LT;rtexprvalue>true&LT;/rtexprvalue>
72  * &LT;/attribute>
73  * &LT;attribute>
74  * &LT;name>format&LT;/name>
75  * &LT;required>false&LT;/required>
76  * &LT;rtexprvalue>true&LT;/rtexprvalue>
77  * &LT;/attribute>
78  * &LT;/tag>
79  * </pre>
80  *
81  * @author Morgan Delagrange
82  * @author Marius Scurtescu
83  */

84 public class GetDateTag extends BaseDateTimeGetterTag {
85
86   public int doStartTag() throws JspTagException JavaDoc {
87
88     try {
89       int position = getPosition();
90
91       String JavaDoc date = getDateAsString(position,Types.DATE);
92
93       // null results are often OK, in outer joins for example
94
if (date == null) {
95         return EVAL_BODY_INCLUDE;
96       }
97
98       if (_attributeName != null) {
99         setAttribute(_attributeName, date, _scope);
100       } else {
101         pageContext.getOut().write(date);
102       }
103     } catch (IOException JavaDoc e) {
104       throw new JspTagException JavaDoc(e.toString());
105     }
106
107     return EVAL_BODY_INCLUDE;
108
109   }
110
111 }
112
Popular Tags