1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 03:02:22 -05:00

Caldav: partial MKCALENDAR implementation

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1265 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-24 22:23:14 +00:00
parent 674a1436d0
commit 809f16311b
6 changed files with 65 additions and 24 deletions

View File

@ -308,6 +308,11 @@ public class CaldavConnection extends AbstractConnection {
// test event
ExchangeSession.Item item = session.getItem(request.getFolderPath(), lastPath);
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(item.getEtag()), item.getContentType(), (byte[]) null, true);
} else if (request.isMkCalendar()) {
HashMap<String, String> properties = new HashMap<String, String>();
//properties.put("displayname", request.getProperty("displayname"));
int status = session.createCalendarFolder(request.getFolderPath(), properties);
sendHttpResponse(status, null);
} else {
sendUnsupported(request);
}
@ -1202,7 +1207,7 @@ public class CaldavConnection extends AbstractConnection {
protected final Map<String, String> headers;
protected int depth;
protected final String body;
protected final HashSet<String> properties = new HashSet<String>();
protected final HashMap<String, String> properties = new HashMap<String, String>();
protected HashSet<String> hrefs;
protected boolean isMultiGet;
protected String timeRangeStart;
@ -1216,7 +1221,7 @@ public class CaldavConnection extends AbstractConnection {
buildDepth();
this.body = body;
if (isPropFind() || isReport()) {
if (isPropFind() || isReport() || isMkCalendar()) {
parseXmlBody();
}
}
@ -1257,6 +1262,10 @@ public class CaldavConnection extends AbstractConnection {
return "DELETE".equals(command);
}
public boolean isMkCalendar() {
return "MKCALENDAR".equals(command);
}
/**
* Check if this request is a folder request.
*
@ -1385,8 +1394,8 @@ public class CaldavConnection extends AbstractConnection {
} else if ("time-range".equals(currentElement)) {
timeRangeStart = streamReader.getAttributeValue(null, "start");
timeRangeEnd = streamReader.getAttributeValue(null, "end");
} else if (inProperties) {
properties.add(currentElement);
} else if (inProperties && !"calendar-free-busy-set".equals(currentElement)) {
properties.put(currentElement, streamReader.getElementText());
}
} else if (event == XMLStreamConstants.END_ELEMENT) {
if ("prop".equals(currentElement)) {
@ -1420,7 +1429,11 @@ public class CaldavConnection extends AbstractConnection {
}
public boolean hasProperty(String propertyName) {
return properties.contains(propertyName);
return properties.containsKey(propertyName);
}
public String getProperty(String propertyName) {
return properties.get(propertyName);
}
public boolean isMultiGet() {
@ -1445,6 +1458,16 @@ public class CaldavConnection extends AbstractConnection {
return getFolderPath(null);
}
public String getParentFolderPath() {
int endIndex;
if (isFolder()) {
endIndex = getPathLength() - 1;
} else {
endIndex = getPathLength() - 2;
}
return getFolderPath(endIndex, null);
}
/**
* Get request folder path with subFolder.
*
@ -1458,6 +1481,10 @@ public class CaldavConnection extends AbstractConnection {
} else {
endIndex = getPathLength() - 1;
}
return getFolderPath(endIndex, subFolder);
}
protected String getFolderPath(int endIndex, String subFolder) {
StringBuilder calendarPath = new StringBuilder();
for (int i = 0; i < endIndex; i++) {

View File

@ -1002,9 +1002,10 @@ public abstract class ExchangeSession {
*
* @param folderName logical folder name
* @throws IOException on error
* @return status
*/
public void createMessageFolder(String folderName) throws IOException {
createFolder(folderName, "IPF.Note");
public int createMessageFolder(String folderName) throws IOException {
return createFolder(folderName, "IPF.Note", null);
}
/**
@ -1012,9 +1013,10 @@ public abstract class ExchangeSession {
*
* @param folderName logical folder name
* @throws IOException on error
* @return status
*/
public void createCalendarFolder(String folderName) throws IOException {
createFolder(folderName, "IPF.Appointment");
public int createCalendarFolder(String folderName, Map<String, String> properties) throws IOException {
return createFolder(folderName, "IPF.Appointment", properties);
}
/**
@ -1022,9 +1024,10 @@ public abstract class ExchangeSession {
*
* @param folderName logical folder name
* @throws IOException on error
* @return status
*/
public void createContactFolder(String folderName) throws IOException {
createFolder(folderName, "IPF.Contact");
public int createContactFolder(String folderName, Map<String, String> properties) throws IOException {
return createFolder(folderName, "IPF.Contact", properties);
}
/**
@ -1032,9 +1035,10 @@ public abstract class ExchangeSession {
*
* @param folderName logical folder name
* @param folderClass folder class
* @return status
* @throws IOException on error
*/
public abstract void createFolder(String folderName, String folderClass) throws IOException;
public abstract int createFolder(String folderName, String folderClass, Map<String, String> properties) throws IOException;
/**
* Delete Exchange folder.

View File

@ -678,7 +678,7 @@ public class DavExchangeSession extends ExchangeSession {
try {
status = httpClient.executeMethod(attachmentPropPatchMethod);
if (status != HttpStatus.SC_MULTI_STATUS) {
LOGGER.error("Error in contact photo create or update: "+attachmentPropPatchMethod.getStatusCode());
LOGGER.error("Error in contact photo create or update: " + attachmentPropPatchMethod.getStatusCode());
throw new IOException("Unable to update contact picture");
}
} finally {
@ -691,7 +691,7 @@ public class DavExchangeSession extends ExchangeSession {
try {
status = httpClient.executeMethod(deleteMethod);
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) {
LOGGER.error("Error in contact photo delete: "+status);
LOGGER.error("Error in contact photo delete: " + status);
throw new IOException("Unable to delete contact picture");
}
} finally {
@ -974,11 +974,17 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc
*/
@Override
public void createFolder(String folderPath, String folderClass) throws IOException {
ArrayList<DavConstants> list = new ArrayList<DavConstants>();
list.add(Field.createDavProperty("folderclass", folderClass));
public int createFolder(String folderPath, String folderClass, Map<String, String> properties) throws IOException {
Set<PropertyValue> propertyValues = new HashSet<PropertyValue>();
if (properties != null) {
for (Map.Entry<String, String> entry : properties.entrySet()) {
propertyValues.add(Field.createPropertyValue(entry.getKey(), entry.getValue()));
}
}
propertyValues.add(Field.createPropertyValue("folderclass", folderClass));
// standard MkColMethod does not take properties, override PropPatchMethod instead
PropPatchMethod method = new PropPatchMethod(URIUtil.encodePath(getFolderPath(folderPath)), list) {
ExchangePropPatchMethod method = new ExchangePropPatchMethod(URIUtil.encodePath(getFolderPath(folderPath)), propertyValues) {
@Override
public String getName() {
return "MKCOL";
@ -989,6 +995,7 @@ public class DavExchangeSession extends ExchangeSession {
if (status != HttpStatus.SC_MULTI_STATUS && status != HttpStatus.SC_METHOD_NOT_ALLOWED) {
throw DavGatewayHttpClientFacade.buildHttpException(method);
}
return status;
}
/**
@ -1331,7 +1338,7 @@ public class DavExchangeSession extends ExchangeSession {
VTimezone userTimezone = new VTimezone();
// create temporary folder
String folderPath = getFolderPath("davmailtemp");
createCalendarFolder(folderPath);
createCalendarFolder(folderPath, null);
PostMethod postMethod = new PostMethod(URIUtil.encodePath(folderPath));
postMethod.addParameter("Cmd", "saveappt");

View File

@ -577,14 +577,16 @@ public class EwsExchangeSession extends ExchangeSession {
* @inheritDoc
*/
@Override
public void createFolder(String folderPath, String folderClass) throws IOException {
public int createFolder(String folderPath, String folderClass, Map<String,String> properties) throws IOException {
FolderPath path = new FolderPath(folderPath);
EWSMethod.Item folder = new EWSMethod.Item();
folder.type = "Folder";
folder.put("DisplayName", path.folderName);
folder.put("FolderClass", folderClass);
// TODO: handle properties
CreateFolderMethod createFolderMethod = new CreateFolderMethod(getFolderId(path.parentPath), folder);
executeMethod(createFolderMethod);
return HttpStatus.SC_CREATED;
}
/**

View File

@ -48,7 +48,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
public void testCreateFolder() throws IOException {
// recreate empty folder
session.deleteFolder("testcontactfolder");
session.createContactFolder("testcontactfolder");
session.createContactFolder("testcontactfolder", null);
}
public void testCreateContact() throws IOException {
@ -424,7 +424,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
System.out.println(contact.getBody());
}
public void testAnniversary() throws IOException {
public void testAnniversary() throws IOException {
ExchangeSession.Contact contact = getCurrentContact();
VCardWriter vCardWriter = new VCardWriter();
@ -440,4 +440,5 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("20000102T000000Z", contact.get("anniversary"));
System.out.println(contact.getBody());
}
}

View File

@ -69,7 +69,7 @@ public class TestExchangeSessionFolder extends AbstractExchangeSessionTestCase {
public void testCalendarFolder() throws IOException {
String folderName = "testcalendar";
session.createCalendarFolder(folderName);
session.createCalendarFolder(folderName, null);
ExchangeSession.Folder folder = session.getFolder(folderName);
assertNotNull(folder);
assertEquals("IPF.Appointment", folder.folderClass);
@ -78,7 +78,7 @@ public class TestExchangeSessionFolder extends AbstractExchangeSessionTestCase {
public void testContactFolder() throws IOException {
String folderName = "testcontact";
session.createContactFolder(folderName);
session.createContactFolder(folderName, null);
ExchangeSession.Folder folder = session.getFolder(folderName);
assertNotNull(folder);
assertEquals("IPF.Contact", folder.folderClass);