Changeset 774

Show
Ignore:
Timestamp:
07/13/06 16:31:46
Author:
douglm
Message:

Changes to create meeting object
Add some accept... headers
Fix up domino interface to handle xml

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/caldavClientApi/build.xml

    r751 r774  
    4444      <pathelement location="${ical4j.jar}"/> 
    4545      <pathelement location="${log4j.jar}"/> 
     46      <pathelement location="${hibernate.jar}"/> 
    4647 
    4748      <!-- Include the location of the compiled calendar classes --> 
  • trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/BwIcalTrans.java

    r751 r774  
    3333import org.bedework.icalendar.IcalTranslator; 
    3434 
     35import net.fortuna.ical4j.model.Calendar; 
     36import net.fortuna.ical4j.model.Dur; 
     37import net.fortuna.ical4j.model.ParameterList; 
     38import net.fortuna.ical4j.model.PropertyList; 
    3539import net.fortuna.ical4j.model.TimeZone; 
     40import net.fortuna.ical4j.model.component.VEvent; 
     41import net.fortuna.ical4j.model.parameter.TzId; 
     42import net.fortuna.ical4j.model.property.Description; 
     43import net.fortuna.ical4j.model.property.DtStart; 
     44import net.fortuna.ical4j.model.property.Duration; 
     45import net.fortuna.ical4j.model.property.Location; 
     46import net.fortuna.ical4j.model.property.Summary; 
     47import net.fortuna.ical4j.model.property.Uid; 
     48import net.fortuna.ical4j.model.property.Url; 
    3649 
    3750import java.io.InputStreamReader; 
     51import java.io.Reader; 
     52import java.net.URI; 
    3853import java.util.Collection; 
    3954import java.util.List; 
     55import java.util.Properties; 
     56 
     57import org.hibernate.Hibernate; 
     58import org.hibernate.id.Configurable; 
     59import org.hibernate.id.UUIDHexGenerator; 
    4060 
    4161/** Translate to/from ical. This requires the ability to get timezone info so 
     
    4565 */ 
    4666public class BwIcalTrans { 
     67  private transient UUIDHexGenerator uuidGen; 
     68 
    4769  private boolean debug; 
    4870 
     
    99121  public TimeZone getTimeZone(String tzid) throws CalFacadeException { 
    100122    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; 
    101181  } 
    102182 
     
    140220   * @throws Throwable 
    141221   */ 
     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   */ 
    142231  public Collection getFreeBusy(InputStreamReader in) throws Throwable { 
    143232    return trans.fromIcal(null, in); 
     
    170259    } 
    171260  } 
     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  } 
    172283} 
  • trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/api/CaldavClientIo.java

    r755 r774  
    6666import org.apache.commons.httpclient.HttpMethod; 
    6767import org.apache.commons.httpclient.contrib.ssl.BaseProtocolSocketFactory; 
     68import org.apache.commons.httpclient.methods.EntityEnclosingMethod; 
    6869import org.apache.commons.httpclient.protocol.Protocol; 
    6970//import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; 
     
    230231    } 
    231232 
    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      } 
    238241    } 
    239242 
  • trunk/calendar3/caldavDomino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java

    r755 r774  
    6969import edu.rpi.cct.webdav.servlet.shared.WebdavException; 
    7070import edu.rpi.cct.webdav.servlet.shared.WebdavIntfException; 
     71import edu.rpi.sss.util.xml.XmlUtil; 
    7172 
    7273import net.fortuna.ical4j.model.Calendar; 
     
    7778import org.apache.commons.httpclient.NoHttpResponseException; 
    7879import org.apache.log4j.Logger; 
     80import org.w3c.dom.Document; 
     81import org.w3c.dom.Element; 
     82import org.w3c.dom.Node; 
     83import org.xml.sax.InputSource; 
     84import org.xml.sax.SAXException; 
    7985 
    8086import java.io.InputStreamReader; 
    8187import java.io.Reader; 
    8288import java.io.Serializable; 
     89import java.io.StringReader; 
    8390import java.net.URI; 
    8491import java.net.URLDecoder; 
     
    9299import javax.servlet.http.HttpServletRequest; 
    93100import javax.servlet.http.HttpServletResponse; 
     101import javax.xml.parsers.DocumentBuilder; 
     102import javax.xml.parsers.DocumentBuilderFactory; 
    94103 
    95104/** Domino implementation of SysIntf. 
     
    237246                 "start-max=" + makeDateTime(end)); 
    238247 
     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"); 
    239253      CaldavResp resp = send(req, di); 
    240254 
    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)); 
    243264 
    244265      /* Domino returns free time - invert to get busy time 
     
    386407   * ==================================================================== */ 
    387408 
     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 
    388540  private BwIcalTrans getTrans() throws WebdavIntfException { 
    389541    try { 
     
    398550  private String makeDateTime(BwDateTime dt) throws WebdavIntfException { 
    399551    try { 
     552      /* 
    400553      String utcdt = dt.getDate(); 
    401554 
     
    415568 
    416569      return sb.toString(); 
     570      */ 
     571      return dt.getDate(); 
    417572    } catch (Throwable t) { 
    418573      throw new WebdavIntfException(t);