[Bedework-commit] webapps r368 - in trunk: webclient/war/WEB-INF webcommon/src/org/bedework/webcommon/misc

svnadmin at bedework.org svnadmin at bedework.org
Thu May 10 14:29:09 EDT 2007


Author: douglm
Date: 2007-05-10 14:29:00 -0400 (Thu, 10 May 2007)
New Revision: 368

Added:
   trunk/webcommon/src/org/bedework/webcommon/misc/WebCalendarAction.java
Modified:
   trunk/webclient/war/WEB-INF/struts-config.xml
Log:
First go at making calendars visible for external subscription e.g. google

Has "cat" request parameter to specify category.

Modified: trunk/webclient/war/WEB-INF/struts-config.xml
===================================================================
--- trunk/webclient/war/WEB-INF/struts-config.xml	2007-05-07 17:29:03 UTC (rev 367)
+++ trunk/webclient/war/WEB-INF/struts-config.xml	2007-05-10 18:29:00 UTC (rev 368)
@@ -723,6 +723,16 @@
 
     <!-- ........... PUBLIC and PERSONAL clients ...... -->
 
+    <action    path="/publish/calendar"
+               type="org.bedework.webcommon.misc.WebCalendarAction"
+               name="calForm"
+               scope="session"
+               validate="false">
+      <forward name="success" path="/misc/showExportData.rdo" redirect="true" />
+      <forward name="noAccess" path="/freeBusy/showFreeBusy.rdo" redirect="true" />
+      <forward name="notFound" path="/freeBusy/showFreeBusy.rdo" redirect="true" />
+    </action>
+
     <!-- renderUrl -->
     <action    path="/calendar/showPublicCals"
                type="org.bedework.webcommon.RenderAction"

