001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-app/src/java/org/sakaiproject/tool/podcasts/jsf/renderer/DatePickerPopupRenderer.java $
003: * $Id: DatePickerPopupRenderer.java 14691 2006-09-15 12:36:27Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.podcasts.jsf.renderer;
021:
022: import java.io.IOException;
023: import javax.faces.component.UIComponent;
024: import javax.faces.component.UIOutput;
025: import javax.faces.context.FacesContext;
026: import javax.faces.context.ResponseWriter;
027: import javax.faces.render.Renderer;
028: import java.util.*;
029: import java.text.*;
030:
031: /**
032: * <p>Description: </p>
033: * <p>Render the HTML code for a Tigris color picker popup.</p>
034: * <p>Organization: Sakai Project</p>
035: * @author Ed Smiley
036: * @version $id: $
037: *
038: * @todo add resource for strings
039: */
040:
041: public class DatePickerPopupRenderer extends Renderer {
042: // these should be coming from a resource
043: // value in alt tags, these are not yet internationalized
044: public static final String PREV_MONTH = "previous month";
045: public static final String NEXT_MONTH = "next month";
046: public static final String PREV_YEAR = "previous year";
047: public static final String NEXT_YEAR = "next year";
048:
049: public boolean supportsComponentType(UIComponent component) {
050: return (component instanceof UIOutput);
051: }
052:
053: public void decode(FacesContext context, UIComponent component) {
054: }
055:
056: public void encodeBegin(FacesContext context, UIComponent component)
057: throws IOException {
058: ;
059: }
060:
061: public void encodeChildren(FacesContext context,
062: UIComponent component) throws IOException {
063: ;
064: }
065:
066: // warning: considerable hand modification...
067: /* *** GENERATOR FILE: c:\Navigo\webapp\html\c.html*** */
068: /* *** IF SOURCE DOCUMENT CHANGES YOU NEED TO REGENERATE THIS METHOD*** */
069: /**
070: * <p>Faces render output method .</p>
071: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
072: *
073: * @param context <code>FacesContext</code> for the current request
074: * @param component <code>UIComponent</code> being rendered
075: *
076: * @throws IOException if an input/output error occurs
077: */
078: public void encodeEnd(FacesContext context, UIComponent component)
079: throws IOException {
080: // get the calendar for the Locale, so this will be localized
081: DateFormatSymbols dfs = new DateFormatSymbols();
082: String[] days = dfs.getShortWeekdays();
083: String[] months = dfs.getMonths();
084: String jan = months[Calendar.JANUARY];
085: String feb = months[Calendar.FEBRUARY];
086: String mar = months[Calendar.MARCH];
087: String apr = months[Calendar.APRIL];
088: String may = months[Calendar.MAY];
089: String jun = months[Calendar.JUNE];
090: String jul = months[Calendar.JULY];
091: String aug = months[Calendar.AUGUST];
092: String sep = months[Calendar.SEPTEMBER];
093: String oct = months[Calendar.OCTOBER];
094: String nov = months[Calendar.NOVEMBER];
095: String dec = months[Calendar.DECEMBER];
096: String mon = days[Calendar.MONDAY];
097: String tue = days[Calendar.TUESDAY];
098: String wed = days[Calendar.WEDNESDAY];
099: String thu = days[Calendar.THURSDAY];
100: String fri = days[Calendar.FRIDAY];
101: String sat = days[Calendar.SATURDAY];
102: String sun = days[Calendar.SUNDAY];
103:
104: String contextPath = context.getExternalContext()
105: .getRequestContextPath();
106:
107: ResponseWriter writer = context.getResponseWriter();
108:
109: writer.write("<!--\n");
110: writer.write("Title: Tigra Calendar\n");
111: writer
112: .write("URL: http://www.softcomplex.com/products/tigra_calendar/\n");
113: writer.write("Version: 3.2\n");
114: writer.write("Date: 10/14/2002 (mm/dd/yyyy)\n");
115: writer
116: .write("Feedback: feedback@softcCalendar calendar = new GregorianCalendar(pdt);omplex.com (specify product title in the subject)\n");
117: writer
118: .write("Note: Permission given to use this script in ANY kind of applications if\n");
119: writer.write(" header lines are left unchanged.\n");
120: writer
121: .write("Note: Script consists of two files: calendar?.js and calendar.html\n");
122: writer
123: .write("About us: Our company provides offshore IT consulting services.\n");
124: writer
125: .write(" Contact us at sales@softcomplex.com if you have any programming task you\n");
126: writer
127: .write(" want to be handled by professionals. Our typical hourly rate is $20.\n");
128: writer.write("-->\n");
129:
130: writer.write("<html>\n");
131: // writer.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
132: // writer.write(
133: // "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN>");
134: // writer.write("<html>\n");
135: writer.write("<head>\n");
136: writer.write("<title>Select Date, Please.</title>\n");
137: writer.write("<style>\n");
138: writer
139: .write(" td {font-family: Tahoma, Verdana, sans-serif; font-size: 12px;}\n");
140: writer.write("</style>\n");
141: writer.write("<script language=\"JavaScript\">\n");
142: writer.write("//<![CDATA[\n");
143: writer
144: .write("// months as they appear in the calendar's title\n");
145: writer
146: .write("// (These are dynamically built by locale DateFormatSymbols!)\n");
147: writer.write("var ARR_MONTHS = " + "[\"" + jan + "\", \"" + feb
148: + "\", " + "\"" + mar + "\", \"" + apr + "\", " + "\""
149: + may + "\", \"" + jun + "\",\n");
150: writer.write(" \"" + jul + "\", \"" + aug + "\", " + "\""
151: + sep + "\", \"" + oct + "\", \"" + nov + "\", \""
152: + dec + "\"];\n");
153: writer
154: .write("// week day titles as they appear on the calendar\n");
155: writer.write("var ARR_WEEKDAYS = " + "[\"" + sun + "\", \""
156: + mon + "\", \"" + tue + "\", " + "\"" + wed + "\", \""
157: + thu + "\", \"" + fri + "\", " + "\"Sa\"];\n");
158: writer
159: .write("// day week starts from (normally 0-Su or 1-Mo)\n");
160: writer.write("var NUM_WEEKSTART = 1;\n");
161: writer
162: .write("// path to the directory where calendar images are stored. trailing slash req.\n");
163: writer.write("var STR_ICONPATH = '" + contextPath
164: + "/images/calendar/';\n");
165: writer.write("\n");
166: writer
167: .write("var re_url = new RegExp('datetime=(\\-?\\d+)');\n");
168: writer
169: .write("var dt_current = (re_url.exec(String(window.location))\n");
170: writer
171: .write(" ? new Date(new Number(RegExp.$1)) : new Date());\n");
172: writer.write("var re_id = new RegExp('id=(\\d+)');\n");
173: writer
174: .write("var num_id = (re_id.exec(String(window.location))\n");
175: writer.write(" ? new Number(RegExp.$1) : 0);\n");
176: writer
177: .write("var obj_caller = (window.opener ? window.opener.calendars[num_id] : null);\n");
178: writer.write("var root_url = new RegExp('root=(\\S+)');\n");
179: writer
180: .write("var root = (root_url.exec(String(window.location)) ? new String(RegExp.$1) : \"\")\n");
181: writer.write("if (obj_caller && obj_caller.year_scroll) {\n");
182: writer.write(" // get same date in the previous year\n");
183: writer.write(" var dt_prev_year = new Date(dt_current);\n");
184: writer
185: .write(" dt_prev_year.setFullYear(dt_prev_year.getFullYear() - 1);\n");
186: writer
187: .write(" if (dt_prev_year.getDate() != dt_current.getDate())\n");
188: writer.write(" dt_prev_year.setDate(0);\n");
189: writer.write("\n");
190: writer.write(" // get same date in the next year\n");
191: writer.write(" var dt_next_year = new Date(dt_current);\n");
192: writer
193: .write(" dt_next_year.setFullYear(dt_next_year.getFullYear() + 1);\n");
194: writer
195: .write(" if (dt_next_year.getDate() != dt_current.getDate())\n");
196: writer.write(" dt_next_year.setDate(0);\n");
197: writer.write("}\n");
198: writer.write("\n");
199: writer.write("// get same date in the previous month\n");
200: writer.write("var dt_prev_month = new Date(dt_current);\n");
201: writer
202: .write("dt_prev_month.setMonth(dt_prev_month.getMonth() - 1);\n");
203: writer
204: .write("if (dt_prev_month.getDate() != dt_current.getDate())\n");
205: writer.write(" dt_prev_month.setDate(0);\n");
206: writer.write("\n");
207: writer.write("// get same date in the next month\n");
208: writer.write("var dt_next_month = new Date(dt_current);\n");
209: writer
210: .write("dt_next_month.setMonth(dt_next_month.getMonth() + 1);\n");
211: writer
212: .write("if (dt_next_month.getDate() != dt_current.getDate())\n");
213: writer.write(" dt_next_month.setDate(0);\n");
214: writer.write("\n");
215: writer
216: .write("// get first day to display in the grid for current month\n");
217: writer.write("var dt_firstday = new Date(dt_current);\n");
218: writer.write("dt_firstday.setDate(1);\n");
219: writer
220: .write("dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);\n");
221: writer.write("\n");
222: writer
223: .write("// function passing selected date to calling window\n");
224: writer.write("function set_datetime(n_datetime, b_close) {\n");
225: writer.write(" if (!obj_caller) return;\n");
226: writer.write("\n");
227: writer.write(" var dt_datetime = obj_caller.prs_time(\n");
228: writer
229: .write(" (document.cal ? document.cal.time.value : ''),\n");
230: writer.write(" new Date(n_datetime)\n");
231: writer.write(" );\n");
232: writer.write("\n");
233: writer.write(" if (!dt_datetime) return;\n");
234: writer.write(" if (b_close) {\n");
235: writer.write(" window.close();\n");
236: writer.write(" obj_caller.target.value = (document.cal\n");
237: writer.write(" ? obj_caller.gen_tsmp(dt_datetime)\n");
238: writer.write(" : obj_caller.gen_date(dt_datetime)\n");
239: writer.write(" );\n");
240: writer.write(" }\n");
241: writer
242: .write(" else obj_caller.popup(dt_datetime.valueOf());\n");
243: writer.write("}\n");
244: writer.write("\n");
245: writer
246: .write("function set_datetime_update(n_datetime, with_root) {\n");
247: writer.write(" if (!obj_caller) return;\n");
248: writer.write("\n");
249: writer.write(" var dt_datetime = obj_caller.prs_time(\n");
250: writer
251: .write(" (document.cal ? document.cal.time.value : ''),\n");
252: writer.write(" new Date(n_datetime)\n");
253: writer.write(" );\n");
254: writer.write("\n");
255: writer.write(" if (!dt_datetime) return;\n");
256: writer
257: .write(" obj_caller.popup(dt_datetime.valueOf(), with_root);\n");
258: writer.write("}\n");
259: writer.write("//]]> \n");
260: writer.write("</script>\n");
261: writer.write("</head>\n");
262: writer
263: .write("<body bgcolor=\"#FFFFFF\" marginheight=\"5\" marginwidth=\"5\" topmargin=\"5\" leftmargin=\"5\" rightmargin=\"5\">\n");
264: // replaced these lines with document.write so dom balanced in XHTML
265: // writer.write("<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n");
266: // writer.write("<tr><td bgcolor=\"#4682B4\">\n");
267: // writer.write("<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n");
268: // writer.write("<tr><td colspan=\"7\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n");
269: // writer.write("<tr>\n");
270: writer.write("<script language=\"JavaScript\">\n");
271: // writer.write("//<![CDATA[\n");
272: // writer.write("alert('got here');\n");
273: // writer.write("//<!--");
274: writer.write("document.write('<table>');");// class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">');\n");
275: // writer.write("document.write('<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">');\n");
276: writer
277: .write("document.write('<tr><td bgcolor=\"#4682B4\">');\n");
278: writer
279: .write("document.write('<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">');\n");
280: writer
281: .write("document.write('<tr><td colspan=\"7\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">');\n");
282: writer.write("document.write('<tr>');\n");
283: // following document.write() in original HTML/JavaScript was
284: // nearly incomprehensible when generated into writer.write lines
285: // broke up into shorter strings, hopefully more readable
286: writer.write("document.write(\n");
287: writer.write("'<td>'+"
288: +
289: //using JavaScript ? operator
290: "(obj_caller && obj_caller.year_scroll?"
291: +
292: // first alternative
293: "'<a href=\"javascript:set_datetime_update('"
294: + "+dt_prev_year.valueOf()+', root)\">"
295: + "<img src=\"'+STR_ICONPATH+'prev_year.gif\" "
296: + "width=\"16\" height=\"16\" border=\"0\" alt=\""
297: + PREV_YEAR
298: + "\"/></a> '"
299: + ":"
300: +
301: // second alternative, a blank
302: "'')+" + "'<a href=\"javascript:set_datetime_update("
303: + "'+dt_prev_month.valueOf()+', root)\">"
304: + "<img src=\"'+STR_ICONPATH+'prev.gif\" "
305: + "width=\"16\" height=\"16\" border=\"0\" alt=\""
306: + PREV_MONTH + "\"/></a></td>'+\n");
307: writer.write("'<td align=\"center\" width=\"100%\">"
308: + "<font color=\"#ffffff\">'+"
309: + "ARR_MONTHS[dt_current.getMonth()]+' '+"
310: + "dt_current.getFullYear() + '</font></td>'+\n");
311: writer.write("'<td><a href=\"javascript:set_datetime_update('"
312: + "+dt_next_month.valueOf()+', root)\">"
313: + "<img src=\"'+STR_ICONPATH+'next.gif\" "
314: + "width=\"16\" height=\"16\" border=\"0\" alt=\""
315: + NEXT_MONTH
316: + "\"/></a>'+"
317: + // ? operator, again...
318: "(obj_caller && obj_caller.year_scroll?"
319: +
320: //first alternative
321: "' <a href=\"javascript:set_datetime_update("
322: + "'+dt_next_year.valueOf()+', root)\">"
323: + "<img src=\"'+STR_ICONPATH+'next_year.gif\" "
324: + "width=\"16\" height=\"16\" border=\"0\" alt=\""
325: + NEXT_YEAR + "\"/></a>'" + ":" +
326: //second alternative, blank
327: "'')" + "+'</td>'\n");
328: writer.write(");\n");
329: writer.write("document.write('</tr>');\n");
330: writer.write("document.write('</table></td></tr>');\n");
331: writer.write("document.write('<tr>')\n");
332: // replaced these lines with document.write so dom balanced in XHTML
333: // writer.write("</script>\n");
334: // writer.write("</tr>\n");
335: // writer.write("</table></td></tr>\n");
336: // writer.write("<tr>\n");
337: // writer.write("<script language=\"JavaScript\">\n");
338: writer.write("\n");
339: writer.write("// print weekdays titles\n");
340: writer.write("for (var n=0; n < 7; n++)\n");
341: writer
342: .write(" document.write('<td bgcolor=\"#87cefa\" align=\"center\"><font color=\"#ffffff\">'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+'</font></td>');\n");
343: writer.write("document.write('</tr>');\n");
344: writer.write("\n");
345: writer.write("// print calendar table\n");
346: writer.write("var dt_current_day = new Date(dt_firstday);\n");
347: writer
348: .write("while (dt_current_day.getMonth() == dt_current.getMonth() ||\n");
349: writer
350: .write(" dt_current_day.getMonth() == dt_firstday.getMonth()) {\n");
351: writer.write(" // print row heder\n");
352: writer.write(" document.write('<tr>');\n");
353: writer
354: .write(" for (var n_current_wday=0; n_current_wday < 7; n_current_wday++) {\n");
355: writer
356: .write(" if (dt_current_day.getDate() == dt_current.getDate() && \n");
357: writer
358: .write(" dt_current_day.getMonth() == dt_current.getMonth())\n");
359: writer.write(" // print current date\n");
360: writer
361: .write(" document.write('<td bgcolor=\"#ffb6c1\" align=\"center\" width=\"14%\">');\n");
362: writer
363: .write(" else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)\n");
364: writer.write(" // weekend days\n");
365: writer
366: .write(" document.write('<td bgcolor=\"#dbeaf5\" align=\"center\" width=\"14%\">');\n");
367: writer.write(" else\n");
368: writer.write(" // print working days of current month\n");
369: writer
370: .write(" document.write('<td bgcolor=\"#ffffff\" align=\"center\" width=\"14%\">');\n");
371: writer.write("\n");
372: writer
373: .write(" document.write('<a href=\"javascript:set_datetime('+dt_current_day.valueOf() +', true);\">');\n");
374: writer.write("\n");
375: writer
376: .write(" if (dt_current_day.getMonth() == this.dt_current.getMonth())\n");
377: writer.write(" // print days of current month\n");
378: writer
379: .write(" document.write('<font color=\"#000000\">');\n");
380: writer.write(" else\n");
381: writer.write(" // print days of other months\n");
382: writer
383: .write(" document.write('<font color=\"#606060\">');\n");
384: writer.write("\n");
385: writer
386: .write(" document.write(dt_current_day.getDate()+'</font></font></a></td>');\n");
387: writer
388: .write(" dt_current_day.setDate(dt_current_day.getDate()+1);\n");
389: writer.write(" }\n");
390: writer.write(" // print row footer\n");
391: writer.write(" document.write('</td></td></tr>');\n");
392: writer.write("}\n");
393: writer.write("if (obj_caller && obj_caller.time_comp)\n");
394: writer
395: .write(" document.write('<form onsubmit=\"javascript:set_datetime('+dt_current.valueOf()+', true)\" name=\"cal\"><tr><td colspan=\"7\" bgcolor=\"#87CEFA\"><font color=\"White\" face=\"tahoma, verdana\" size=\"2\">Time: <input type=\"text\" name=\"time\" value=\"'+obj_caller.gen_time(this.dt_current)+'\" size=\"8\" maxlength=\"8\"/></font></td></tr></form>');\n");
396: writer.write("document.write('</table></td></tr></table>');\n");
397: // writer.write("//]]> \n");
398: writer.write("</script>\n");
399: // replaced these lines with document.write so DOM balanced in XHTML
400: // writer.write("</tr></td>\n");
401: // writer.write("</table></tr></td>\n");
402: // writer.write("</table>\n");
403: writer.write("</body>\n");
404: writer.write("</html>\n");
405: writer.write("\n");
406: }
407: }
|