[Bedework-commit] r493 - in trunk/calendar3: http/src/org/bedework/http/client/caldav webcommon/src/org/bedework/webcommon webcommon/src/org/bedework/webcommon/misc webcommon/src/org/bedework/webcommon/subs

svnadmin at bedework.org svnadmin at bedework.org
Thu May 18 15:27:44 EDT 2006


Author: douglm
Date: 2006-05-18 15:27:43 -0400 (Thu, 18 May 2006)
New Revision: 493

Added:
   trunk/calendar3/http/src/org/bedework/http/client/caldav/MkcalendarMethod.java
Modified:
   trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java
   trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java
   trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/EndSubscribeAction.java
   trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/InitSubscribeAction.java
Log:
Reset the current selection when changes to views and subscriptions are made.

Add forgotten source for caldav client.

Start to enumerate all possible forwards from client actions.

Added: trunk/calendar3/http/src/org/bedework/http/client/caldav/MkcalendarMethod.java
===================================================================
--- trunk/calendar3/http/src/org/bedework/http/client/caldav/MkcalendarMethod.java	                        (rev 0)
+++ trunk/calendar3/http/src/org/bedework/http/client/caldav/MkcalendarMethod.java	2006-05-18 19:27:43 UTC (rev 493)
@@ -0,0 +1,86 @@
+/*
+ Copyright (c) 2000-2005 University of Washington.  All 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 the University of Washington
+   are not used in advertising or publicity without the express prior
+   written permission of the University of Washington;
+
+   Recipients acknowledge that this distribution is made available as a
+   research courtesy, "as is", potentially with defects, without
+   any obligation on the part of the University of Washington to
+   provide support, services, or repair;
+
+   THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
+   IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
+   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+   PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
+   WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+   DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+   PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
+   NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
+   THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/* **********************************************************************
+    Copyright 2005 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.http.client.caldav;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+
+/** The report method
+*
+* @author Mike Douglass  douglm @ rpi.edu
+*/
+public class MkcalendarMethod extends EntityEnclosingMethod {
+
+  /** Constructor
+   *
+   * @param uri
+   */
+  public MkcalendarMethod(String uri) {
+    super(uri);
+  }
+
+  public String getName() {
+    return "MKCALENDAR";
+  }
+
+  public void addRequestHeaders(HttpState st, HttpConnection conn)
+          throws IOException, HttpException {
+    super.addRequestHeaders(st, conn);
+    setRequestHeader("Content-Type", "text/xml");
+  }
+}

Modified: trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java
===================================================================
--- trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java	2006-05-18 15:04:06 UTC (rev 492)
+++ trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java	2006-05-18 19:27:43 UTC (rev 493)
@@ -73,6 +73,7 @@
 import org.bedework.calfacade.svc.BwAuthUser;
 import org.bedework.calfacade.svc.BwAuthUserPrefs;
 import org.bedework.calfacade.svc.BwSubscription;
+import org.bedework.calfacade.svc.BwView;
 import org.bedework.calfacade.svc.EventInfo;
 import org.bedework.calfacade.svc.UserAuth;
 import org.bedework.calsvc.CalSvc;
@@ -83,6 +84,7 @@
 import edu.rpi.sss.util.jsp.UtilAbstractAction;
 import edu.rpi.sss.util.jsp.UtilActionForm;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -106,6 +108,53 @@
   /** Name of the init parameter holding our name */
   private static final String appNameInitParameter = "rpiappname";
 
+  /* These are all the possible forwards we take. Internal routines should
+   * return one of the following indices.
+   */
+  // ENUM
+  protected int forwardSuccess = 0;
+  protected int forwardContinue = 1;
+  protected int forwardRetry = 2;
+
+  protected int forwardError = 3;
+  protected int forwardNoAccess = 4;
+
+  protected int forwardNotFound = 5;
+
+  protected int forwardNoSuchView = 6;
+
+  /* Set when an optional parameter is not found */
+  protected int forwardNoParameter = 7;
+
+  /* Set when no action was taken */
+  protected int forwardNoAction = 8;
+
+  /* Something is referenced and cannot be removed */
+  protected int forwardReffed = 9;
+
+  /* an object was added/updated */
+  protected int forwardAdded = 10;
+  protected int forwardUpdated = 11;
+
+  protected final String[] forwards = {
+    "success",
+    "continue",
+    "retry",
+    "error",
+    "noAccess",
+    "notFound",
+    "noSuchView",
+    "noParameter",
+    "noAction",
+    "reffed",
+    "added",
+    "updated",
+  };
+
+  /*
+   *  (non-Javadoc)
+   * @see edu.rpi.sss.util.jsp.UtilAbstractAction#getId()
+   */
   public String getId() {
     return getClass().getName();
   }
