Carddav: implement categories support in EWS mode

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1185 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-13 11:27:12 +00:00
parent 63324f9a78
commit 641dcaeeb1
5 changed files with 58 additions and 11 deletions

View File

@ -576,12 +576,28 @@ public abstract class EWSMethod extends PostMethod {
String tagLocalName = reader.getLocalName();
if ("ExtendedFieldURI".equals(tagLocalName)) {
propertyTag = getAttributeValue(reader, "PropertyTag");
// property name is in PropertyId with DistinguishedPropertySetId
// property name is in PropertyId or PropertyName with DistinguishedPropertySetId
if (propertyTag == null) {
propertyTag = getAttributeValue(reader, "PropertyId");
}
if (propertyTag == null) {
propertyTag = getAttributeValue(reader, "PropertyName");
}
} else if ("Value".equals(tagLocalName)) {
propertyValue = reader.getElementText();
} else if ("Values".equals(tagLocalName)) {
StringBuilder buffer = new StringBuilder();
while (reader.hasNext() && !(isEndTag(reader, "Values"))) {
reader.next();
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
if (buffer.length() > 0) {
buffer.append(',');
}
buffer.append(reader.getElementText());
}
}
propertyValue = buffer.toString();
}
}
}

View File

@ -76,6 +76,18 @@ public class ExtendedFieldURI implements FieldURI {
this.propertyType = PropertyType.String;
}
/**
* Create extended field uri.
*
* @param distinguishedPropertySetId distinguished property set id
* @param propertyName property name
*/
public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType) {
this.distinguishedPropertySetId = distinguishedPropertySetId;
this.propertyName = propertyName;
this.propertyType = propertyType;
}
public void appendTo(StringBuilder buffer) {
buffer.append("<t:ExtendedFieldURI ");
if (propertyTag != null) {
@ -108,9 +120,21 @@ public class ExtendedFieldURI implements FieldURI {
}
buffer.append("<t:ExtendedProperty>");
appendTo(buffer);
buffer.append("<t:Value>");
buffer.append(value);
buffer.append("</t:Value>");
if (propertyType == PropertyType.StringArray) {
buffer.append("<t:Values>");
String[] values = value.split("\n");
for (final String singleValue : values) {
buffer.append("<t:Value>");
buffer.append(singleValue);
buffer.append("</t:Value>");
}
buffer.append("</t:Values>");
} else {
buffer.append("<t:Value>");
buffer.append(value);
buffer.append("</t:Value>");
}
buffer.append("</t:ExtendedProperty>");
if (itemType != null) {
buffer.append("</t:");
@ -127,6 +151,8 @@ public class ExtendedFieldURI implements FieldURI {
public String getResponseName() {
if (propertyTag != null) {
return propertyTag;
} else if (propertyName != null) {
return propertyName;
} else {
return String.valueOf(propertyId);
}

View File

@ -132,7 +132,7 @@ public class Field {
FIELD_MAP.put("othercountry", new ExtendedFieldURI(0x3A60, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("othercity", new ExtendedFieldURI(0x3A5F, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("keywords", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "Keywords"));
FIELD_MAP.put("keywords", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "Keywords", ExtendedFieldURI.PropertyType.StringArray));
FIELD_MAP.put("private", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Common, 0x8506, ExtendedFieldURI.PropertyType.Boolean));
FIELD_MAP.put("sensitivity", new ExtendedFieldURI(0x0036, ExtendedFieldURI.PropertyType.Long));

View File

@ -61,13 +61,16 @@ public class FieldUpdate {
writer.write("Field>");
}
StringBuilder buffer = new StringBuilder();
if (value == null) {
fieldURI.appendTo(buffer);
} else {
fieldURI.appendValue(buffer, itemType, value);
// do not try to set empty value on create
if (itemType != null || value != null) {
StringBuilder buffer = new StringBuilder();
if (value == null) {
fieldURI.appendTo(buffer);
} else {
fieldURI.appendValue(buffer, itemType, value);
}
writer.write(buffer.toString());
}
writer.write(buffer.toString());
if (itemType != null) {
writer.write("</t:");

View File

@ -95,6 +95,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
vCardWriter.appendProperty("ROLE", "profession");
vCardWriter.appendProperty("X-AIM", "im");
vCardWriter.appendProperty("BDAY", "20000102T000000Z");
vCardWriter.appendProperty("CATEGORIES", "keywords");
vCardWriter.appendProperty("X-ASSISTANT", "secretarycn");
vCardWriter.appendProperty("X-MANAGER", "manager");
@ -169,5 +170,6 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("secretarycn", contact.get("secretarycn"));
assertEquals("manager", contact.get("manager"));
assertEquals("spousecn", contact.get("spousecn"));
assertEquals("keywords", contact.get("keywords"));
}
}