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

Caldav: implement startdate and duedate on tasks

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1767 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-08-08 09:06:39 +00:00
parent 849a5058ec
commit 2a5244a5af
5 changed files with 83 additions and 33 deletions

View File

@ -2111,22 +2111,6 @@ public abstract class ExchangeSession {
return writer.toString(); return writer.toString();
} }
protected String convertZuluDateToBday(String value) {
String result = null;
if (value != null && value.length() > 0) {
try {
SimpleDateFormat parser = ExchangeSession.getZuluDateFormat();
Calendar cal = Calendar.getInstance();
cal.setTime(parser.parse(value));
cal.add(Calendar.HOUR_OF_DAY, 12);
result = ExchangeSession.getVcardBdayFormat().format(cal.getTime());
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
return result;
}
} }
/** /**
@ -2912,6 +2896,22 @@ public abstract class ExchangeSession {
return internalCreateOrUpdateContact(folderPath, itemName, properties, etag, noneMatch); return internalCreateOrUpdateContact(folderPath, itemName, properties, etag, noneMatch);
} }
protected String convertZuluDateToBday(String value) {
String result = null;
if (value != null && value.length() > 0) {
try {
SimpleDateFormat parser = ExchangeSession.getZuluDateFormat();
Calendar cal = Calendar.getInstance();
cal.setTime(parser.parse(value));
cal.add(Calendar.HOUR_OF_DAY, 12);
result = ExchangeSession.getVcardBdayFormat().format(cal.getTime());
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
return result;
}
protected String convertBDayToZulu(String value) { protected String convertBDayToZulu(String value) {
String result = null; String result = null;
if (value != null && value.length() > 0) { if (value != null && value.length() > 0) {

View File

@ -1395,6 +1395,8 @@ public class DavExchangeSession extends ExchangeSession {
eventProperties.add("uid"); eventProperties.add("uid");
eventProperties.add("percentcomplete"); eventProperties.add("percentcomplete");
eventProperties.add("keywords"); eventProperties.add("keywords");
eventProperties.add("startdate");
eventProperties.add("duedate");
MultiStatusResponse[] responses = searchItems(folderPath, eventProperties, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow, 1); MultiStatusResponse[] responses = searchItems(folderPath, eventProperties, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow, 1);
if (responses.length == 0) { if (responses.length == 0) {
@ -1409,6 +1411,9 @@ public class DavExchangeSession extends ExchangeSession {
vEvent.setPropertyValue("CREATED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "created"))); vEvent.setPropertyValue("CREATED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "created")));
vEvent.setPropertyValue("LAST-MODIFIED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "calendarlastmodified"))); vEvent.setPropertyValue("LAST-MODIFIED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "calendarlastmodified")));
vEvent.setPropertyValue("DTSTAMP", convertDateFromExchange(getPropertyIfExists(davPropertySet, "dtstamp"))); vEvent.setPropertyValue("DTSTAMP", convertDateFromExchange(getPropertyIfExists(davPropertySet, "dtstamp")));
vEvent.setPropertyValue("DUE;VALUE=DATE", convertDateFromExchangeToTaskDate(getPropertyIfExists(davPropertySet, "duedate")));
vEvent.setPropertyValue("DTSTART;VALUE=DATE", convertDateFromExchangeToTaskDate(getPropertyIfExists(davPropertySet, "startdate")));
String uid = getPropertyIfExists(davPropertySet, "calendaruid"); String uid = getPropertyIfExists(davPropertySet, "calendaruid");
if (uid == null) { if (uid == null) {
uid = getPropertyIfExists(davPropertySet, "uid"); uid = getPropertyIfExists(davPropertySet, "uid");
@ -1578,6 +1583,8 @@ public class DavExchangeSession extends ExchangeSession {
propertyValues.add(Field.createPropertyValue("percentcomplete", String.valueOf(Double.parseDouble(percentComplete) / 100))); propertyValues.add(Field.createPropertyValue("percentcomplete", String.valueOf(Double.parseDouble(percentComplete) / 100)));
propertyValues.add(Field.createPropertyValue("taskstatus", vTodoToTaskStatusMap.get(vCalendar.getFirstVeventPropertyValue("STATUS")))); propertyValues.add(Field.createPropertyValue("taskstatus", vTodoToTaskStatusMap.get(vCalendar.getFirstVeventPropertyValue("STATUS"))));
propertyValues.add(Field.createPropertyValue("keywords", vCalendar.getFirstVeventPropertyValue("CATEGORIES"))); propertyValues.add(Field.createPropertyValue("keywords", vCalendar.getFirstVeventPropertyValue("CATEGORIES")));
propertyValues.add(Field.createPropertyValue("duedate", convertTaskDateToZulu(vCalendar.getFirstVeventPropertyValue("DUE"))));
propertyValues.add(Field.createPropertyValue("startdate", convertTaskDateToZulu(vCalendar.getFirstVeventPropertyValue("DTSTART"))));
ExchangePropPatchMethod propPatchMethod = new ExchangePropPatchMethod(encodedHref, propertyValues); ExchangePropPatchMethod propPatchMethod = new ExchangePropPatchMethod(encodedHref, propertyValues);
propPatchMethod.setRequestHeader("Translate", "f"); propPatchMethod.setRequestHeader("Translate", "f");
@ -2880,4 +2887,45 @@ public class DavExchangeSession extends ExchangeSession {
return dateFormatter.format(date); return dateFormatter.format(date);
} }
protected String convertTaskDateToZulu(String value) {
String result = null;
if (value != null && value.length() > 0) {
try {
SimpleDateFormat parser;
if (value.length() == 8) {
parser = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
parser.setTimeZone(GMT_TIMEZONE);
} else if (value.length() == 15) {
parser = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
parser.setTimeZone(GMT_TIMEZONE);
} else {
parser = ExchangeSession.getExchangeZuluDateFormat();
}
Calendar calendarValue = Calendar.getInstance(GMT_TIMEZONE);
calendarValue.setTime(parser.parse(value));
calendarValue.set(Calendar.HOUR, 0);
calendarValue.set(Calendar.MINUTE, 0);
calendarValue.set(Calendar.SECOND, 0);
result = ExchangeSession.getExchangeZuluDateFormatMillisecond().format(calendarValue.getTime());
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
return result;
}
protected String convertDateFromExchangeToTaskDate(String exchangeDateValue) throws DavMailException {
String result = null;
if (exchangeDateValue != null) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
dateFormat.setTimeZone(GMT_TIMEZONE);
result = dateFormat.format(getExchangeZuluDateFormatMillisecond().parse(exchangeDateValue));
} catch (ParseException e) {
throw new DavMailException("EXCEPTION_INVALID_DATE", exchangeDateValue);
}
}
return result;
}
} }

View File

@ -87,7 +87,7 @@ public class ExchangePropPatchMethod extends PostMethod {
final Set<PropertyValue> deletePropertyValues = new HashSet<PropertyValue>(); final Set<PropertyValue> deletePropertyValues = new HashSet<PropertyValue>();
for (PropertyValue propertyValue : propertyValues) { for (PropertyValue propertyValue : propertyValues) {
// data type namespace // data type namespace
if (!nameSpaceMap.containsKey(TYPE_NAMESPACE) && propertyValue.getType() != null) { if (!nameSpaceMap.containsKey(TYPE_NAMESPACE) && propertyValue.getTypeString() != null) {
nameSpaceMap.put(TYPE_NAMESPACE, currentChar++); nameSpaceMap.put(TYPE_NAMESPACE, currentChar++);
} }
// property namespace // property namespace
@ -115,17 +115,13 @@ public class ExchangePropPatchMethod extends PostMethod {
if (!setPropertyValues.isEmpty()) { if (!setPropertyValues.isEmpty()) {
writer.write("<D:set><D:prop>"); writer.write("<D:set><D:prop>");
for (PropertyValue propertyValue : setPropertyValues) { for (PropertyValue propertyValue : setPropertyValues) {
PropertyType propertyType = propertyValue.getType(); String typeString = propertyValue.getTypeString();
char nameSpaceChar = (char) nameSpaceMap.get(propertyValue.getNamespaceUri()).intValue(); char nameSpaceChar = (char) nameSpaceMap.get(propertyValue.getNamespaceUri()).intValue();
writer.write('<'); writer.write('<');
writer.write(nameSpaceChar); writer.write(nameSpaceChar);
writer.write(':'); writer.write(':');
writer.write(propertyValue.getName()); writer.write(propertyValue.getName());
if (propertyType != null) { if (typeString != null) {
String typeString = propertyType.toString().toLowerCase();
if ("integer".equals(typeString)) {
typeString = "int";
}
writer.write(' '); writer.write(' ');
writer.write(nameSpaceMap.get(TYPE_NAMESPACE)); writer.write(nameSpaceMap.get(TYPE_NAMESPACE));
writer.write(":dt=\""); writer.write(":dt=\"");

View File

@ -328,6 +328,8 @@ public class Field {
createField(URN_SCHEMAS_MAILHEADER, "importance");//PS_INTERNET_HEADERS/importance createField(URN_SCHEMAS_MAILHEADER, "importance");//PS_INTERNET_HEADERS/importance
createField("percentcomplete", DistinguishedPropertySetType.Task, 0x8102, "percentcomplete", PropertyType.Double); createField("percentcomplete", DistinguishedPropertySetType.Task, 0x8102, "percentcomplete", PropertyType.Double);
createField("taskstatus", DistinguishedPropertySetType.Task, 0x8101, "taskstatus", PropertyType.Integer); createField("taskstatus", DistinguishedPropertySetType.Task, 0x8101, "taskstatus", PropertyType.Integer);
createField("startdate", DistinguishedPropertySetType.Task, 0x8104, "startdate", PropertyType.SystemTime);
createField("duedate", DistinguishedPropertySetType.Task, 0x8105, "duedate", PropertyType.SystemTime);
createField("categories", DistinguishedPropertySetType.PublicStrings, 0x9000, "categories", PropertyType.StringArray); createField("categories", DistinguishedPropertySetType.PublicStrings, 0x9000, "categories", PropertyType.StringArray);
} }
@ -407,6 +409,7 @@ public class Field {
protected final boolean isMultivalued; protected final boolean isMultivalued;
protected final boolean isBooleanValue; protected final boolean isBooleanValue;
protected final boolean isFloatValue; protected final boolean isFloatValue;
protected final boolean isDateValue;
/** /**
* Create field for namespace and name, use name as alias. * Create field for namespace and name, use name as alias.
@ -454,6 +457,7 @@ public class Field {
isIntValue = propertyType == PropertyType.Long || propertyType == PropertyType.Integer || propertyType == PropertyType.Short; isIntValue = propertyType == PropertyType.Long || propertyType == PropertyType.Integer || propertyType == PropertyType.Short;
isBooleanValue = propertyType == PropertyType.Boolean; isBooleanValue = propertyType == PropertyType.Boolean;
isFloatValue = propertyType == PropertyType.Float || propertyType == PropertyType.Double; isFloatValue = propertyType == PropertyType.Float || propertyType == PropertyType.Double;
isDateValue = propertyType == PropertyType.SystemTime;
this.uri = namespace.getURI() + name; this.uri = namespace.getURI() + name;
if (responseAlias == null) { if (responseAlias == null) {
@ -572,16 +576,18 @@ public class Field {
return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), buffer.toString()); return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), buffer.toString());
} else if (field.isBooleanValue) { } else if (field.isBooleanValue) {
if ("true".equals(value)) { if ("true".equals(value)) {
return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "1", PropertyType.Boolean); return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "1", "boolean");
} else if ("false".equals(value)) { } else if ("false".equals(value)) {
return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "0", PropertyType.Boolean); return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "0", "boolean");
} else { } else {
throw new RuntimeException("Invalid value for " + field.alias + ": " + value); throw new RuntimeException("Invalid value for " + field.alias + ": " + value);
} }
} else if (field.isFloatValue) { } else if (field.isFloatValue) {
return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value), PropertyType.Float); return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value), "float");
} else if (field.isIntValue) { } else if (field.isIntValue) {
return new PropertyValue(field.updatePropertyName.getNamespace().getURI(), field.updatePropertyName.getName(), StringUtil.xmlEncode(value), PropertyType.Integer); return new PropertyValue(field.updatePropertyName.getNamespace().getURI(), field.updatePropertyName.getName(), StringUtil.xmlEncode(value), "int");
} else if (field.isDateValue) {
return new PropertyValue(field.updatePropertyName.getNamespace().getURI(), field.updatePropertyName.getName(), StringUtil.xmlEncode(value), "dateTime.tz");
} else { } else {
return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value)); return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value));
} }

View File

@ -25,7 +25,7 @@ public class PropertyValue {
protected final String namespaceUri; protected final String namespaceUri;
protected final String name; protected final String name;
protected final String xmlEncodedValue; protected final String xmlEncodedValue;
protected final PropertyType type; protected final String typeString;
/** /**
* Create Dav property value. * Create Dav property value.
@ -54,13 +54,13 @@ public class PropertyValue {
* @param namespaceUri property namespace * @param namespaceUri property namespace
* @param name property name * @param name property name
* @param xmlEncodedValue xml encoded value * @param xmlEncodedValue xml encoded value
* @param type property type * @param typeString property type
*/ */
public PropertyValue(String namespaceUri, String name, String xmlEncodedValue, PropertyType type) { public PropertyValue(String namespaceUri, String name, String xmlEncodedValue, String typeString) {
this.namespaceUri = namespaceUri; this.namespaceUri = namespaceUri;
this.name = name; this.name = name;
this.xmlEncodedValue = xmlEncodedValue; this.xmlEncodedValue = xmlEncodedValue;
this.type = type; this.typeString = typeString;
} }
/** /**
@ -86,8 +86,8 @@ public class PropertyValue {
* *
* @return property type * @return property type
*/ */
public PropertyType getType() { public String getTypeString() {
return type; return typeString;
} }
/** /**