microsoft.exchange.webservices.data.misc.MapiTypeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ews-java-api Show documentation
Show all versions of ews-java-api Show documentation
Exchange Web Services (EWS) Java API
The newest version!
/*
* The MIT License
* Copyright (c) 2012 Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package microsoft.exchange.webservices.data.misc;
import microsoft.exchange.webservices.data.core.EwsUtilities;
import microsoft.exchange.webservices.data.core.ILazyMember;
import microsoft.exchange.webservices.data.core.LazyMember;
import microsoft.exchange.webservices.data.core.enumeration.property.MapiPropertyType;
import microsoft.exchange.webservices.data.core.exception.misc.FormatException;
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlDeserializationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* Utility class to convert between MAPI Property type values and strings.
*/
public class MapiTypeConverter {
private static final Log LOG = LogFactory.getLog(MapiTypeConverter.class);
private static final IFunction DATE_TIME_PARSER = new IFunction() {
public Object func(final String s) {
return parseDateTime(s);
}
};
private static final IFunction MAPI_VALUE_PARSER = new IFunction() {
public Object func(final String s) {
return MapiTypeConverter.parseMapiIntegerValue(s);
}
};
/**
* The mapi type converter map.
*/
private static final LazyMember MAPI_TYPE_CONVERTER_MAP =
new LazyMember(new ILazyMember() {
@Override
public MapiTypeConverterMap createInstance() {
MapiTypeConverterMap map = new MapiTypeConverterMap();
map.put(MapiPropertyType.ApplicationTime, new MapiTypeConverterMapEntry(Double.class));
MapiTypeConverterMapEntry mapitype = new MapiTypeConverterMapEntry(Double.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.ApplicationTimeArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(Byte[].class);
mapitype.setParse(IFunctions.Base64Decoder.INSTANCE);
mapitype.setConvertToString(IFunctions.Base64Encoder.INSTANCE);
map.put(MapiPropertyType.Binary, mapitype);
mapitype = new MapiTypeConverterMapEntry(Byte[].class);
mapitype.setParse(IFunctions.Base64Decoder.INSTANCE);
mapitype.setConvertToString(IFunctions.Base64Encoder.INSTANCE);
mapitype.setIsArray(true);
map.put(MapiPropertyType.BinaryArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(Boolean.class);
mapitype.setParse(IFunctions.ToBoolean.INSTANCE);
mapitype.setConvertToString(IFunctions.ToLowerCase.INSTANCE);
map.put(MapiPropertyType.Boolean, mapitype);
mapitype = new MapiTypeConverterMapEntry(UUID.class);
mapitype.setParse(IFunctions.ToUUID.INSTANCE);
mapitype.setConvertToString(IFunctions.ToString.INSTANCE);
map.put(MapiPropertyType.CLSID, mapitype);
mapitype = new MapiTypeConverterMapEntry(UUID.class);
mapitype.setParse(IFunctions.ToUUID.INSTANCE);
mapitype.setConvertToString(IFunctions.ToString.INSTANCE);
mapitype.setIsArray(true);
map.put(MapiPropertyType.CLSIDArray, mapitype);
map.put(MapiPropertyType.Currency, new MapiTypeConverterMapEntry(Long.class));
mapitype = new MapiTypeConverterMapEntry(Long.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.CurrencyArray, mapitype);
map.put(MapiPropertyType.Double, new MapiTypeConverterMapEntry(Double.class));
mapitype = new MapiTypeConverterMapEntry(Double.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.DoubleArray, mapitype);
map.put(MapiPropertyType.Error, new MapiTypeConverterMapEntry(Integer.class));
map.put(MapiPropertyType.Float, new MapiTypeConverterMapEntry(Float.class));
mapitype = new MapiTypeConverterMapEntry(Float.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.FloatArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(Integer.class);
mapitype.setParse(MAPI_VALUE_PARSER);
map.put(MapiPropertyType.Integer, mapitype);
mapitype = new MapiTypeConverterMapEntry(Integer.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.IntegerArray, mapitype);
map.put(MapiPropertyType.Long, new MapiTypeConverterMapEntry(Long.class));
mapitype = new MapiTypeConverterMapEntry(Long.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.LongArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(String.class);
mapitype.setParse(IFunctions.StringToObject.INSTANCE);
map.put(MapiPropertyType.Object, mapitype);
mapitype = new MapiTypeConverterMapEntry(String.class);
mapitype.setParse(IFunctions.StringToObject.INSTANCE);
mapitype.setIsArray(true);
map.put(MapiPropertyType.ObjectArray, mapitype);
map.put(MapiPropertyType.Short, new MapiTypeConverterMapEntry(Short.class));
mapitype = new MapiTypeConverterMapEntry(Short.class);
mapitype.setIsArray(true);
map.put(MapiPropertyType.ShortArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(String.class);
mapitype.setParse(IFunctions.StringToObject.INSTANCE);
map.put(MapiPropertyType.String, mapitype);
mapitype = new MapiTypeConverterMapEntry(String.class);
mapitype.setParse(IFunctions.StringToObject.INSTANCE);
mapitype.setIsArray(true);
map.put(MapiPropertyType.StringArray, mapitype);
mapitype = new MapiTypeConverterMapEntry(Date.class);
mapitype.setParse(DATE_TIME_PARSER);
mapitype.setConvertToString(IFunctions.DateTimeToXSDateTime.INSTANCE);
map.put(MapiPropertyType.SystemTime, mapitype);
mapitype = new MapiTypeConverterMapEntry(Date.class);
mapitype.setParse(DATE_TIME_PARSER);
mapitype.setConvertToString(IFunctions.DateTimeToXSDateTime.INSTANCE);
mapitype.setIsArray(true);
map.put(MapiPropertyType.SystemTimeArray, mapitype);
return map;
}
});
/**
* Converts the string list to array.
*
* @param mapiPropType Type of the MAPI property.
* @param strings the strings
* @return Array of objects.
* @throws Exception the exception
*/
public static List