From 43f4f632b5b95d793ddabdc35d754a5131f4f411 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 24 Dec 2008 16:57:34 +0000 Subject: [PATCH] iCal fix : implement GET request on event git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@253 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index f2a424ac..6a0735b3 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -330,6 +330,10 @@ public class CaldavConnection extends AbstractConnection { int status = session.createOrUpdateEvent(path.substring("/calendar/".length()), body, etag); sendHttpResponse(status, true); + } else if ("GET".equals(command) && path.startsWith("/calendar/")) { + ExchangeSession.Event event = session.getEvent(path.substring("/calendar/".length())); + sendHttpResponse(HttpStatus.SC_OK, null, "text/calendar;charset=UTF-8", event.getICS(), true); + } else if ("POST".equals(command) && path.startsWith("/outbox")) { Map valueMap = new HashMap(); Map keyMap = new HashMap(); @@ -398,31 +402,35 @@ public class CaldavConnection extends AbstractConnection { int count = 0; for (ExchangeSession.Event event : events) { DavGatewayTray.debug("Retrieving event "+(++count)+"/"+size); - String eventPath = event.getPath().replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append("\n"); - buffer.append(" /calendar").append(eventPath).append("\n"); - buffer.append(" \n"); - buffer.append(" \n"); - if (request.hasProperty("calendar-data")) { - String ics = event.getICS(); - if (ics != null && ics.length() > 0) { - ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append(" "); - buffer.append(ics); - buffer.append("\n"); - } - } - if (request.hasProperty("getetag")) { - buffer.append(" ").append(event.getEtag()).append("\n"); - } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + appendEventResponse(buffer, request, event); } } + protected void appendEventResponse(StringBuilder buffer, CaldavRequest request, ExchangeSession.Event event) throws IOException { + String eventPath = event.getPath().replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + buffer.append("\n"); + buffer.append(" /calendar").append(eventPath).append("\n"); + buffer.append(" \n"); + buffer.append(" \n"); + if (request.hasProperty("calendar-data")) { + String ics = event.getICS(); + if (ics != null && ics.length() > 0) { + ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + buffer.append(" "); + buffer.append(ics); + buffer.append("\n"); + } + } + if (request.hasProperty("getetag")) { + buffer.append(" ").append(event.getEtag()).append("\n"); + } + buffer.append(" \n"); + buffer.append(" HTTP/1.1 200 OK\n"); + buffer.append(" \n"); + buffer.append(" \n"); + } + public void sendErr(int status, Exception e) throws IOException { String message = e.getMessage(); if (message == null) {