Class EwsUtilities
- java.lang.Object
-
- microsoft.exchange.webservices.data.core.EwsUtilities
-
public final class EwsUtilities extends Object
EWS utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAutodiscoverSoapNamespaceThe Constant AutodiscoverSoapNamespace.static StringAutodiscoverSoapNamespacePrefixThe Constant AutodiscoverSoapNamespacePrefix.static StringDomainRegexRegular expression for legal domain names.static LazyMember<Map<Class<?>,Map<String,String>>>ENUM_TO_SCHEMA_DICTIONARIESDictionary of enum type to enum-value-to-schema-name maps.static StringEwsErrorsNamespaceThe Constant EwsErrorsNamespace.static StringEwsErrorsNamespacePrefixThe Constant EwsErrorsNamespacePrefix.static StringEwsMessagesNamespaceThe Constant EwsMessagesNamespace.static StringEwsMessagesNamespacePrefixThe Constant EwsMessagesNamespacePrefix.static StringEwsSoap12NamespaceThe Constant EwsSoap12Namespace.static StringEwsSoapNamespaceThe Constant EwsSoapNamespace.static StringEwsSoapNamespacePrefixThe Constant EwsSoapNamespacePrefix.static StringEwsTypesNamespaceThe Constant EwsTypesNamespace.static StringEwsTypesNamespacePrefixThe Constant EwsTypesNamespacePrefix.static StringEwsXmlSchemaInstanceNamespaceThe Constant EwsXmlSchemaInstanceNamespace.static StringEwsXmlSchemaInstanceNamespacePrefixThe Constant EwsXmlSchemaInstanceNamespacePrefix.static StringPassportSoapFaultNamespaceThe Constant PassportSoapFaultNamespace.static StringPassportSoapFaultNamespacePrefixThe Constant PassportSoapFaultNamespacePrefix.static StringWSAddressingNamespaceThe Constant WSAddressingNamespace.static StringWSAddressingNamespacePrefixThe Constant WSAddressingNamespacePrefix.static StringWSSecuritySecExtNamespacestatic StringWSSecuritySecExtNamespacePrefixThe Constant WSSecuritySecExtNamespacePrefix.static StringWSSecurityUtilityNamespacestatic StringWSSecurityUtilityNamespacePrefixThe Constant WSSecurityUtilityNamespacePrefix.static StringWSTrustFebruary2005NamespaceThe Constant WSTrustFebruary2005Namespace.static StringWSTrustFebruary2005NamespacePrefixThe Constant WSTrustFebruary2005NamespacePrefix.static StringXSFalseThe Constant XSFalse.static StringXSTrueThe Constant XSTrue.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringboolToXSBool(Boolean value)Convert bool to XML Schema bool.static intcountMatchingChars(String str, IPredicate<Character> charPredicate)Count characters in string that match a condition.static <TServiceObject extends ServiceObject>
TServiceObjectcreateEwsObjectFromXmlElementName(Class<?> itemClass, ExchangeService service, String xmlElementName)Creates the ews object from xml element name.static ItemcreateItemFromItemClass(ItemAttachment itemAttachment, Class<?> itemClass, boolean isNew)Creates the item from item class.static ItemcreateItemFromXmlElementName(ItemAttachment itemAttachment, String xmlElementName)Creates the item from xml element name.static StringdateTimeToXSDate(Date date)Convert DateTime to XML Schema date.static StringdateTimeToXSDateTime(Date date)Dates the DateTime into an XML schema date time.static StringdomainFromEmailAddress(String emailAddress)Gets the domain name from an email address.static voidewsAssert(boolean condition, String caller, String message)Asserts that the specified condition if true.static <TItem extends Item>
TItemfindFirstItemOfType(Class<TItem> cls, Iterable<Item> items)Finds the first item of type TItem (not a descendant type) in the specified collection.static <T> voidforEach(Iterable<T> collection, IAction<T> action)Call an action for each member of a collection.static StringformatHttpRequestHeaders(HttpWebRequest request)Format request HTTP headers.static StringformatHttpResponseHeaders(HttpWebRequest response)Format http response headers.static StringformatLogMessage(String entryKind, String logEntry).static StringformatLogMessageWithXmlContent(String traceTypeStr, ByteArrayOutputStream stream)Format XML content in a MemoryStream for message.static StringgetBuildVersion()Gets the builds the version.static intgetDim(Object array)static <T> ObjectgetEnumeratedObjectAt(Iterable<T> objects, int index)Gets the enumerated object at.static <T> intgetEnumeratedObjectCount(Iterator<T> objects)Gets the enumerated object count.static Class<?>getItemTypeFromXmlElementName(String xmlElementName)static XmlNamespacegetNamespaceFromUri(String namespaceUri)Gets the namespace from uri.static StringgetNamespacePrefix(XmlNamespace xmlNamespace)Gets the namespace prefix from an XmlNamespace enum value.static StringgetNamespaceUri(XmlNamespace xmlNamespace)Gets the namespace URI from an XmlNamespace enum value.static StringgetTimeSpanToXSDuration(TimeSpan timeOffset)Takes a System.TimeSpan structure and converts it into an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#durationstatic TimeSpangetXSDurationToTimeSpan(String xsDuration)Takes an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a System.TimeSpan structure This method uses the following approximations: 1 year = 365 days 1 month = 30 days Additionally, it only allows for four decimal points of seconds precision.static <T> Tparse(Class<T> cls, String value)Parses the.static <T extends Enum<?>>
voidparseEnumValueList(Class<T> c, List<T> list, String value, char... separators)Parses an enum value list.static StringserializeEnum(Object value)Converts an enum to a string, using the mapping dictionaries if appropriate.static StringtimeSpanToXSTime(TimeSpan timeSpan)Time span to xs time.static <T> booleantrueForAll(Iterable<T> collection, IPredicate<T> predicate)Determines whether every element in the collection matches the conditions defined by the specified predicate.static voidvalidateClassVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String className)Validates class version against the request version.static voidvalidateDomainNameAllowNull(String domainName, String paramName)Validates domain name (null value allowed)static voidvalidateEnumVersionValue(Enum<?> enumValue, ExchangeVersion requestVersion)Validate enum version value.static voidvalidateMethodVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String methodName)Validate method version.static voidvalidateNonBlankStringParam(String param, String paramName)Validates string parameter to be non-empty string (null value not allowed).static voidvalidateNonBlankStringParamAllowNull(String param, String paramName)Validates string parameter to be non-empty string (null value allowed).static voidvalidateParam(Object param, String paramName)Validates parameter (null value not allowed).static voidvalidateParamAllowNull(Object param, String paramName)Validates parameter (and allows null value).static <T> voidvalidateParamCollection(Iterator<T> collection, String paramName)Validates parameter collection.static voidvalidateParamCollection(EventType[] eventTypes, String paramName)Validate param collection.static voidvalidatePropertyVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String propertyName)Validates property version against the request version.static voidvalidateServiceObjectVersion(ServiceObject serviceObject, ExchangeVersion requestVersion)Validates service object version against the request version.
-
-
-
Field Detail
-
XSFalse
public static final String XSFalse
The Constant XSFalse.- See Also:
- Constant Field Values
-
XSTrue
public static final String XSTrue
The Constant XSTrue.- See Also:
- Constant Field Values
-
EwsTypesNamespacePrefix
public static final String EwsTypesNamespacePrefix
The Constant EwsTypesNamespacePrefix.- See Also:
- Constant Field Values
-
EwsMessagesNamespacePrefix
public static final String EwsMessagesNamespacePrefix
The Constant EwsMessagesNamespacePrefix.- See Also:
- Constant Field Values
-
EwsErrorsNamespacePrefix
public static final String EwsErrorsNamespacePrefix
The Constant EwsErrorsNamespacePrefix.- See Also:
- Constant Field Values
-
EwsSoapNamespacePrefix
public static final String EwsSoapNamespacePrefix
The Constant EwsSoapNamespacePrefix.- See Also:
- Constant Field Values
-
EwsXmlSchemaInstanceNamespacePrefix
public static final String EwsXmlSchemaInstanceNamespacePrefix
The Constant EwsXmlSchemaInstanceNamespacePrefix.- See Also:
- Constant Field Values
-
PassportSoapFaultNamespacePrefix
public static final String PassportSoapFaultNamespacePrefix
The Constant PassportSoapFaultNamespacePrefix.- See Also:
- Constant Field Values
-
WSTrustFebruary2005NamespacePrefix
public static final String WSTrustFebruary2005NamespacePrefix
The Constant WSTrustFebruary2005NamespacePrefix.- See Also:
- Constant Field Values
-
WSAddressingNamespacePrefix
public static final String WSAddressingNamespacePrefix
The Constant WSAddressingNamespacePrefix.- See Also:
- Constant Field Values
-
AutodiscoverSoapNamespacePrefix
public static final String AutodiscoverSoapNamespacePrefix
The Constant AutodiscoverSoapNamespacePrefix.- See Also:
- Constant Field Values
-
WSSecurityUtilityNamespacePrefix
public static final String WSSecurityUtilityNamespacePrefix
The Constant WSSecurityUtilityNamespacePrefix.- See Also:
- Constant Field Values
-
WSSecuritySecExtNamespacePrefix
public static final String WSSecuritySecExtNamespacePrefix
The Constant WSSecuritySecExtNamespacePrefix.- See Also:
- Constant Field Values
-
EwsTypesNamespace
public static final String EwsTypesNamespace
The Constant EwsTypesNamespace.- See Also:
- Constant Field Values
-
EwsMessagesNamespace
public static final String EwsMessagesNamespace
The Constant EwsMessagesNamespace.- See Also:
- Constant Field Values
-
EwsErrorsNamespace
public static final String EwsErrorsNamespace
The Constant EwsErrorsNamespace.- See Also:
- Constant Field Values
-
EwsSoapNamespace
public static final String EwsSoapNamespace
The Constant EwsSoapNamespace.- See Also:
- Constant Field Values
-
EwsSoap12Namespace
public static final String EwsSoap12Namespace
The Constant EwsSoap12Namespace.- See Also:
- Constant Field Values
-
EwsXmlSchemaInstanceNamespace
public static final String EwsXmlSchemaInstanceNamespace
The Constant EwsXmlSchemaInstanceNamespace.- See Also:
- Constant Field Values
-
PassportSoapFaultNamespace
public static final String PassportSoapFaultNamespace
The Constant PassportSoapFaultNamespace.- See Also:
- Constant Field Values
-
WSTrustFebruary2005Namespace
public static final String WSTrustFebruary2005Namespace
The Constant WSTrustFebruary2005Namespace.- See Also:
- Constant Field Values
-
WSAddressingNamespace
public static final String WSAddressingNamespace
The Constant WSAddressingNamespace.- See Also:
- Constant Field Values
-
AutodiscoverSoapNamespace
public static final String AutodiscoverSoapNamespace
The Constant AutodiscoverSoapNamespace.- See Also:
- Constant Field Values
-
WSSecurityUtilityNamespace
public static final String WSSecurityUtilityNamespace
- See Also:
- Constant Field Values
-
WSSecuritySecExtNamespace
public static final String WSSecuritySecExtNamespace
- See Also:
- Constant Field Values
-
ENUM_TO_SCHEMA_DICTIONARIES
public static final LazyMember<Map<Class<?>,Map<String,String>>> ENUM_TO_SCHEMA_DICTIONARIES
Dictionary of enum type to enum-value-to-schema-name maps.
-
DomainRegex
public static final String DomainRegex
Regular expression for legal domain names.- See Also:
- Constant Field Values
-
-
Method Detail
-
getBuildVersion
public static String getBuildVersion()
Gets the builds the version.- Returns:
- the builds the version
-
ewsAssert
public static void ewsAssert(boolean condition, String caller, String message)
Asserts that the specified condition if true.- Parameters:
condition- Assertion.caller- The caller.message- The message to use if assertion fails.
-
getNamespacePrefix
public static String getNamespacePrefix(XmlNamespace xmlNamespace)
Gets the namespace prefix from an XmlNamespace enum value.- Parameters:
xmlNamespace- The XML namespace- Returns:
- Namespace prefix string.
-
getNamespaceUri
public static String getNamespaceUri(XmlNamespace xmlNamespace)
Gets the namespace URI from an XmlNamespace enum value.- Parameters:
xmlNamespace- The XML namespace.- Returns:
- Uri as string
-
getNamespaceFromUri
public static XmlNamespace getNamespaceFromUri(String namespaceUri)
Gets the namespace from uri.- Parameters:
namespaceUri- the namespace uri- Returns:
- the namespace from uri
-
createEwsObjectFromXmlElementName
public static <TServiceObject extends ServiceObject> TServiceObject createEwsObjectFromXmlElementName(Class<?> itemClass, ExchangeService service, String xmlElementName) throws Exception
Creates the ews object from xml element name.- Type Parameters:
TServiceObject- the generic type- Parameters:
itemClass- the item classservice- the servicexmlElementName- the xml element name- Returns:
- the t service object
- Throws:
Exception- the exception
-
createItemFromItemClass
public static Item createItemFromItemClass(ItemAttachment itemAttachment, Class<?> itemClass, boolean isNew) throws Exception
Creates the item from item class.- Parameters:
itemAttachment- the item attachmentitemClass- the item classisNew- the is new- Returns:
- the item
- Throws:
Exception- the exception
-
createItemFromXmlElementName
public static Item createItemFromXmlElementName(ItemAttachment itemAttachment, String xmlElementName) throws Exception
Creates the item from xml element name.- Parameters:
itemAttachment- the item attachmentxmlElementName- the xml element name- Returns:
- the item
- Throws:
Exception- the exception
-
getItemTypeFromXmlElementName
public static Class<?> getItemTypeFromXmlElementName(String xmlElementName)
-
findFirstItemOfType
public static <TItem extends Item> TItem findFirstItemOfType(Class<TItem> cls, Iterable<Item> items)
Finds the first item of type TItem (not a descendant type) in the specified collection.- Type Parameters:
TItem- TItem is the type of the item to find.- Parameters:
cls- the clsitems- the item- Returns:
- A TItem instance or null if no instance of TItem could be found.
-
formatLogMessage
public static String formatLogMessage(String entryKind, String logEntry) throws XMLStreamException, IOException
.- Parameters:
entryKind- the entry kindlogEntry- the log entry- Returns:
- the string
- Throws:
XMLStreamException- the XML stream exceptionIOException- signals that an I/O exception has occurred.
-
formatHttpResponseHeaders
public static String formatHttpResponseHeaders(HttpWebRequest response) throws EWSHttpException
Format http response headers.- Parameters:
response- the response- Returns:
- the string
- Throws:
EWSHttpException- the EWS http exception
-
formatHttpRequestHeaders
public static String formatHttpRequestHeaders(HttpWebRequest request) throws URISyntaxException, EWSHttpException
Format request HTTP headers.- Parameters:
request- The HTTP request.- Throws:
URISyntaxExceptionEWSHttpException
-
formatLogMessageWithXmlContent
public static String formatLogMessageWithXmlContent(String traceTypeStr, ByteArrayOutputStream stream)
Format XML content in a MemoryStream for message.- Parameters:
traceTypeStr- Kind of the entry.stream- The memory stream.- Returns:
- XML log entry as a string.
-
boolToXSBool
public static String boolToXSBool(Boolean value)
Convert bool to XML Schema bool.- Parameters:
value- Bool value.- Returns:
- String representing bool value in XML Schema.
-
parseEnumValueList
public static <T extends Enum<?>> void parseEnumValueList(Class<T> c, List<T> list, String value, char... separators)
Parses an enum value list.- Type Parameters:
T- the generic type- Parameters:
c- the clist- the listvalue- the valueseparators- the separators
-
serializeEnum
public static String serializeEnum(Object value)
Converts an enum to a string, using the mapping dictionaries if appropriate.- Parameters:
value- The enum value to be serialized- Returns:
- String representation of enum to be used in the protocol
-
parse
public static <T> T parse(Class<T> cls, String value) throws ParseException
Parses the.- Type Parameters:
T- the generic type- Parameters:
cls- the clsvalue- the value- Returns:
- the t
- Throws:
ParseException- the parse exception
-
validateParamCollection
public static void validateParamCollection(EventType[] eventTypes, String paramName) throws Exception
Validate param collection.- Parameters:
eventTypes- the event typesparamName- the param name- Throws:
Exception- the exception
-
dateTimeToXSDate
public static String dateTimeToXSDate(Date date)
Convert DateTime to XML Schema date.- Parameters:
date- the date- Returns:
- String representation of DateTime.
-
dateTimeToXSDateTime
public static String dateTimeToXSDateTime(Date date)
Dates the DateTime into an XML schema date time.- Parameters:
date- the date- Returns:
- String representation of DateTime.
-
getTimeSpanToXSDuration
public static String getTimeSpanToXSDuration(TimeSpan timeOffset)
Takes a System.TimeSpan structure and converts it into an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration- Parameters:
timeOffset- structure to convert- Returns:
- xs:duration formatted string
-
getXSDurationToTimeSpan
public static TimeSpan getXSDurationToTimeSpan(String xsDuration)
Takes an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a System.TimeSpan structure This method uses the following approximations: 1 year = 365 days 1 month = 30 days Additionally, it only allows for four decimal points of seconds precision.- Parameters:
xsDuration- xs:duration string to convert- Returns:
- System.TimeSpan structure
-
timeSpanToXSTime
public static String timeSpanToXSTime(TimeSpan timeSpan)
Time span to xs time.- Parameters:
timeSpan- the time span- Returns:
- the string
-
domainFromEmailAddress
public static String domainFromEmailAddress(String emailAddress) throws FormatException
Gets the domain name from an email address.- Parameters:
emailAddress- The email address.- Returns:
- Domain name.
- Throws:
FormatException- the format exception
-
validateParamAllowNull
public static void validateParamAllowNull(Object param, String paramName) throws Exception
Validates parameter (and allows null value).- Parameters:
param- The param.paramName- Name of the param.- Throws:
Exception- the exception
-
validateParam
public static void validateParam(Object param, String paramName) throws Exception
Validates parameter (null value not allowed).- Parameters:
param- The param.paramName- Name of the param.- Throws:
Exception- the exception
-
validateParamCollection
public static <T> void validateParamCollection(Iterator<T> collection, String paramName) throws Exception
Validates parameter collection.- Type Parameters:
T- the generic type- Parameters:
collection- The collection.paramName- Name of the param.- Throws:
Exception- the exception
-
validateNonBlankStringParamAllowNull
public static void validateNonBlankStringParamAllowNull(String param, String paramName) throws ArgumentException, ServiceLocalException
Validates string parameter to be non-empty string (null value allowed).- Parameters:
param- The string parameter.paramName- Name of the parameter.- Throws:
ArgumentExceptionServiceLocalException
-
validateNonBlankStringParam
public static void validateNonBlankStringParam(String param, String paramName) throws ArgumentNullException, ArgumentException, ServiceLocalException
Validates string parameter to be non-empty string (null value not allowed).- Parameters:
param- The string parameter.paramName- Name of the parameter.- Throws:
ArgumentNullExceptionArgumentExceptionServiceLocalException
-
validateEnumVersionValue
public static void validateEnumVersionValue(Enum<?> enumValue, ExchangeVersion requestVersion) throws ServiceVersionException
Validate enum version value.- Parameters:
enumValue- the enum valuerequestVersion- the request version- Throws:
ServiceVersionException- the service version exception
-
validateServiceObjectVersion
public static void validateServiceObjectVersion(ServiceObject serviceObject, ExchangeVersion requestVersion) throws ServiceVersionException
Validates service object version against the request version.- Parameters:
serviceObject- The service object.requestVersion- The request version.- Throws:
ServiceVersionException- Raised if this service object type requires a later version of Exchange.
-
validatePropertyVersion
public static void validatePropertyVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String propertyName) throws ServiceVersionException
Validates property version against the request version.- Parameters:
service- The Exchange service.minimumServerVersion- The minimum server versionpropertyName- The property name- Throws:
ServiceVersionException- The service version exception
-
validateMethodVersion
public static void validateMethodVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String methodName) throws ServiceVersionException
Validate method version.- Parameters:
service- the serviceminimumServerVersion- the minimum server versionmethodName- the method name- Throws:
ServiceVersionException- the service version exception
-
validateClassVersion
public static void validateClassVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String className) throws ServiceVersionException
Validates class version against the request version.- Parameters:
service- the serviceminimumServerVersion- The minimum server version that supports the method.className- Name of the class.- Throws:
ServiceVersionException
-
validateDomainNameAllowNull
public static void validateDomainNameAllowNull(String domainName, String paramName) throws ArgumentException
Validates domain name (null value allowed)- Parameters:
domainName- Domain name.paramName- Parameter name.- Throws:
ArgumentException
-
getEnumeratedObjectCount
public static <T> int getEnumeratedObjectCount(Iterator<T> objects)
Gets the enumerated object count.- Type Parameters:
T- the generic type- Parameters:
objects- The objects.- Returns:
- Count of objects in iterator.
-
getEnumeratedObjectAt
public static <T> Object getEnumeratedObjectAt(Iterable<T> objects, int index)
Gets the enumerated object at.- Type Parameters:
T- the generic type- Parameters:
objects- the objectsindex- the index- Returns:
- the enumerated object at
-
countMatchingChars
public static int countMatchingChars(String str, IPredicate<Character> charPredicate) throws ServiceLocalException
Count characters in string that match a condition.- Parameters:
str- The string.charPredicate- Predicate to evaluate for each character in the string.- Returns:
- Count of characters that match condition expressed by predicate.
- Throws:
ServiceLocalException
-
trueForAll
public static <T> boolean trueForAll(Iterable<T> collection, IPredicate<T> predicate) throws ServiceLocalException
Determines whether every element in the collection matches the conditions defined by the specified predicate.- Type Parameters:
T- Entry type.- Parameters:
collection- The collection.predicate- Predicate that defines the conditions to check against the elements.- Returns:
- True if every element in the collection matches the conditions defined by the specified predicate; otherwise, false.
- Throws:
ServiceLocalException
-
-