Changeset 472
- Timestamp:
- 05/12/06 16:51:23
- Files:
-
- trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavBWIntf.java (modified) (1 diff)
- trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavCalNode.java (modified) (5 diffs)
- trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java (modified) (6 diffs)
- trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/calquery/FreeBusyQuery.java (modified) (6 diffs)
- trunk/calendar3/icalendar/src/org/bedework/icalendar/BwFreeBusyUtil.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavBWIntf.java
r465 r472 1217 1217 1218 1218 /** The node represents a calendar resource for which we must get free-busy 1219 * information. We return a copy of the node for each time period in the 1220 * request. 1219 * information. 1221 1220 * 1222 * @param wdnode1221 * @param cnode CaldavCalNode 1223 1222 * @param freeBusy 1224 * @return Collection1225 1223 * @throws WebdavIntfException 1226 1224 */ 1227 public Collection getFreeBusy(WebdavNsNode wdnode, 1228 FreeBusyQuery freeBusy) throws WebdavIntfException { 1229 try { 1230 CaldavBwNode uwnode = getBwnode(wdnode); 1231 if (!(uwnode instanceof CaldavCalNode)) { 1232 throw WebdavIntfException.badRequest(); 1233 } 1234 1235 CaldavCalNode cnode = (CaldavCalNode)uwnode; 1236 1225 public void getFreeBusy(CaldavCalNode cnode, 1226 FreeBusyQuery freeBusy) throws WebdavIntfException { 1227 try { 1237 1228 String user = cnode.getCDURI().getOwner(); 1238 1229 1239 1230 getSvci(); 1240 1231 1241 Iterator it = freeBusy.getFreeBusy(svci, user).iterator(); 1242 Collection nodes = new ArrayList(); 1243 1244 while (it.hasNext()) { 1245 BwFreeBusy fb = (BwFreeBusy)it.next(); 1246 1247 CaldavCalNode fbnode = (CaldavCalNode)cnode.clone(); 1248 1249 fbnode.setFreeBusy(fb); 1250 1251 nodes.add(fbnode); 1252 } 1253 1254 return nodes; 1232 BwFreeBusy fb = freeBusy.getFreeBusy(svci, user); 1233 1234 cnode.setFreeBusy(fb); 1255 1235 } catch (WebdavIntfException we) { 1256 1236 throw we; trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavCalNode.java
r119 r472 69 69 import java.util.Vector; 70 70 71 import net.fortuna.ical4j.model.Calendar; 71 72 import net.fortuna.ical4j.model.component.VFreeBusy; 72 73 … … 76 77 */ 77 78 public class CaldavCalNode extends CaldavBwNode { 78 private VFreeBusy vfreeBusy;79 private Calendar ical; 79 80 80 81 private String vfreeBusyString; … … 153 154 public void setFreeBusy(BwFreeBusy fb) throws WebdavIntfException { 154 155 try { 155 vfreeBusy = VFreeUtil.toVFreeBusy(fb);156 VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(fb); 156 157 if (vfreeBusy != null) { 157 vfreeBusyString = vfreeBusy.toString(); 158 ical = new Calendar(); 159 ical.getComponents().add(vfreeBusy); 160 vfreeBusyString = ical.toString(); 158 161 contentLen = vfreeBusyString.length(); 159 162 } else { … … 161 164 contentLen = 0; 162 165 } 166 allowsGet = true; 163 167 } catch (Throwable t) { 164 168 if (debug) { … … 172 176 init(true); 173 177 174 if ( vfreeBusy== null) {178 if (ical == null) { 175 179 return null; 176 180 } trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java
r469 r472 127 127 } 128 128 129 startEmit(resp);130 131 129 int st = processDoc(doc); 132 130 … … 145 143 processFbResp(req, resp); 146 144 } else { 145 startEmit(resp); 146 147 147 processResp(req, resp, depth); 148 148 } … … 182 182 } else if (nodeMatches(root, CaldavTags.freeBusyQuery)) { 183 183 reportType = reportTypeFreeBusy; 184 freeBusy = new FreeBusyQuery(intf, debug); 184 185 } else if (nodeMatches(root, WebdavTags.expandProperty)) { 185 186 reportType = reportTypeExpandProperty; … … 204 205 205 206 if (reportType == reportTypeFreeBusy) { 206 freeBusy = new FreeBusyQuery(intf, debug);207 207 freeBusy.parse(curnode); 208 208 } else if (reportType == reportTypeExpandProperty) { … … 420 420 * @param req 421 421 * @param resp 422 * @param depth423 422 * @throws WebdavException 424 423 */ … … 433 432 WebdavNsNode node = intf.getNode(resourceUri); 434 433 435 int status = HttpServletResponse.SC_OK; 436 437 Collection nodes = null; 438 439 try { 440 nodes = intf.getFreeBusy(node, freeBusy); 441 } catch (WebdavException wde) { 434 if (!(node instanceof CaldavCalNode)) { 442 435 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(); 436 trace("Expected CaldavCalNode - got " + node); 437 } 438 node.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 439 } else { 440 try { 441 intf.getFreeBusy((CaldavCalNode)node, freeBusy); 442 } catch (WebdavException wde) { 443 if (debug) { 444 trace("intf.getFreeBusy exception"); 445 } 446 node.setStatus(wde.getStatusCode()); 447 } 448 449 Writer out; 450 try { 451 out = resp.getWriter(); 452 } catch (Throwable t) { 453 throw new WebdavException(t); 454 } 455 456 /** Get the content now to set up length, type etc. 457 */ 458 Reader in = getNsIntf().getContent(node); 459 resp.setContentLength(node.getContentLen()); 460 if (in == null) { 461 if (debug) { 462 debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT); 463 } 464 465 resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 466 } else { 467 if (debug) { 468 debugMsg("send content - length=" + node.getContentLen()); 469 } 470 471 writeContent(in, out); 472 } 473 } 499 474 } 500 475 trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/calquery/FreeBusyQuery.java
r420 r472 68 68 import edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf; 69 69 70 import java.util.ArrayList;71 import java.util.Collection;72 import java.util.Iterator;73 import javax.servlet.http.HttpServletResponse;74 75 70 import org.apache.log4j.Logger; 76 71 import org.w3c.dom.Node; … … 86 81 protected transient Logger log; 87 82 88 private Collection timeRanges;83 private TimeRange timeRange; 89 84 90 85 /** Constructor … … 99 94 100 95 /** The given node is is the free-busy-query time-range element 101 * Should have one or more time-range elements.96 * Should have exactly one time-range element. 102 97 * 103 98 * @param nd 104 * @return int htp status105 99 * @throws WebdavException 106 100 */ 107 public intparse(Node nd) throws WebdavException {101 public void parse(Node nd) throws WebdavException { 108 102 try { 109 if (timeRange s == null) {110 t imeRanges = new ArrayList();103 if (timeRange != null) { 104 throw new WebdavBadRequest(); 111 105 } 112 106 … … 115 109 } 116 110 117 TimeRange tr = CalDavParseUtil.parseTimeRange(nd, intf.getSvci().getTimezones()); 118 timeRanges.add(tr); 111 timeRange = CalDavParseUtil.parseTimeRange(nd, intf.getSvci().getTimezones()); 119 112 120 113 if (debug) { 121 trace("Parsed time range " + t r);114 trace("Parsed time range " + timeRange); 122 115 } 123 116 } catch (WebdavBadRequest wbr) { 124 return wbr.getStatusCode();117 throw wbr; 125 118 } catch (Throwable t) { 126 119 throw new WebdavBadRequest(); 127 120 } 128 129 return HttpServletResponse.SC_OK;130 121 } 131 122 … … 133 124 * @param svci 134 125 * @param user 135 * @return Collection126 * @return BwFreeBusy 136 127 * @throws WebdavException 137 128 */ 138 public Collection getFreeBusy(CalSvcI svci, String user) throws WebdavException { 139 Iterator it = timeRanges.iterator(); 140 Collection fbs = new ArrayList(); 141 142 while (it.hasNext()) { 143 TimeRange tr = (TimeRange)it.next(); 144 145 try { 146 BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 147 tr.getStart(), tr.getEnd(), null, 148 false); 149 150 if (debug) { 151 trace("Got " + fb); 152 } 153 fbs.add(fb); 154 } catch (Throwable t) { 155 throw new WebdavException(t); 156 } 157 } 158 159 return fbs; 129 public BwFreeBusy getFreeBusy(CalSvcI svci, String user) throws WebdavException { 130 try { 131 BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 132 timeRange.getStart(), timeRange.getEnd(), 133 null, false); 134 135 if (debug) { 136 trace("Got " + fb); 137 } 138 139 return fb; 140 } catch (Throwable t) { 141 throw new WebdavException(t); 142 } 160 143 } 161 144 … … 166 149 trace("<free-busy-query>"); 167 150 168 Iterator it = timeRanges.iterator(); 169 while (it.hasNext()) { 170 TimeRange tr = (TimeRange)it.next(); 171 172 tr.dump(getLogger(), " "); 173 } 151 timeRange.dump(getLogger(), " "); 174 152 175 153 trace("</free-busy-query>"); trunk/calendar3/icalendar/src/org/bedework/icalendar/BwFreeBusyUtil.java
r471 r472 70 70 import net.fortuna.ical4j.model.parameter.FbType; 71 71 import net.fortuna.ical4j.model.property.DtEnd; 72 import net.fortuna.ical4j.model.property.DtStamp; 72 73 import net.fortuna.ical4j.model.property.DtStart; 73 74 import net.fortuna.ical4j.model.property.Duration; … … 168 169 Iterator perit = perpl.iterator(); 169 170 while (perit.hasNext()) { 170 Period per = (Period) it.next();171 Period per = (Period)perit.next(); 171 172 172 173 fbc.addPeriod(per); … … 174 175 175 176 fb.addTime(fbc); 177 } else if (prop instanceof DtEnd) { 178 /* ------------------- DtEnd -------------------- */ 179 } else if (prop instanceof DtStamp) { 180 /* ------------------- DtStamp -------------------- */ 181 182 //ev.setDtstamp(wrapper.getDtStamp()); 183 } else if (prop instanceof DtStart) { 184 /* ------------------- DtStart -------------------- */ 176 185 } else { 177 186 if (debug) {
