Changeset 493

Show
Ignore:
Timestamp:
05/18/06 15:27:43
Author:
douglm
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java

    r490 r493  
    7474import org.bedework.calfacade.svc.BwAuthUserPrefs; 
    7575import org.bedework.calfacade.svc.BwSubscription; 
     76import org.bedework.calfacade.svc.BwView; 
    7677import org.bedework.calfacade.svc.EventInfo; 
    7778import org.bedework.calfacade.svc.UserAuth; 
     
    8485import edu.rpi.sss.util.jsp.UtilActionForm; 
    8586 
     87import java.util.ArrayList; 
    8688import java.util.Collection; 
    8789import java.util.Iterator; 
     
    107109  private static final String appNameInitParameter = "rpiappname"; 
    108110 
     111  /* These are all the possible forwards we take. Internal routines should 
     112   * return one of the following indices. 
     113   */ 
     114  // ENUM 
     115  protected int forwardSuccess = 0; 
     116  protected int forwardContinue = 1; 
     117  protected int forwardRetry = 2; 
     118 
     119  protected int forwardError = 3; 
     120  protected int forwardNoAccess = 4; 
     121 
     122  protected int forwardNotFound = 5; 
     123 
     124  protected int forwardNoSuchView = 6; 
     125 
     126  /* Set when an optional parameter is not found */ 
     127  protected int forwardNoParameter = 7; 
     128 
     129  /* Set when no action was taken */ 
     130  protected int forwardNoAction = 8; 
     131 
     132  /* Something is referenced and cannot be removed */ 
     133  protected int forwardReffed = 9; 
     134 
     135  /* an object was added/updated */ 
     136  protected int forwardAdded = 10; 
     137  protected int forwardUpdated = 11; 
     138 
     139  protected final String[] forwards = { 
     140    "success", 
     141    "continue", 
     142    "retry", 
     143    "error", 
     144    "noAccess", 
     145    "notFound", 
     146    "noSuchView", 
     147    "noParameter", 
     148    "noAction", 
     149    "reffed", 
     150    "added", 
     151    "updated", 
     152  }; 
     153 
     154  /* 
     155   *  (non-Javadoc) 
     156   * @see edu.rpi.sss.util.jsp.UtilAbstractAction#getId() 
     157   */ 
    109158  public String getId() { 
    110159    return getClass().getName(); 
     
    282331  } 
    283332 
     333  /* Reset the current selection. Called after updates to views, subscriptions 
     334   * or calendars. 
     335   */ 
     336  protected void resetSelection(BwActionFormBase form) throws CalFacadeException { 
     337    String seltype = form.getSelectionType(); 
     338    CalSvcI svci = form.fetchSvci(); 
     339    String name = null; 
     340 
     341    if (seltype.equals(BedeworkDefs.selectionTypeView)) { 
     342      BwView v = svci.getCurrentView(); 
     343      if (v != null) { 
     344        name = v.getName(); 
     345      } 
     346      setView(name, form); 
     347    } else if (seltype.equals(BedeworkDefs.selectionTypeSubscription)) { 
     348      // No refresh needed? 
     349    } else if (seltype.equals(BedeworkDefs.selectionTypeCalendar)) { 
     350      // No refresh needed? 
     351    } else { 
     352      // Set to default 
     353      setView(null, form); 
     354    } 
     355  } 
     356 
    284357  /* Set the view to the given name or the default if null. 
    285358   * 
     
    307380    form.refreshIsNeeded(); 
    308381    return true; 
     382  } 
     383 
     384  /* Set the subscription to the given name or the default if null. 
     385   * 
     386   * @return int result code 
     387   */ 
     388  protected int setSubscription(String name, 
     389                                BwActionFormBase form) throws CalFacadeException { 
     390    CalSvcI svci = form.fetchSvci(); 
     391 
     392    if (name == null) { 
     393      return forwardNoParameter; 
     394    } 
     395 
     396    BwSubscription sub = svci.findSubscription(name); 
     397 
     398    if (sub == null) { 
     399      form.getErr().emit("org.bedework.client.error.unknownsubscription"); 
     400      return forwardNotFound; 
     401    } 
     402 
     403    Collection c = new ArrayList(); 
     404    c.add(sub.clone()); 
     405    svci.setCurrentSubscriptions(c); 
     406    form.assignCurrentSubscriptions(c); 
     407    form.setSelectionType(BedeworkDefs.selectionTypeSubscription); 
     408 
     409    form.refreshIsNeeded(); 
     410    return forwardSuccess; 
    309411  } 
    310412 
     
    379481   * @param sub 
    380482   * @param form 
    381    * @return String "added" for added, "updated" for updated. 
     483   * @return int   result code 
    382484   * @throws Throwable 
    383485   */ 
    384   protected String finishSubscribe(HttpServletRequest request, 
     486  protected int finishSubscribe(HttpServletRequest request, 
    385487                                   BwSubscription sub, 
    386488                                   BwActionFormBase form) throws Throwable { 
    387489    CalSvcI svc = form.fetchSvci(); 
    388     String forward
     490    int result
    389491 
    390492    String viewName = getReqPar(request, "view"); 
     
    402504    if (bool != null) { 
    403505      if (!form.getUserAuth().isSuperUser()) { 
    404         return "noAccess"; // Only super user for that flag 
     506        return forwardNoAccess; // Only super user for that flag 
    405507      } 
    406508 
     
    409511 
    410512    if (!validateSub(sub, form)) { 
    411       return "retry"
     513      return forwardRetry
    412514    } 
    413515 
     
    415517      try { 
    416518        svc.addSubscription(sub); 
    417         forward = "added"
     519        result = forwardAdded
    418520      } catch (CalFacadeException cfe) { 
    419521        if (CalFacadeException.duplicateSubscription.equals(cfe.getMessage())) { 
    420522          form.getErr().emit(cfe.getMessage()); 
    421           return "success"; // User will see message and we'll stay on page 
     523          return forwardSuccess; // User will see message and we'll stay on page 
    422524        } 
    423525 
     
    426528    } else if (getReqPar(request, "updateSubscription") != null) { 
    427529      svc.updateSubscription(sub); 
    428       forward = "updated"
     530      result = forwardUpdated
    429531    } else { 
    430       forward = "noaction"
     532      result = forwardNoAction
    431533    } 
    432534 
    433535    if ((viewName == null) && !addToDefaultView) { 
    434536      // We're done - not adding to a view 
    435       return forward
     537      return result
    436538    } 
    437539 
     
    442544    form.setSubscriptions(svc.getSubscriptions()); 
    443545 
    444     return forward
     546    return result
    445547  } 
    446548 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java

    r300 r493  
    107107  private String trySub(HttpServletRequest request, 
    108108                        BwActionFormBase form) throws Throwable { 
    109     CalSvcI svci = form.fetchSvci(); 
    110     String name = getReqPar(request, "subname"); 
     109    int result = setSubscription(getReqPar(request, "subname"), form); 
    111110 
    112     if (name == null) { 
     111    if (result == forwardNoParameter) { 
    113112      return null; 
    114113    } 
    115114 
    116     BwSubscription sub = svci.findSubscription(name); 
    117  
    118     if (sub == null) { 
    119       form.getErr().emit("org.bedework.client.error.unknownsubscription"); 
    120       return "notFound"; 
    121     } 
    122  
    123     Collection c = new ArrayList(); 
    124     c.add(sub.clone()); 
    125     svci.setCurrentSubscriptions(c); 
    126     form.assignCurrentSubscriptions(c); 
    127     form.setSelectionType(BedeworkDefs.selectionTypeSubscription); 
    128  
    129     form.refreshIsNeeded(); 
    130     return "success"; 
     115    return forwards[result]; 
    131116  } 
    132117 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/EndSubscribeAction.java

    r490 r493  
    9999    } 
    100100 
     101    int result; 
     102 
    101103    if (getReqPar(request, "delete") != null) { 
    102       return unsubscribe(request, form); 
     104      result = unsubscribe(request, form); 
     105    } else { 
     106      result = finishSubscribe(request, form.getSubscription(), form); 
    103107    } 
    104108 
    105     return finishSubscribe(request, form.getSubscription(), form); 
     109    resetSelection(form); 
     110 
     111    return forwards[result]; 
    106112  } 
    107113 
    108   private String unsubscribe(HttpServletRequest request, 
    109                              BwActionFormBase form) throws Throwable { 
     114  private int unsubscribe(HttpServletRequest request, 
     115                          BwActionFormBase form) throws Throwable { 
    110116    CalSvcI svc = form.fetchSvci(); 
    111117 
     
    115121      // Assume no access 
    116122      form.getErr().emit("org.bedework.client.error.missingfield", "name"); 
    117       return "error"
     123      return forwardError
    118124    } 
    119125 
     
    122128    if (sub == null) { 
    123129      form.getErr().emit("org.bedework.client.error.nosuchsubscription", name); 
    124       return "notFound"
     130      return forwardNotFound
    125131    } 
    126132 
    127133    if (sub.getUnremoveable() && !form.getUserAuth().isSuperUser()) { 
    128       return "noAccess"; // Only super user can remove the unremovable 
     134      return forwardNoAccess; // Only super user can remove the unremovable 
    129135    } 
    130136 
     
    145151            form.getErr().emit("org.bedework.client.error.viewnotfound", 
    146152                               v.getName()); 
    147             return "error"
     153            return forwardError
    148154          } 
    149155        } else { 
     
    156162 
    157163    if (reffed) { 
    158       return "reffed"
     164      return forwardReffed
    159165    } 
    160166 
     
    165171    form.setSubscriptions(svc.getSubscriptions()); 
    166172 
    167     return "success"
     173    return forwardSuccess
    168174  } 
    169175} 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/subs/InitSubscribeAction.java

    r487 r493  
    157157 
    158158    if (getReqPar(request, "addSubscription") != null) { 
    159       return finishSubscribe(request, sub, form)
     159      return forwards[finishSubscribe(request, sub, form)]
    160160    } 
    161161