2010-05-20 05:22:03 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2010 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
package davmail.exchange.ews;
|
|
|
|
|
2010-07-20 11:00:48 -04:00
|
|
|
import davmail.util.StringUtil;
|
|
|
|
|
2010-05-20 05:22:03 -04:00
|
|
|
/**
|
|
|
|
* Extended MAPI property.
|
|
|
|
*/
|
|
|
|
public class ExtendedFieldURI implements FieldURI {
|
2010-07-20 05:10:39 -04:00
|
|
|
|
|
|
|
@SuppressWarnings({"UnusedDeclaration"})
|
2010-05-26 17:49:46 -04:00
|
|
|
protected enum PropertyType {
|
|
|
|
ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray,
|
|
|
|
Double, DoubleArray, Error, Float, FloatArray, Integer, IntegerArray, Long, LongArray, Null, Object,
|
|
|
|
ObjectArray, Short, ShortArray, SystemTime, SystemTimeArray, String, StringArray
|
|
|
|
}
|
|
|
|
|
2010-07-20 05:10:39 -04:00
|
|
|
@SuppressWarnings({"UnusedDeclaration"})
|
2010-06-08 18:21:53 -04:00
|
|
|
protected static enum DistinguishedPropertySetType {
|
|
|
|
Meeting, Appointment, Common, PublicStrings, Address, InternetHeaders, CalendarAssistant, UnifiedMessaging, Task
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 04:46:46 -04:00
|
|
|
protected String propertyTag;
|
2010-06-08 18:21:53 -04:00
|
|
|
protected DistinguishedPropertySetType distinguishedPropertySetId;
|
2010-06-02 04:46:46 -04:00
|
|
|
protected String propertySetId;
|
2010-06-08 18:21:53 -04:00
|
|
|
protected String propertyName;
|
2010-06-02 04:46:46 -04:00
|
|
|
protected int propertyId;
|
2010-07-19 05:22:42 -04:00
|
|
|
protected final PropertyType propertyType;
|
2010-05-20 05:22:03 -04:00
|
|
|
|
2010-07-10 20:13:28 -04:00
|
|
|
/**
|
|
|
|
* Create extended field uri.
|
|
|
|
*
|
|
|
|
* @param intPropertyTag property tag as int
|
|
|
|
* @param propertyType property type
|
|
|
|
*/
|
2010-06-08 06:46:00 -04:00
|
|
|
public ExtendedFieldURI(int intPropertyTag, PropertyType propertyType) {
|
2010-06-08 18:21:53 -04:00
|
|
|
this.propertyTag = "0x" + Integer.toHexString(intPropertyTag);
|
2010-05-20 05:22:03 -04:00
|
|
|
this.propertyType = propertyType;
|
|
|
|
}
|
|
|
|
|
2010-07-10 20:13:28 -04:00
|
|
|
/**
|
|
|
|
* Create extended field uri.
|
|
|
|
*
|
|
|
|
* @param distinguishedPropertySetId distinguished property set id
|
|
|
|
* @param propertyId property id
|
|
|
|
* @param propertyType property type
|
|
|
|
*/
|
2010-06-08 18:21:53 -04:00
|
|
|
public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, int propertyId, PropertyType propertyType) {
|
|
|
|
this.distinguishedPropertySetId = distinguishedPropertySetId;
|
2010-06-02 04:46:46 -04:00
|
|
|
this.propertyId = propertyId;
|
|
|
|
this.propertyType = propertyType;
|
|
|
|
}
|
|
|
|
|
2010-07-10 20:13:28 -04:00
|
|
|
/**
|
|
|
|
* Create extended field uri.
|
|
|
|
*
|
|
|
|
* @param distinguishedPropertySetId distinguished property set id
|
|
|
|
* @param propertyName property name
|
|
|
|
*/
|
2010-06-08 18:21:53 -04:00
|
|
|
public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName) {
|
|
|
|
this.distinguishedPropertySetId = distinguishedPropertySetId;
|
|
|
|
this.propertyName = propertyName;
|
2010-07-05 10:23:26 -04:00
|
|
|
this.propertyType = PropertyType.String;
|
2010-06-08 18:21:53 -04:00
|
|
|
}
|
|
|
|
|
2010-07-13 07:27:12 -04:00
|
|
|
/**
|
|
|
|
* Create extended field uri.
|
|
|
|
*
|
|
|
|
* @param distinguishedPropertySetId distinguished property set id
|
|
|
|
* @param propertyName property name
|
2010-07-20 05:10:39 -04:00
|
|
|
* @param propertyType property type
|
2010-07-13 07:27:12 -04:00
|
|
|
*/
|
|
|
|
public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType) {
|
|
|
|
this.distinguishedPropertySetId = distinguishedPropertySetId;
|
|
|
|
this.propertyName = propertyName;
|
|
|
|
this.propertyType = propertyType;
|
|
|
|
}
|
|
|
|
|
2010-06-07 17:17:07 -04:00
|
|
|
public void appendTo(StringBuilder buffer) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append("<t:ExtendedFieldURI");
|
2010-06-02 04:46:46 -04:00
|
|
|
if (propertyTag != null) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" PropertyTag=\"").append(propertyTag).append('"');
|
2010-06-02 04:46:46 -04:00
|
|
|
}
|
2010-06-08 18:21:53 -04:00
|
|
|
if (distinguishedPropertySetId != null) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append('"');
|
2010-06-08 18:21:53 -04:00
|
|
|
}
|
2010-06-02 04:46:46 -04:00
|
|
|
if (propertySetId != null) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" PropertySetId=\"").append(propertySetId).append('"');
|
2010-06-02 04:46:46 -04:00
|
|
|
}
|
2010-06-08 18:21:53 -04:00
|
|
|
if (propertyName != null) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" PropertyName=\"").append(propertyName).append('"');
|
2010-06-08 18:21:53 -04:00
|
|
|
}
|
2010-06-02 04:46:46 -04:00
|
|
|
if (propertyId != 0) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" PropertyId=\"").append(String.valueOf(propertyId)).append('"');
|
2010-06-02 04:46:46 -04:00
|
|
|
}
|
2010-06-08 18:21:53 -04:00
|
|
|
if (propertyType != null) {
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(" PropertyType=\"").append(propertyType.toString()).append('"');
|
2010-06-08 18:21:53 -04:00
|
|
|
}
|
2010-07-05 10:23:26 -04:00
|
|
|
buffer.append("/>");
|
2010-05-20 05:22:03 -04:00
|
|
|
}
|
|
|
|
|
2010-06-29 10:15:50 -04:00
|
|
|
public void appendValue(StringBuilder buffer, String itemType, String value) {
|
2010-07-05 05:58:18 -04:00
|
|
|
if (itemType != null) {
|
|
|
|
appendTo(buffer);
|
|
|
|
buffer.append("<t:");
|
|
|
|
buffer.append(itemType);
|
|
|
|
buffer.append('>');
|
|
|
|
}
|
2010-06-29 10:15:50 -04:00
|
|
|
buffer.append("<t:ExtendedProperty>");
|
|
|
|
appendTo(buffer);
|
2010-07-13 07:27:12 -04:00
|
|
|
if (propertyType == PropertyType.StringArray) {
|
|
|
|
buffer.append("<t:Values>");
|
|
|
|
String[] values = value.split("\n");
|
|
|
|
for (final String singleValue : values) {
|
|
|
|
buffer.append("<t:Value>");
|
2010-07-20 11:00:48 -04:00
|
|
|
buffer.append(StringUtil.xmlEncode(singleValue));
|
2010-07-13 07:27:12 -04:00
|
|
|
buffer.append("</t:Value>");
|
|
|
|
|
|
|
|
}
|
|
|
|
buffer.append("</t:Values>");
|
|
|
|
} else {
|
|
|
|
buffer.append("<t:Value>");
|
2010-07-25 16:36:52 -04:00
|
|
|
if ("0x10f3".equals(propertyTag)) {
|
|
|
|
buffer.append(StringUtil.xmlEncode(StringUtil.encodeUrlcompname(value)));
|
|
|
|
} else {
|
|
|
|
buffer.append(StringUtil.xmlEncode(value));
|
|
|
|
}
|
2010-07-13 07:27:12 -04:00
|
|
|
buffer.append("</t:Value>");
|
|
|
|
}
|
2010-06-29 10:15:50 -04:00
|
|
|
buffer.append("</t:ExtendedProperty>");
|
2010-07-05 05:58:18 -04:00
|
|
|
if (itemType != null) {
|
|
|
|
buffer.append("</t:");
|
|
|
|
buffer.append(itemType);
|
|
|
|
buffer.append('>');
|
|
|
|
}
|
2010-06-29 10:15:50 -04:00
|
|
|
}
|
|
|
|
|
2010-07-10 20:13:28 -04:00
|
|
|
/**
|
|
|
|
* Field name in EWS response.
|
|
|
|
*
|
|
|
|
* @return field name in response
|
|
|
|
*/
|
2010-07-01 12:12:57 -04:00
|
|
|
public String getResponseName() {
|
2010-07-07 08:29:41 -04:00
|
|
|
if (propertyTag != null) {
|
|
|
|
return propertyTag;
|
2010-07-13 07:27:12 -04:00
|
|
|
} else if (propertyName != null) {
|
|
|
|
return propertyName;
|
2010-07-07 08:29:41 -04:00
|
|
|
} else {
|
|
|
|
return String.valueOf(propertyId);
|
|
|
|
}
|
2010-07-01 12:12:57 -04:00
|
|
|
}
|
|
|
|
|
2010-05-20 05:22:03 -04:00
|
|
|
}
|
|
|
|
|