KickJava   Java API By Example, From Geeks To Geeks.

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


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

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