FileDocCategorySizeDatePackage
CalEventMaker.javaAPI DocExample3364Thu Jul 31 11:40:46 BST 2003None

CalEventMaker

public class CalEventMaker extends HttpServlet
Program to generate an iCalendar event. Can be used as a main program or as a Servlet.

Fields Summary
static int
nEvent
static Random
r
private static NumberFormat
format4d
private static NumberFormat
format2d
Constructors Summary
Methods Summary
public voiddoGet(HttpServletRequest request, HttpServletResponse response)


		String event = request.getParameter("description");

		String yyStart = request.getParameter("yyStart");
		String mmStart = request.getParameter("mmStart");
		String ddStart = request.getParameter("ddStart");

		String yyEnd = request.getParameter("yyEnd");
		String mmEnd = request.getParameter("mmEnd");
		String ddEnd = request.getParameter("ddEnd");

		response.setContentType("ical");	// BLEARGH

		writeEvent(out, event,
			Integer.parseInt(yyStart),
			Integer.parseInt(mmStart),
			Integer.parseInt(ddStart),
			Integer.parseInt(yyEnd),
			Integer.parseInt(mmEnd),
			Integer.parseInt(ddEnd));
	
public static java.lang.Stringint2digit(int mm)

	     
		return format2d.format(mm);
	
public static java.lang.Stringint4digit(int yyyy)

	     
		return format4d.format(yyyy);
	
public static voidmain(java.lang.String[] args)


	       
		String TMPFILE = "j.ics";
		PrintWriter out = new PrintWriter(new FileWriter(TMPFILE));
		writeEvent(out, 
			args[0], 					// description
			Integer.parseInt(args[1]),	// mm start
			Integer.parseInt(args[2]),	// dd start
			Integer.parseInt(args[3]),	// mm end
			Integer.parseInt(args[4]));	// dd end
		out.close();
		// This is Mac OS X specific; on MS-Windows use "start".
		Runtime.getRuntime().exec("open" + ' " + TMPFILE);
	
public static voidwriteEvent(java.io.PrintWriter out, java.lang.String event, int startMon, int startDay, int endMon, int endDay)
Write an event in the current year

		int thisyear = Calendar.getInstance().get(Calendar.YEAR);
		writeEvent(out, event, 
			2003, startMon, startYear,
			2003, endMon, endYear);
	
public static voidwriteEvent(java.io.PrintWriter out, java.lang.String event, int startYear, int startMon, int startDay, int endYear, int endMon, int endDay)
Write an event.

param
out - the PrintWriter to use.
param
event - a textual description of the event.
param
startYear - starting year (e.g., 2010)
param
startMon - starting month (
param
startDay
param
endYear - ending year (e.g., 2010)
param
endMon
param
endDay

		out.println("BEGIN:VCALENDAR");
		out.println("CALSCALE:GREGORIAN");
		out.println("X-WR-TIMEZONE;VALUE=TEXT:Canada/Eastern");
		out.println("METHOD:PUBLISH");
		out.println("PRODID:-//Darwin Open Systems//CalEventMaker 1.0//EN");
		out.println("X-WR-CALNAME;VALUE=TEXT:Work");
		out.println("VERSION:2.0");
		out.println("BEGIN:VEVENT");
		out.println("SEQUENCE:" + nEvent++);
		out.println("UID:27F0307F-37A6-21D7-AD6A-" + r.nextInt(9999999));
		out.println("SUMMARY:" + event);
		out.println("STATUS:TENTATIVE");
		out.println("DTSTART;VALUE=DATE:" +
			int4digit(startYear) + int2digit(startMon) + int2digit(startDay));
		out.println("DTEND;VALUE=DATE:" +
			int4digit(endYear) + int2digit(endMon) + int2digit(endDay));
		out.println("END:VEVENT");
		out.println("END:VCALENDAR");