KickJava   Java API By Example, From Geeks To Geeks.

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


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

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