Added: trunk/webcommon/src/org/bedework/webcommon/misc/WebCalendarAction.java
===================================================================
--- trunk/webcommon/src/org/bedework/webcommon/misc/WebCalendarAction.java	                        (rev 0)
+++ trunk/webcommon/src/org/bedework/webcommon/misc/WebCalendarAction.java	2007-05-10 18:29:00 UTC (rev 368)
@@ -0,0 +1,187 @@
+/* **********************************************************************
+    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.webcommon.misc;
+
+import org.bedework.appcommon.ClientError;
+import org.bedework.calfacade.BwCalendar;
+import org.bedework.calfacade.BwDateTime;
+import org.bedework.calfacade.RecurringRetrievalMode;
+import org.bedework.calfacade.RecurringRetrievalMode.Rmode;
+import org.bedework.calfacade.exc.CalFacadeAccessException;
+import org.bedework.calfacade.filter.BwFilter;
+import org.bedework.calfacade.filter.BwObjectFilter;
+import org.bedework.calfacade.svc.BwSubscription;
+import org.bedework.calfacade.svc.EventInfo;
+import org.bedework.calfacade.timezones.CalTimezones;
+import org.bedework.calfacade.util.CalFacadeUtil;
+import org.bedework.calfacade.util.PropertyIndex;
+import org.bedework.calfacade.util.PropertyIndex.PropertyInfo;
+import org.bedework.calsvci.CalSvcI;
+import org.bedework.icalendar.IcalTranslator;
+import org.bedework.icalendar.Icalendar;
+import org.bedework.webcommon.BwAbstractAction;
+import org.bedework.webcommon.BwActionFormBase;
+import org.bedework.webcommon.BwRequest;
+
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Action to publish a calendar as rfc formatted information
+ * <p>Request parameters - all optional:<ul>
+ *      <li>  userid:   whose free busy we want - default to current user</li>.
+ *      <li>  start:    start of period - default to beginning of this week</li>.
+ *      <li>  end:      end of period - default to end of this week</li>.
+ *      <li>  calPath:  required path to calendar</li>.
+ * </ul>
+ *
+ * <p>Forwards to:<ul>
+ *      <li>"noAction"     input error or we want to ignore the request.</li>
+ *      <li>"noAccess"     No acccess to free busy</li>
+ *      <li>"notFound"     event not found.</li>
+ *      <li>"error"        input error - correct and retry.</li>
+ *      <li>"success"      fetched OK.</li>
+ * </ul>
+ *
+ * <p>If no period is given return this week. If no interval and intunit is
+ * supplied default to 1 hour intervals during the workday.
+ *
+ * @author Mike Douglass douglm @ rpi.edu
+ */
+public class WebCalendarAction extends BwAbstractAction {
+  /* (non-Javadoc)
+   * @see org.bedework.webcommon.BwAbstractAction#doAction(org.bedework.webcommon.BwRequest, org.bedework.webcommon.BwActionFormBase)
+   */
+  public int doAction(BwRequest request,
+                      BwActionFormBase form) throws Throwable {
+    CalSvcI svci = form.fetchSvci();
+
+    gotoDateView(form, form.getDate(), form.getViewTypeI(), debug);
+
+    /*String userId = request.getReqPar("user");
+
+    if (userId != null) {
+      user = svci.findUser(userId, false);
+    } else if (!form.getGuest()) {
+      user = svci.getUser();
+    }*/
+
+    Locale loc = Locale.getDefault();  // XXX Locale
+    Calendar start = Calendar.getInstance(loc);
+    Calendar end = Calendar.getInstance(loc);
+
+    String st = request.getReqPar("start");
+
+    if (st != null) {
+      Date jdt = CalFacadeUtil.fromISODate(st);
+      start.setTime(jdt);
+    }
+
+    String et = request.getReqPar("end");
+
+    if (et == null) {
+      // 1 week
+      end.add(Calendar.WEEK_OF_YEAR, 1);
+    } else {
+      Date jdt = CalFacadeUtil.fromISODate(et);
+      end.setTime(jdt);
+    }
+
+    // Don't allow more than a month
+    Calendar check = Calendar.getInstance(loc);
+    check.setTime(start.getTime());
+    check.add(Calendar.DATE, 32);
+
+    if (check.before(end)) {
+      return forwardBadRequest;
+    }
+
+    BwCalendar cal = null;
+
+    String calPath = request.getReqPar("calPath");
+    if (calPath != null) {
+      cal = svci.getCalendar(calPath);
+      if (cal == null) {
+        return forwardNotFound;
+      }
+    }
+
+    BwFilter filter = null;
+
+    String cat = request.getReqPar("cat");
+    if (cat != null) {
+      PropertyInfo pi = PropertyIndex.propertyInfoByPname.get("CATEGORIES");
+      BwObjectFilter<String> f = new BwObjectFilter<String>(null, pi.getPindex());
+      f.setEntity(cat);
+      f.setExact(false);
+
+      filter = f;
+    }
+
+    CalTimezones tzs = svci.getTimezones();
+
+    try {
+      BwDateTime sdt = CalFacadeUtil.getDateTime(CalFacadeUtil.isoDate(start.getTime()),
+                                                 true, false, false, null, null,
+                                                 null, tzs);
+      BwDateTime edt = CalFacadeUtil.getDateTime(CalFacadeUtil.isoDate(end.getTime()),
+                                                 true, false, false, null, null,
+                                                 null, tzs);
+
+      if (debug) {
+        debugMsg("getEvents for start =  " + sdt +
+                 " end = " + edt);
+      }
+
+      BwSubscription sub = BwSubscription.makeSubscription(cal);
+
+      RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded,
+                                                              sdt, edt);
+      Collection<EventInfo> evs = svci.getEvents(sub, filter, sdt, edt, rrm);
+
+      IcalTranslator trans = new IcalTranslator(svci.getIcalCallback(), debug);
+
+      net.fortuna.ical4j.model.Calendar c = trans.toIcal(evs,
+                                                         Icalendar.methodTypePublish);
+
+      form.setContentName("freebusy.ics");
+      request.getResponse().setHeader("Content-Disposition",
+                                      "Attachment; Filename=\"freebusy.ics\"");
+      request.getResponse().setContentType("text/calendar");
+      form.getPresentationState().setNoXSLT(true);
+
+      //form.setVcal(IcalTranslator.toIcalString(ical));
+      IcalTranslator.writeCalendar(c, request.getResponse().getWriter());
+
+      return forwardNull;
+    } catch (CalFacadeAccessException cfae) {
+      form.getErr().emit(ClientError.noAccess);
+      return forwardNoAccess;
+    }
+  }
+}


Property changes on: trunk/webcommon/src/org/bedework/webcommon/misc/WebCalendarAction.java
___________________________________________________________________
Name: svn:eol-style
   + LF



More information about the Bedework-commit mailing list