Source code: Demo/Calendar.java
1 /*********************************************************************************************
2 **********************************************************************************************
3 This Java servlet file should be placed in the WEB-INF/classes directory used by your
4 servlet engine (e.g., Tomcat or Resin), or in a subdirectory thereof. If in a subdirectory,
5 use the package statement below to identify the directory. Else, delete the package line.
6
7 The statements here simply modify variables that control the look and feel of the calendar.
8 Also, if the MySQL Events table doesn't already exist, this servlet creates it.
9 The main WebCalendar Java file is contained in the jar file webcalendar-1.12-src.jar, which
10 should be placed in the lib directory or elsewhere in the Java CLASSPATH used by the servlet
11 engine.
12
13 To compile this servlet, try the following (may need to be adjusted for your operating system
14 and configuration).
15 %> cd /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/
16 %> CLASSPATH=$CLASSPATH:/usr/local/tomcat/lib/webcalendar-1.12-src.jar
17 %> EXPORT CLASSPATH
18 %> javac Demo/Calendar.java
19
20 If successful, the calendar should now be accessible at the URL
21 http://yourserver.com/servlet/Demo.Calendar
22
23 You can run multiple WebCalendars by changing the subdirectory (which must match the package
24 name) or the Java filename (which must match the class name) or both.
25 **********************************************************************************************
26 *********************************************************************************************/
27
28 package Demo; // name of subdirectory holding this file (e.g., ...WEB-INF/classes/Demo)
29
30 import edu.utah.chem.wight.WebCalendar;
31 import java.text.SimpleDateFormat;
32 import java.sql.*;
33
34 public class Calendar extends WebCalendar { // class may be renamed
35 //(e.g. ClubCalendar extends WebCalendar)
36 public Calendar(){ // Constructor must have same name as the class name above
37 // these parameters may be changed to customize the look and feel of the calendar:
38 viewOnly = false; // true to disallow changes (for public viewing only)
39 eventsDatabase = "jdbc:mysql://localhost/DemoCalendar"; // location of the MySQL database
40 mySQLUser = "WebCalDemo"; // internal MySQL database user/password
41 mySQLPass = "demo";
42 authMessage = "For this demo version, the secret phrase is: KilroyWasHere";
43 secretPassPhrase = "KilroyWasHere"; // required by users to add,edit,delete events
44 cookieMaxAge = 1; // week
45 titleBar = "Demo WebCalendar for "; // label shown on the top bar of the Calendar
46 cTFontsColor = "#FFFF00"; // yellow
47 cTopBarColor = "#0000AA"; // dark blue
48 cDayBarColor = "#0000AA"; // dark blue
49 cOutDayColor = "#DDDDFF"; // light blue
50 cTodaysColor = "#E8E8E8"; // light gray
51 cBGCellColor = "#FFFFFF"; // white
52 cDtFontColor = "#000000"; // black
53 dfTimeField = new SimpleDateFormat("HH:mm"); // or try "h:mma" for AM/PM format
54 dfDateField = new SimpleDateFormat("M/d/yy"); // or try "d-M-yyyy" or "dMMMyyyy"
55
56 try {
57 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
58 Connection conn = DriverManager.getConnection(eventsDatabase,mySQLUser,mySQLPass);
59 Statement stmt = conn.createStatement();
60 stmt.executeUpdate("CREATE TABLE Events (EventID INT PRIMARY KEY AUTO_INCREMENT,Sdate "
61 + "DATETIME,Edate DATETIME,Description TEXT,Notes TEXT,User VARCHAR(50),Flagged INT)");
62 }
63 catch (Exception e) {
64 }
65 }
66 }