Changeset 774
- Timestamp:
- 07/13/06 16:31:46
- Files:
-
- trunk/calendar3/caldavClientApi/build.xml (modified) (1 diff)
- trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/BwIcalTrans.java (modified) (5 diffs)
- trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/CaldavClientIo.java (modified) (2 diffs)
- trunk/calendar3/caldavDomino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/calendar3/caldavClientApi/build.xml
r751 r774 44 44 <pathelement location="${ical4j.jar}"/> 45 45 <pathelement location="${log4j.jar}"/> 46 <pathelement location="${hibernate.jar}"/> 46 47 47 48 <!-- Include the location of the compiled calendar classes --> trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/BwIcalTrans.java
r751 r774 33 33 import org.bedework.icalendar.IcalTranslator; 34 34 35 import net.fortuna.ical4j.model.Calendar; 36 import net.fortuna.ical4j.model.Dur; 37 import net.fortuna.ical4j.model.ParameterList; 38 import net.fortuna.ical4j.model.PropertyList; 35 39 import net.fortuna.ical4j.model.TimeZone; 40 import net.fortuna.ical4j.model.component.VEvent; 41 import net.fortuna.ical4j.model.parameter.TzId; 42 import net.fortuna.ical4j.model.property.Description; 43 import net.fortuna.ical4j.model.property.DtStart; 44 import net.fortuna.ical4j.model.property.Duration; 45 import net.fortuna.ical4j.model.property.Location; 46 import net.fortuna.ical4j.model.property.Summary; 47 import net.fortuna.ical4j.model.property.Uid; 48 import net.fortuna.ical4j.model.property.Url; 36 49 37 50 import java.io.InputStreamReader; 51 import java.io.Reader; 52 import java.net.URI; 38 53 import java.util.Collection; 39 54 import java.util.List; 55 import java.util.Properties; 56 57 import org.hibernate.Hibernate; 58 import org.hibernate.id.Configurable; 59 import org.hibernate.id.UUIDHexGenerator; 40 60 41 61 /** Translate to/from ical. This requires the ability to get timezone info so … … 45 65 */ 46 66 public class BwIcalTrans { 67 private transient UUIDHexGenerator uuidGen; 68 47 69 private boolean debug; 48 70 … … 99 121 public TimeZone getTimeZone(String tzid) throws CalFacadeException { 100 122 return svci.getTimezones().getTimeZone(tzid); 123 } 124 125 /** 126 * @param startDt 127 * @param tzid 128 * @param duration - int minutes 129 * @param summary 130 * @param description 131 * @param location 132 * @param uri - URI or null 133 * @return Calendar 134 * @throws Throwable 135 */ 136 public Calendar makeMeeting(String startDt, 137 String tzid, 138 int duration, 139 String summary, 140 String description, 141 String location, 142 URI uri) throws Throwable { 143 String guid = getGuid(); 144 145 Calendar vcal = IcalTranslator.newIcal(); 146 147 VEvent ev = new VEvent(); 148 149 vcal.getComponents().add(ev); 150 151 PropertyList props = ev.getProperties(); 152 153 TzId tz = new TzId(tzid); 154 ParameterList aList = new ParameterList(); 155 156 aList.add(tz); 157 158 props.add(new DtStart(aList, startDt)); 159 160 props.add(new Duration(new Dur(0, 0, duration, 0))); 161 162 props.add(new Uid(guid)); 163 164 if (summary != null) { 165 props.add(new Summary(summary)); 166 } 167 168 if (description != null) { 169 props.add(new Description(description)); 170 } 171 172 if (location != null) { 173 props.add(new Location(location)); 174 } 175 176 if (uri != null) { 177 props.add(new Url(uri)); 178 } 179 180 return vcal; 101 181 } 102 182 … … 140 220 * @throws Throwable 141 221 */ 222 public Collection getFreeBusy(Reader in) throws Throwable { 223 return trans.fromIcal(null, in); 224 } 225 226 /** 227 * @param in 228 * @return Collection 229 * @throws Throwable 230 */ 142 231 public Collection getFreeBusy(InputStreamReader in) throws Throwable { 143 232 return trans.fromIcal(null, in); … … 170 259 } 171 260 } 261 262 /* ==================================================================== 263 * Private methods 264 * ==================================================================== */ 265 266 private String getGuid() { 267 return "CAL-" + (String)getUuidGen().generate(null, null) + 268 "freebusy.bedework.org"; 269 } 270 271 /* Use the hibernate uid generator */ 272 private UUIDHexGenerator getUuidGen() { 273 if (uuidGen != null) { 274 return uuidGen; 275 } 276 277 Properties uidprops = new Properties(); 278 uidprops.setProperty("separator", "-"); 279 uuidGen = new UUIDHexGenerator(); 280 ((Configurable)uuidGen).configure(Hibernate.STRING, uidprops, null); 281 return uuidGen; 282 } 172 283 } trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/CaldavClientIo.java
r755 r774 66 66 import org.apache.commons.httpclient.HttpMethod; 67 67 import org.apache.commons.httpclient.contrib.ssl.BaseProtocolSocketFactory; 68 import org.apache.commons.httpclient.methods.EntityEnclosingMethod; 68 69 import org.apache.commons.httpclient.protocol.Protocol; 69 70 //import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; … … 230 231 } 231 232 232 if (contentType == null) { 233 contentType = "text/xml"; 234 } 235 236 if (content != null) { 237 client.setContent(content, contentType); 233 if (meth instanceof EntityEnclosingMethod) { 234 if (contentType == null) { 235 contentType = "text/xml"; 236 } 237 238 if (content != null) { 239 client.setContent(content, contentType); 240 } 238 241 } 239 242 trunk/calendar3/caldavDomino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java
r755 r774 69 69 import edu.rpi.cct.webdav.servlet.shared.WebdavException; 70 70 import edu.rpi.cct.webdav.servlet.shared.WebdavIntfException; 71 import edu.rpi.sss.util.xml.XmlUtil; 71 72 72 73 import net.fortuna.ical4j.model.Calendar; … … 77 78 import org.apache.commons.httpclient.NoHttpResponseException; 78 79 import org.apache.log4j.Logger; 80 import org.w3c.dom.Document; 81 import org.w3c.dom.Element; 82 import org.w3c.dom.Node; 83 import org.xml.sax.InputSource; 84 import org.xml.sax.SAXException; 79 85 80 86 import java.io.InputStreamReader; 81 87 import java.io.Reader; 82 88 import java.io.Serializable; 89 import java.io.StringReader; 83 90 import java.net.URI; 84 91 import java.net.URLDecoder; … … 92 99 import javax.servlet.http.HttpServletRequest; 93 100 import javax.servlet.http.HttpServletResponse; 101 import javax.xml.parsers.DocumentBuilder; 102 import javax.xml.parsers.DocumentBuilderFactory; 94 103 95 104 /** Domino implementation of SysIntf. … … 237 246 "start-max=" + makeDateTime(end)); 238 247 248 req.addHeader("Accept", 249 "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); 250 req.addHeader("Accept-Language", "en-us,en;q=0.7,es;q=0.3"); 251 req.addHeader("Accept-Encoding", "gzip,deflate"); 252 req.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); 239 253 CaldavResp resp = send(req, di); 240 254 241 Collection fbs = getTrans().getFreeBusy( 242 new InputStreamReader(resp.getContentStream())); 255 /* He switched to XML! - parse back to a vfreebusy object */ 256 257 String vfb = makeVfb(new InputStreamReader(resp.getContentStream())); 258 259 if (debug) { 260 debugMsg(vfb); 261 } 262 263 Collection fbs = getTrans().getFreeBusy(new StringReader(vfb)); 243 264 244 265 /* Domino returns free time - invert to get busy time … … 386 407 * ==================================================================== */ 387 408 409 /* <?xml version="1.0" encoding="UTF-8"?> 410 <iCalendar> 411 <vcalendar method="REPLY" version="2.0" prodid="-//IBM Domino Freetime//NONSGML Prototype//EN"> 412 <vfreebusy> 413 <attendee>John</attendee> 414 <url>http://t1.egenconsulting.com:80/servlet/Freetime/John</url> 415 <dtstamp>20060713T185253Z</dtstamp> 416 <dtstart>20060717T030000Z</dtstart> 417 <dtend>20060723T030000Z</dtend> 418 <freebusy fbtype="FREE">20060717T130000Z/20060717T160000Z</freebusy> 419 <freebusy fbtype="FREE">20060717T170000Z/20060717T210000Z</freebusy> 420 <freebusy fbtype="FREE">20060718T130000Z/20060718T160000Z</freebusy> 421 <freebusy fbtype="FREE">20060718T170000Z/20060718T210000Z</freebusy> 422 <freebusy fbtype="FREE">20060719T130000Z/20060719T160000Z</freebusy> 423 <freebusy fbtype="FREE">20060719T170000Z/20060719T210000Z</freebusy> 424 <freebusy fbtype="FREE">20060720T130000Z/20060720T160000Z</freebusy> 425 <freebusy fbtype="FREE">20060720T170000Z/20060720T210000Z</freebusy> 426 <freebusy fbtype="FREE">20060721T130000Z/20060721T160000Z</freebusy> 427 <freebusy fbtype="FREE">20060721T170000Z/20060721T210000Z</freebusy> 428 </vfreebusy> 429 430 </vcalendar> 431 </iCalendar> 432 */ 433 private String makeVfb(Reader rdr) throws WebdavException{ 434 try { 435 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 436 factory.setNamespaceAware(true); 437 438 DocumentBuilder builder = factory.newDocumentBuilder(); 439 440 Document doc = builder.parse(new InputSource(rdr)); 441 442 StringBuffer sb = new StringBuffer(); 443 444 sb.append("BEGIN:VCALENDAR\n"); 445 sb.append("VERSION:2.0\n"); 446 sb.append("PRODID:-//Bedework Domino/caldav interface//EN\n"); 447 sb.append("BEGIN:VFREEBUSY\n"); 448 449 Element root = doc.getDocumentElement(); // </iCalendar> 450 Element child = getOnlyChild(root); // </vcalendar> 451 452 child = getOnlyChild(child); // </vfreebusy> 453 454 Element[] children = getChildren(child); 455 456 for (int i = 0; i < children.length; i++) { 457 Element curnode = children[i]; 458 459 String nm = curnode.getLocalName(); 460 461 if (nm.equals("attendee")) { 462 sb.append("ATTENDEE:"); 463 sb.append(getElementContent(curnode)); 464 sb.append("\n"); 465 } else if (nm.equals("url")) { 466 sb.append("URL:"); 467 sb.append(getElementContent(curnode)); 468 sb.append("\n"); 469 } else if (nm.equals("dtstamp")) { 470 sb.append("DTSTAMP:"); 471 sb.append(getElementContent(curnode)); 472 sb.append("\n"); 473 } else if (nm.equals("dtstart")) { 474 sb.append("DTSTART:"); 475 sb.append(getElementContent(curnode)); 476 sb.append("\n"); 477 } else if (nm.equals("dtend")) { 478 sb.append("DTEND:"); 479 sb.append(getElementContent(curnode)); 480 sb.append("\n"); 481 } else if (nm.equals("freebusy")) { 482 sb.append("FREEBUSY;FBTYPE=FREE:"); 483 sb.append(getElementContent(curnode)); 484 sb.append("\n"); 485 } 486 } 487 sb.append("END:VFREEBUSY\n"); 488 sb.append("END:VCALENDAR\n"); 489 490 return sb.toString(); 491 } catch (SAXException e) { 492 throw new WebdavException(HttpServletResponse.SC_BAD_REQUEST); 493 } catch (Throwable t) { 494 throw new WebdavException(t); 495 } finally { 496 if (rdr != null) { 497 try { 498 rdr.close(); 499 } catch (Throwable t) {} 500 } 501 } 502 } 503 504 protected Element[] getChildren(Node nd) throws WebdavException { 505 try { 506 return XmlUtil.getElementsArray(nd); 507 } catch (Throwable t) { 508 if (debug) { 509 getLogger().error(this, t); 510 } 511 512 throw new WebdavException(t); 513 } 514 } 515 516 protected Element getOnlyChild(Node nd) throws WebdavException { 517 try { 518 return XmlUtil.getOnlyElement(nd); 519 } catch (Throwable t) { 520 if (debug) { 521 getLogger().error(this, t); 522 } 523 524 throw new WebdavException(t); 525 } 526 } 527 528 protected String getElementContent(Element el) throws WebdavException { 529 try { 530 return XmlUtil.getElementContent(el); 531 } catch (Throwable t) { 532 if (debug) { 533 getLogger().error(this, t); 534 } 535 536 throw new WebdavException(t); 537 } 538 } 539 388 540 private BwIcalTrans getTrans() throws WebdavIntfException { 389 541 try { … … 398 550 private String makeDateTime(BwDateTime dt) throws WebdavIntfException { 399 551 try { 552 /* 400 553 String utcdt = dt.getDate(); 401 554 … … 415 568 416 569 return sb.toString(); 570 */ 571 return dt.getDate(); 417 572 } catch (Throwable t) { 418 573 throw new WebdavIntfException(t);