@@ -281,6 +330,30 @@
   protected void initFields(BwActionFormBase form) {
   }
 
+  /* Reset the current selection. Called after updates to views, subscriptions
+   * or calendars.
+   */
+  protected void resetSelection(BwActionFormBase form) throws CalFacadeException {
+    String seltype = form.getSelectionType();
+    CalSvcI svci = form.fetchSvci();
+    String name = null;
+
+    if (seltype.equals(BedeworkDefs.selectionTypeView)) {
+      BwView v = svci.getCurrentView();
+      if (v != null) {
+        name = v.getName();
+      }
+      setView(name, form);
+    } else if (seltype.equals(BedeworkDefs.selectionTypeSubscription)) {
+      // No refresh needed?
+    } else if (seltype.equals(BedeworkDefs.selectionTypeCalendar)) {
+      // No refresh needed?
+    } else {
+      // Set to default
+      setView(null, form);
+    }
+  }
+
   /* Set the view to the given name or the default if null.
    *
    * @return false for not found
@@ -308,6 +381,35 @@
     return true;
   }
 
+  /* Set the subscription to the given name or the default if null.
+   *
+   * @return int result code
+   */
+  protected int setSubscription(String name,
+                                BwActionFormBase form) throws CalFacadeException {
+    CalSvcI svci = form.fetchSvci();
+
+    if (name == null) {
+      return forwardNoParameter;
+    }
+
+    BwSubscription sub = svci.findSubscription(name);
+
+    if (sub == null) {
+      form.getErr().emit("org.bedework.client.error.unknownsubscription");
+      return forwardNotFound;
+    }
+
+    Collection c = new ArrayList();
+    c.add(sub.clone());
+    svci.setCurrentSubscriptions(c);
+    form.assignCurrentSubscriptions(c);
+    form.setSelectionType(BedeworkDefs.selectionTypeSubscription);
+
+    form.refreshIsNeeded();
+    return forwardSuccess;
+  }
+
   /** Method to find a subscription given its name. Expects a request parameter
    * "subname". Returns with the subscription or null set in the form.
    *
@@ -378,14 +480,14 @@
    * @param request
    * @param sub
    * @param form
-   * @return String "added" for added, "updated" for updated.
+   * @return int   result code
    * @throws Throwable
    */
