/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import com.sun.media.sound.JavaSoundAudioClip;
import java.applet.*;
import java.util.*;
import java.util.concurrent.*;
import java.awt.*;
import java.io.*;
import java.security.*;
import org.json.*;
/**
* This is the controller for the local calendar application
*/
public class CalendarController extends Applet {
public static final String DBNAME = "LocalCalDB";
private String calid;
private String gmtOffset;
private String user;
private String password;
private String startDay;
private String endDay;
private static PrintStream console;
private static final String CONSOLE_FILENAME = "localcal.log";
/** The calendar we're logged in to */
GCalendar calendar;
/** Indicates whether we're online or not */
boolean online = true;
/**
* Log in to the Google Calendar service.
*
* @param calid
* The calendar id. If this is your default Google Calendar,
* it's the email address you use to login to Google Calendar,
* e.g. "david.vancouvering@gmail.com".
*
* If it's not your default calendar, you can get the calendar id
* for the calendar you want by doing the following:
*
*
Go to your Google Calendar page
*
On the left pane all your calendars are listed. Click on the
* drop-down menu for the calendar you want, and choose
* "Calendar settings".
*
Under "Calendar Address" click on the [XML] button. A window
* will pop up that will give you a URL of the form
Your calendar id is "@group.calendar.google.com"
*
*
* @param gmtOffset
* The offset, positive or negative, from GMT for the time zone for
* the calendar
*
* @param user
* your username for your Google Calendar account, e.g.
* david.vancouvering@gmail.com
*
* @param password
* your password for your Google Calendar account
*
* @param startDay
* The starting day for this calendar in the format
* --
*
* @param endDay
* The ending day inclusive for this calendar, in the format
* --
*
* @return a JSON Array containing the list of events from Google
*/
public void login(String calid, String gmtOffset,
String user, String password, String startDay,
String endDay, boolean drop) throws Exception {
// Create the calendar, and if the login succeeds, start up the thread
log("DerbyCalendarApplet.login(" + calid + ", " + gmtOffset + ", " +
user + ", " + startDay + ", " + endDay + ")");
this.calid = calid;
this.gmtOffset = gmtOffset;
this.user = user;
this.password = password;
this.startDay = startDay;
this.endDay = endDay;
goOnline();
}
private void startConsole(String dir) throws Exception {
final String path = dir + "/" + CONSOLE_FILENAME;
AccessController.doPrivileged(
new PrivilegedExceptionAction