Changeset 469

Show
Ignore:
Timestamp:
05/12/06 12:37:23
Author:
douglm
Message:

Change getSpecialCalendar to optionally create. Avoids hibernate problem.

Change free/busy response to be at caldav12

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java

    r466 r469  
    285285 
    286286  public BwCalendar getSpecialCalendar(BwUser user, 
    287                                        int calType) throws CalFacadeException { 
     287                                       int calType, 
     288                                       boolean create) throws CalFacadeException { 
    288289    StringBuffer sb = new StringBuffer(); 
    289290    String name; 
     
    316317    BwCalendar cal = getCalendar(sb.toString(), privRead); 
    317318 
    318     if (cal != null) { 
     319    if ((cal != null) || !create) { 
    319320      return cal; 
    320321    } 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r466 r469  
    871871 
    872872  public BwCalendar getSpecialCalendar(BwUser user, 
    873                                        int calType) throws CalFacadeException { 
    874     return calendars.getSpecialCalendar(user, calType); 
     873                                       int calType, 
     874                                       boolean create) throws CalFacadeException { 
     875    return calendars.getSpecialCalendar(user, calType, create); 
    875876  } 
    876877 
     
    11231124 
    11241125  public Collection getDeletedProxies() throws CalFacadeException { 
    1125     BwCalendar cal = getSpecialCalendar(user, BwCalendar.calTypeDeleted); 
     1126    BwCalendar cal = getSpecialCalendar(user, BwCalendar.calTypeDeleted, false); 
    11261127 
    11271128    if (cal == null) { 
    1128       // Not supported 
     1129      // Not supported or never deleted anything 
    11291130      return new ArrayList(); 
    11301131    } 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java

    r466 r469  
    473473 
    474474  public BwCalendar getSpecialCalendar(BwUser user, 
    475                                        int calType) throws CalFacadeException { 
     475                                       int calType, 
     476                                       boolean create) throws CalFacadeException { 
    476477    throw new CalFacadeUnimplementedException(); 
    477478  } 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java

    r466 r469  
    188188   * @param  user 
    189189   * @param  calType   int special calendar type. 
     190   * @param  create    true if we shoudl create it if non-existant. 
    190191   * @return BwCalendar null for unknown calendar 
    191192   * @throws CalFacadeException 
    192193   */ 
    193194  public BwCalendar getSpecialCalendar(BwUser user, 
    194                                        int calType) throws CalFacadeException; 
     195                                       int calType, 
     196                                       boolean create) throws CalFacadeException; 
    195197 
    196198  /** Add a calendar object 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java

    r423 r469  
    7676import org.w3c.dom.Element; 
    7777 
     78import java.io.Reader; 
     79import java.io.Writer; 
    7880import java.util.ArrayList; 
    7981import java.util.Collection; 
     
    140142    } 
    141143 
    142     processResp(req, resp, depth); 
     144    if (reportType == reportTypeFreeBusy) { 
     145      processFbResp(req, resp); 
     146    } else { 
     147      processResp(req, resp, depth); 
     148    } 
    143149  } 
    144150 
     
    386392        } 
    387393      } 
    388     } else if (reportType == reportTypeFreeBusy) { 
    389       try { 
    390         nodes = intf.getFreeBusy(node, freeBusy); 
    391       } catch (WebdavException wde) { 
    392         if (debug) { 
    393           trace("intf.getFreeBusy exception"); 
    394         } 
    395         status = wde.getStatusCode(); 
    396       } 
    397394    } else if (reportType == reportTypeExpandProperty) { 
    398395    } 
     
    417414 
    418415    flush(); 
     416  } 
     417 
     418  /** Handle free/busy response 
     419   * 
     420   * @param req 
     421   * @param resp 
     422   * @param depth 
     423   * @throws WebdavException 
     424   */ 
     425  public void processFbResp(HttpServletRequest req, 
     426                            HttpServletResponse resp) throws WebdavException { 
     427    resp.setStatus(HttpServletResponse.SC_OK); 
     428    resp.setContentType("text/calendar; charset=UTF-8"); 
     429 
     430    String resourceUri = getResourceUri(req); 
     431 
     432    CaldavBWIntf intf = (CaldavBWIntf)getNsIntf(); 
     433    WebdavNsNode node = intf.getNode(resourceUri); 
     434 
     435    int status = HttpServletResponse.SC_OK; 
     436 
     437    Collection nodes = null; 
     438 
     439    try { 
     440      nodes = intf.getFreeBusy(node, freeBusy); 
     441    } catch (WebdavException wde) { 
     442      if (debug) { 
     443        trace("intf.getFreeBusy exception"); 
     444      } 
     445      status = wde.getStatusCode(); 
     446    } 
     447 
     448    if (status != HttpServletResponse.SC_OK) { 
     449      if (debug) { 
     450        trace("REPORT status " + status); 
     451      } 
     452      // Entire request failed. 
     453      node.setStatus(status); 
     454      doNode(node); 
     455    } else if (nodes != null) { 
     456      Iterator it = nodes.iterator(); 
     457 
     458      // XXX Only one node? 
     459      while (it.hasNext()) { 
     460        WebdavNsNode curnode = (WebdavNsNode)it.next(); 
     461 
     462        if (!(node instanceof CaldavCalNode)) { 
     463          if (debug) { 
     464            trace("Expected CaldavCalNode - got " + node); 
     465          } 
     466          status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 
     467        } else { 
     468          CaldavCalNode cnode = (CaldavCalNode)node; 
     469 
     470          Writer out; 
     471          try { 
     472            out = resp.getWriter(); 
     473          } catch (Throwable t) { 
     474            throw new WebdavException(t); 
     475          } 
     476 
     477          /** Get the content now to set up length, type etc. 
     478           */ 
     479          Reader in = getNsIntf().getContent(node); 
     480          resp.setContentLength(node.getContentLen()); 
     481          if (in == null) { 
     482            if (debug) { 
     483              debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT); 
     484            } 
     485 
     486            resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 
     487          } else { 
     488            if (debug) { 
     489              debugMsg("send content - length=" + node.getContentLen()); 
     490            } 
     491 
     492            writeContent(in, out); 
     493          } 
     494        } 
     495      } 
     496    } 
     497 
     498    flush(); 
     499  } 
     500 
     501  // XXX Make the following part of the interface. 
     502 
     503  /** size of buffer used for copying content to response. 
     504   */ 
     505  private static final int bufferSize = 4096; 
     506 
     507  private void writeContent(Reader in, Writer out) 
     508      throws WebdavException { 
     509    try { 
     510      char[] buff = new char[bufferSize]; 
     511      int len; 
     512 
     513      while (true) { 
     514        len = in.read(buff); 
     515 
     516        if (len < 0) { 
     517          break; 
     518        } 
     519 
     520        out.write(buff, 0, len); 
     521      } 
     522    } catch (Throwable t) { 
     523      throw new WebdavException(t); 
     524    } finally { 
     525      try { 
     526        in.close(); 
     527      } catch (Throwable t) {} 
     528      try { 
     529        out.close(); 
     530      } catch (Throwable t) {} 
     531    } 
    419532  } 
    420533 
     
    440553          } 
    441554        } 
    442       } else if (reportType == reportTypeFreeBusy) { 
    443         if (!(node instanceof CaldavCalNode)) { 
    444           if (debug) { 
    445             trace("Expected CaldavCalNode - got " + node); 
    446           } 
    447           status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 
    448         } else { 
    449           CaldavCalNode cnode = (CaldavCalNode)node; 
    450  
    451           content = cnode.getContentString(); 
    452         } 
    453555      } 
    454556    } 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r466 r469  
    17021702      event.setDeleted(true); 
    17031703      event.setCalendar(getCal().getSpecialCalendar(event.getOwner(), 
    1704                                                     BwCalendar.calTypeTrash)); 
     1704                                                    BwCalendar.calTypeTrash, 
     1705                                                    true)); 
    17051706      updateEvent(event); 
    17061707      return; 
     
    17121713 
    17131714    // Where does the ref go? Not in the same calendar - we have no access 
    1714     // Put it in the trash - but don't delete on empty trash 
    17151715 
    17161716    BwCalendar cal = getCal().getSpecialCalendar(getUser(), 
    1717                                                  BwCalendar.calTypeTrash); 
     1717                                                 BwCalendar.calTypeDeleted, 
     1718                                                 true); 
    17181719    proxy.setOwner(getUser()); 
    17191720    proxy.setDeleted(true); 
  • trunk/calendar3/config/configs/democal.options.xml

    r463 r469  
    3838        <defaultUserViewName>All</defaultUserViewName> 
    3939 
    40         <publicUser>user</publicUser> 
     40        <publicUser>public-user</publicUser> 
    4141 
    4242        <httpConnectionsPerUser>10</httpConnectionsPerUser> 
  • trunk/calendar3/config/configs/democal.properties

    r468 r469  
    214214org.bedework.app.dumpres.description=Bedework dump/restore utility 
    215215org.bedework.app.dumpres.version=3.1 
    216 org.bedework.app.dumpres.dumpfile=${calendar.dir}/dumprestore/initcaldata.xml 
    217216org.bedework.app.dumpres.hibernate.dialect=org.hibernate.dialect.HSQLDialect 
    218217org.bedework.app.dumpres.jdbcdriver=org.hsqldb.jdbcDriver 
  • trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java

    r418 r469  
    5757import org.bedework.calfacade.BwCalendar; 
    5858import org.bedework.calfacade.BwEvent; 
     59import org.bedework.calfacade.BwFreeBusy; 
    5960import org.bedework.calfacade.BwUser; 
    6061import org.bedework.calfacade.CalFacadeException; 
     
    6970import net.fortuna.ical4j.model.Calendar; 
    7071import net.fortuna.ical4j.model.component.VEvent; 
     72import net.fortuna.ical4j.model.component.VFreeBusy; 
    7173import net.fortuna.ical4j.model.component.VTimeZone; 
    7274import net.fortuna.ical4j.model.Component; 
     
    8183import java.io.StringWriter; 
    8284import java.io.Serializable; 
     85import java.util.ArrayList; 
    8386import java.util.Collection; 
    8487import java.util.HashMap; 
     
    260263  } 
    261264 
    262   /** Convert the given string representation of an Icalendar object to an EventVO 
    263    * 
    264    * <p>Because an icalendar object can contain 0 or more VEvents we return 
    265    * a collection of events which may be empty. 
     265  /** Convert the given string representation of an Icalendar object to a 
     266   * Collection of Calendar objects 
    266267   * 
    267268   * @param cal       calendar 
     
    272273  public Collection fromIcal(BwCalendar cal, String val) throws CalFacadeException { 
    273274    return fromIcal(cal, new StringReader(val)); 
    274     /* 
    275     try { 
    276       CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl()); 
    277  
    278       UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(val), true); 
    279  
    280       //return fromIcal(cal, bldr.build(new UnfoldingReader(new StringReader(val)))); 
    281       return fromIcal(cal, bldr.build(ufrdr)); 
    282     } catch (ParserException pe) { 
    283       if (debug) { 
    284         error(pe); 
    285       } 
    286       throw new IcalMalformedException(pe.getMessage()); 
    287     } catch (CalFacadeException cfe) { 
    288       throw cfe; 
    289     } catch (Throwable t) { 
    290       throw new CalFacadeException(t); 
    291     }*/ 
    292275  } 
    293276 
     
    326309   */ 
    327310  public Collection fromIcal(BwCalendar cal, Calendar val) throws CalFacadeException { 
    328     Vector objs = new Vector(); 
     311    ArrayList objs = new ArrayList(); 
    329312 
    330313    if (val == null) { 
     
    344327        if (ev != null) { 
    345328          objs.add(ev); 
     329        } 
     330      } else if (o instanceof VFreeBusy) { 
     331        BwFreeBusy fb = BwFreeBusyUtil.toFreeBusy(cb, 
     332                                                  (VFreeBusy)o, 
     333                                                  debug); 
     334 
     335        if (fb != null) { 
     336          objs.add(fb); 
    346337        } 
    347338      } else if (o instanceof VTimeZone) {