KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > gnat > tstampTag


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.gnat;
18
19 import javax.servlet.jsp.*;
20 import javax.servlet.jsp.tagext.*;
21 import java.util.*;
22 import java.text.SimpleDateFormat JavaDoc;
23
24 /**
25  * Sets String variables named TSTAMP, DSTAMP and TODAY.
26  *
27  * @author costin@dnt.ro
28  * @author stefano@apache.org
29  * @author sstirling@mediaone.net
30  */

31
32 public class tstampTag extends TagSupport
33 {
34     public tstampTag()
35     {
36         super();
37     }
38     
39     Date d = null;
40     private SimpleDateFormat JavaDoc dstamp = null;
41     private SimpleDateFormat JavaDoc tstamp = null;
42     private SimpleDateFormat JavaDoc today = null;
43     private ResourceBundle gnatRB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatTagStrings");
44     private ResourceBundle gnatERB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatExceptionStrings");
45     
46     public int doStartTag()
47     {
48         return SKIP_BODY;
49     }
50
51     public int doEndTag() throws JspTagException
52     {
53         d = new Date();
54         
55         try
56         {
57             dstamp = new SimpleDateFormat JavaDoc ("yyyyMMdd");
58             pageContext.setAttribute("DSTAMP", dstamp.format(d));
59  
60             tstamp = new SimpleDateFormat JavaDoc ("HHmm");
61             pageContext.setAttribute("TSTAMP", tstamp.format(d));
62  
63             today = new SimpleDateFormat JavaDoc ("MMMM d yyyy", Locale.US);
64             pageContext.setAttribute("TODAY", today.format(d));
65         }
66         catch (Exception JavaDoc e)
67         {
68             throw new JspTagException(gnatRB.getString("tstamp.tag") +": "+e.getMessage());
69         }
70         return EVAL_PAGE;
71     }
72 }
73
Popular Tags