KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > dialoglayout > www > CalendarInitTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: CalendarInitTag.java,v 1.11 2007/01/07 06:14:28 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.dialoglayout.www;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26
27 import org.opensubsystems.core.util.DateUtils;
28 import org.opensubsystems.core.www.PageElementCacheTag;
29
30 /**
31  * Custom tag to initialize the calendar component. This needs to be the first
32  * tag of all calendar tags and should be placed in the page before the html
33  * tag. The <core:pagecache id="xyz"/> in emptypage.jsp layout will take the
34  * elements put into cache by this tag and place them at a correct location.
35  *
36  * @version $Id: CalendarInitTag.java,v 1.11 2007/01/07 06:14:28 bastafidli Exp $
37  * @author Julian Legeny
38  * @code.reviewer Miro Halas
39  * @code.reviewed 1.8 2006/02/17 06:54:14 bastafidli
40  */

41 public class CalendarInitTag extends PageElementCacheTag
42 {
43    // Attributes ///////////////////////////////////////////////////////////////
44

45    /**
46     * Generated serial version id for this class.
47     */

48    private static final long serialVersionUID = -4019110758209153477L;
49
50    /**
51     * Name of the attribute for datetime format
52     * TODO: For Julo: You are missing test demonstrating how to use this attribute.
53     * Once you add it update the example in the tld.
54     */

55    protected String JavaDoc m_strDatetime;
56
57    /**
58     * Name of the attribute for date format
59     * TODO: For Julo: You are missing test demonstrating how to use this attribute.
60     * Once you add it update the example in the tld.
61     */

62    protected String JavaDoc m_strDate;
63
64    /**
65     * Name of the attribute for time format
66     * TODO: For Julo: You are missing test demonstrating how to use this attribute.
67     * Once you add it update the example in the tld.
68     */

69    protected String JavaDoc m_strTime;
70
71    // Constructors /////////////////////////////////////////////////////////////
72

73    /**
74     * Constructor for custom tag.
75     */

76    public CalendarInitTag()
77    {
78       super();
79       
80       // set up default values
81
m_strDatetime = DateUtils.DATETIME_STORE_FORMAT.toPattern();
82       m_strDate = DateUtils.DATE_STORE_FORMAT.toPattern();
83       m_strTime = DateUtils.TIME_STORE_FORMAT.toPattern();
84    }
85    
86    // Business logic ///////////////////////////////////////////////////////////
87

88    /**
89     * {@inheritDoc}
90     */

91    public int doStartTag(
92    ) throws JspException JavaDoc
93    {
94       String JavaDoc contextpath;
95       StringBuffer JavaDoc sbBuffer = new StringBuffer JavaDoc();
96
97       contextpath = ((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath();
98
99       /*
100       <link HREF="<%=contextpath%>/css/calendar-win2k-1.css"
101             rel="StyleSheet" type="text/css" media="screen">
102       <link HREF="<%=contextpath%>/patterns/css/calendar.css"
103             rel="StyleSheet" type="text/css" media="screen">
104       <script type="text/javascript" language="JavaScript"
105               src="<%=contextpath%>/js/calendar.js"></script>
106       <script type="text/javascript" language="JavaScript"
107               src="<%=contextpath%>/js/calendar-setup.js"></script>
108       <script type="text/javascript" language="JavaScript"
109               src="<%=contextpath%>/js/calendar-en.js"></script>
110       <script type="text/javascript" language="JavaScript"
111               src="<%=contextpath%>/patterns/js/calendar.js"></script>
112       <!--
113          Define global variables used for storing datetime format.
114          We will create 3 global variables:
115          1. datetime format
116          2. only date format
117          3. only time format
118       -->
119       <script type="text/javascript" language="JavaScript">
120          var CALENDAR_DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
121          var CALENDAR_DATE_FORMAT = "yyyy-MM-dd";
122          var CALENDAR_TIME_FORMAT = "HH:mm";
123       </script>
124       */

125       sbBuffer.delete(0, sbBuffer.length());
126       sbBuffer.append("<link HREF=\"");
127       sbBuffer.append(contextpath);
128       sbBuffer.append("/css/calendar-win2k-1.css\" rel=\"StyleSheet\"" +
129                       " type=\"text/css\" media=\"screen\">");
130       cache(PageElementCacheTag.CSS_ELEMENT, sbBuffer.toString());
131
132       sbBuffer.delete(0, sbBuffer.length());
133       sbBuffer.append("<link HREF=\"");
134       sbBuffer.append(contextpath);
135       sbBuffer.append("/patterns/css/calendar.css\" rel=\"StyleSheet\"" +
136                       " type=\"text/css\" media=\"screen\">");
137       cache(PageElementCacheTag.CSS_ELEMENT, sbBuffer.toString());
138
139       sbBuffer.delete(0, sbBuffer.length());
140       sbBuffer.append("<script type=\"text/javascript\" language=\"JavaScript\" SRC=\"");
141       sbBuffer.append(contextpath);
142       sbBuffer.append("/js/calendar.js\"></script>");
143       cache(PageElementCacheTag.JS_ELEMENT, sbBuffer.toString());
144
145       sbBuffer.delete(0, sbBuffer.length());
146       sbBuffer.append("<script type=\"text/javascript\" language=\"JavaScript\" SRC=\"");
147       sbBuffer.append(contextpath);
148       sbBuffer.append("/js/calendar-setup.js\"></script>");
149       cache(PageElementCacheTag.JS_ELEMENT, sbBuffer.toString());
150
151       sbBuffer.delete(0, sbBuffer.length());
152       sbBuffer.append("<script type=\"text/javascript\" language=\"JavaScript\" SRC=\"");
153       sbBuffer.append(contextpath);
154       sbBuffer.append("/js/calendar-en.js\"></script>");
155       cache(PageElementCacheTag.JS_ELEMENT, sbBuffer.toString());
156
157       sbBuffer.delete(0, sbBuffer.length());
158       sbBuffer.append("<script type=\"text/javascript\" language=\"JavaScript\" SRC=\"");
159       sbBuffer.append(contextpath);
160       sbBuffer.append("/patterns/js/calendar.js\"></script>");
161       cache(PageElementCacheTag.JS_ELEMENT, sbBuffer.toString());
162
163       // following global variables will be generated within the <script> body
164
// of the emptypage.jsp
165
sbBuffer.delete(0, sbBuffer.length());
166       sbBuffer.append(" var CALENDAR_DATETIME_FORMAT = '");
167       sbBuffer.append(m_strDatetime);
168       sbBuffer.append("';\n");
169       sbBuffer.append(" var CALENDAR_DATE_FORMAT = '");
170       sbBuffer.append(m_strDate);
171       sbBuffer.append("';\n");
172       sbBuffer.append(" var CALENDAR_TIME_FORMAT = '");
173       sbBuffer.append(m_strTime);
174       sbBuffer.append("';\n");
175       cache(PageElementCacheTag.SCRIPT_ELEMENT, sbBuffer.toString());
176
177       return (SKIP_BODY);
178    }
179
180    /**
181     * {@inheritDoc}
182     */

183    public int doEndTag(
184    ) throws JspException JavaDoc
185    {
186       return (EVAL_PAGE);
187    }
188    
189    /**
190     * @return String - Datetime format
191     */

192    public String JavaDoc getDatetime()
193    {
194       return m_strDatetime;
195    }
196
197    /**
198     * @return String - Date format
199     */

200    public String JavaDoc getDatet()
201    {
202       return m_strDate;
203    }
204
205    /**
206     * @return String - Time format
207     */

208    public String JavaDoc getTime()
209    {
210       return m_strTime;
211    }
212
213    /**
214     * @param strDatetime - Datetime format
215     */

216    public void setDatetime(
217       String JavaDoc strDatetime
218    )
219    {
220       m_strDatetime = strDatetime;
221    }
222
223    /**
224     * @param strDate - Date format
225     */

226    public void setDate(
227       String JavaDoc strDate
228    )
229    {
230       m_strDate = strDate;
231    }
232
233    /**
234     * @param strTime - Time format
235     */

236    public void setTime(
237       String JavaDoc strTime
238    )
239    {
240       m_strTime = strTime;
241    }
242 }
243
Popular Tags