-  protected String finishSubscribe(HttpServletRequest request,
+  protected int finishSubscribe(HttpServletRequest request,
                                    BwSubscription sub,
                                    BwActionFormBase form) throws Throwable {
     CalSvcI svc = form.fetchSvci();
-    String forward;
+    int result;
 
     String viewName = getReqPar(request, "view");
     boolean addToDefaultView = false;
@@ -401,38 +503,38 @@
     Boolean bool = getBooleanReqPar(request, "unremoveable");
     if (bool != null) {
       if (!form.getUserAuth().isSuperUser()) {
-        return "noAccess"; // Only super user for that flag
+        return forwardNoAccess; // Only super user for that flag
       }
 
       sub.setUnremoveable(bool.booleanValue());
     }
 
     if (!validateSub(sub, form)) {
-      return "retry";
+      return forwardRetry;
     }
 
     if (getReqPar(request, "addSubscription") != null) {
       try {
         svc.addSubscription(sub);
-        forward = "added";
+        result = forwardAdded;
       } catch (CalFacadeException cfe) {
         if (CalFacadeException.duplicateSubscription.equals(cfe.getMessage())) {
           form.getErr().emit(cfe.getMessage());
-          return "success"; // User will see message and we'll stay on page
+          return forwardSuccess; // User will see message and we'll stay on page
         }
 
         throw cfe;
       }
     } else if (getReqPar(request, "updateSubscription") != null) {
       svc.updateSubscription(sub);
-      forward = "updated";
+      result = forwardUpdated;
     } else {
-      forward = "noaction";
+      result = forwardNoAction;
     }
 
     if ((viewName == null) && !addToDefaultView) {
       // We're done - not adding to a view
-      return forward;
+      return result;
     }
 
     if (sub != null) {
@@ -441,7 +543,7 @@
 
     form.setSubscriptions(svc.getSubscriptions());
 
-    return forward;
+    return result;
   }
 
   /** Find a user object given a "user" request parameter.

Modified: trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java
===================================================================
--- trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java	2006-05-18 15:04:06 UTC (rev 492)
+++ trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java	2006-05-18 19:27:43 UTC (rev 493)
@@ -106,28 +106,13 @@
    */
   private String trySub(HttpServletRequest request,
                         BwActionFormBase form) throws Throwable {
-    CalSvcI svci = form.fetchSvci();
-    String name = getReqPar(request, "subname");
+    int result = setSubscription(getReqPar(request, "subname"), form);
 
-    if (name == null) {
+    if (result == forwardNoParameter) {
       return null;
     }
 
-    BwSubscription sub = svci.findSubscription(name);
-
-    if (sub == null) {
-      form.getErr().emit("org.bedework.client.error.unknownsubscription");
-      return "notFound";
-    }
-
-    Collection c = new ArrayList();
-    c.add(sub.clone());
-    svci.setCurrentSubscriptions(c);
-    form.assignCurrentSubscriptions(c);
-    form.setSelectionType(BedeworkDefs.selectionTypeSubscription);
-
-    form.refreshIsNeeded();
-    return "success";
+    return forwards[result];
   }
 
   /* Try for a calendar url. Return with forward or null for not found.

Modified: trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/EndSubscribeAction.java
===================================================================
--- trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/EndSubscribeAction.java	2006-05-18 15:04:06 UTC (rev 492)
+++ trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/EndSubscribeAction.java	2006-05-18 19:27:43 UTC (rev 493)
@@ -98,15 +98,21 @@
       return "noAccess"; // First line of defence
     }
 
+    int result;
+
     if (getReqPar(request, "delete") != null) {
-      return unsubscribe(request, form);
+      result = unsubscribe(request, form);
+    } else {
+      result = finishSubscribe(request, form.getSubscription(), form);
     }
 
-    return finishSubscribe(request, form.getSubscription(), form);
+    resetSelection(form);
+
+    return forwards[result];
   }
 
-  private String unsubscribe(HttpServletRequest request,
-                             BwActionFormBase form) throws Throwable {
+  private int unsubscribe(HttpServletRequest request,
+                          BwActionFormBase form) throws Throwable {
     CalSvcI svc = form.fetchSvci();
 
     String name = request.getParameter("name");
@@ -114,18 +120,18 @@
     if (name == null) {
       // Assume no access
       form.getErr().emit("org.bedework.client.error.missingfield", "name");
-      return "error";
+      return forwardError;
     }
 
     BwSubscription sub = svc.findSubscription(name);
 
     if (sub == null) {
       form.getErr().emit("org.bedework.client.error.nosuchsubscription", name);
-      return "notFound";
+      return forwardNotFound;
     }
 
     if (sub.getUnremoveable() && !form.getUserAuth().isSuperUser()) {
-      return "noAccess"; // Only super user can remove the unremovable
+      return forwardNoAccess; // Only super user can remove the unremovable
     }
 
     /* Check for references in views. For user extra simple mode only we will
@@ -144,7 +150,7 @@
           if (!svc.removeViewSubscription(v.getName(), sub)) {
             form.getErr().emit("org.bedework.client.error.viewnotfound",
                                v.getName());
-            return "error";
+            return forwardError;
           }
         } else {
           form.getErr().emit("org.bedework.client.error.subscription.reffed",
@@ -155,7 +161,7 @@
     }
 
     if (reffed) {
-      return "reffed";
+      return forwardReffed;
     }
 
     svc.removeSubscription(sub);
@@ -164,6 +170,6 @@
     /* Refetch to tidy up */
     form.setSubscriptions(svc.getSubscriptions());
 
-    return "success";
+    return forwardSuccess;
   }
 }

Modified: trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/InitSubscribeAction.java
===================================================================
--- trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/InitSubscribeAction.java	2006-05-18 15:04:06 UTC (rev 492)
+++ trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/InitSubscribeAction.java	2006-05-18 19:27:43 UTC (rev 493)
@@ -156,7 +156,7 @@
     form.setSubscription(sub);
 
     if (getReqPar(request, "addSubscription") != null) {
-      return finishSubscribe(request, sub, form);
+      return forwards[finishSubscribe(request, sub, form)];
     }
 
     form.assignAddingSubscription(true);



More information about the Bedework-commit mailing list