import com.google.gdata.client.Query; import com.google.gdata.client.calendar.CalendarQuery; import com.google.gdata.client.calendar.CalendarService; import com.google.gdata.data.DateTime; import com.google.gdata.data.Link; import com.google.gdata.data.PlainTextConstruct; import com.google.gdata.data.batch.BatchOperationType; import com.google.gdata.data.batch.BatchStatus; import com.google.gdata.data.batch.BatchUtils; import com.google.gdata.data.calendar.CalendarEntry; import com.google.gdata.data.calendar.CalendarEventEntry; import com.google.gdata.data.calendar.CalendarEventFeed; import com.google.gdata.data.calendar.CalendarFeed; import com.google.gdata.data.calendar.WebContent; import com.google.gdata.data.extensions.ExtendedProperty; import com.google.gdata.data.extensions.Recurrence; import com.google.gdata.data.extensions.Reminder; import com.google.gdata.data.extensions.Reminder.Method; import com.google.gdata.data.extensions.When; import com.google.gdata.util.ServiceException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.TimeZone; import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class GoogleCalendar extends HttpServlet { private static final String METAFEED_URL_BASE = "http://www.google.com/calendar/feeds/"; private static final String EVENT_FEED_URL_SUFFIX = "/private/full"; private static URL metafeedUrl = null; private static URL eventFeedUrl = null; private static CalendarEventEntry createEvent(CalendarService service,String eventTitle, String eventContent, String recurData, boolean isQuickAdd, WebContent wc) throws ServiceException, IOException { CalendarEventEntry myEntry = new CalendarEventEntry(); myEntry.setTitle(new PlainTextConstruct(eventTitle)); myEntry.setContent(new PlainTextConstruct(eventContent)); myEntry.setQuickAdd(isQuickAdd); myEntry.setWebContent(wc); if (recurData == null) { Calendar calendar = new GregorianCalendar(); DateTime startTime = new DateTime(calendar.getTime(), TimeZone.getDefault()); calendar.add(Calendar.MINUTE, 30); DateTime endTime = new DateTime(calendar.getTime(), TimeZone.getDefault()); When eventTimes = new When(); eventTimes.setStartTime(startTime); eventTimes.setEndTime(endTime); myEntry.addTime(eventTimes); } else { Recurrence recur = new Recurrence(); recur.setValue(recurData); myEntry.setRecurrence(recur); } return service.insert(eventFeedUrl, myEntry); } private static CalendarEventEntry createSingleEvent(CalendarService service, String eventTitle, String eventContent) throws ServiceException, IOException { return createEvent(service, eventTitle, eventContent, null, false, null); } private static CalendarEventEntry createQuickAddEvent(CalendarService service, String quickAddContent) throws ServiceException, IOException { return createEvent(service, null, quickAddContent, null, true, null); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/xml"); PrintWriter out = response.getWriter(); String User = "rohit.jain.test@gmail.com"; String Password = "1234asdf"; try { metafeedUrl = new URL(METAFEED_URL_BASE + User); eventFeedUrl = new URL(METAFEED_URL_BASE +User+ EVENT_FEED_URL_SUFFIX); } catch (MalformedURLException e) { System.err.println("Uh oh - you've got an invalid URL."); e.printStackTrace(); return; } CalendarService myService = new CalendarService("Rohit"); try { myService.setUserCredentials(User,Password); CalendarEventFeed myFeed = myService.getFeed(eventFeedUrl, CalendarEventFeed.class); out.println(""); int count = myFeed.getEntries().size(); for (int i = 0; i < count; i++) { CalendarEventEntry entry = myFeed.getEntries().get(i); out.print("\t"); } } out.println(""); } catch (ServiceException e) { System.err.println("The server had a problem handling your request."); e.printStackTrace(); } } }