mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
EWS: implement resolvenames response parsing
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1325 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
247ab3df9e
commit
1d4c095dc1
@ -82,10 +82,21 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
* @param methodName method name
|
* @param methodName method name
|
||||||
*/
|
*/
|
||||||
public EWSMethod(String itemType, String methodName) {
|
public EWSMethod(String itemType, String methodName) {
|
||||||
|
this(itemType, methodName, itemType + 's');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build EWS method
|
||||||
|
*
|
||||||
|
* @param itemType item type
|
||||||
|
* @param methodName method name
|
||||||
|
* @param responseCollectionName item response collection name
|
||||||
|
*/
|
||||||
|
public EWSMethod(String itemType, String methodName, String responseCollectionName) {
|
||||||
super("/ews/exchange.asmx");
|
super("/ews/exchange.asmx");
|
||||||
this.itemType = itemType;
|
this.itemType = itemType;
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
responseCollectionName = itemType + 's';
|
this.responseCollectionName = responseCollectionName;
|
||||||
setRequestEntity(new RequestEntity() {
|
setRequestEntity(new RequestEntity() {
|
||||||
byte[] content;
|
byte[] content;
|
||||||
|
|
||||||
@ -649,7 +660,6 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||||
String tagLocalName = reader.getLocalName();
|
String tagLocalName = reader.getLocalName();
|
||||||
String value = null;
|
String value = null;
|
||||||
// detect version
|
|
||||||
if ("ExtendedProperty".equals(tagLocalName)) {
|
if ("ExtendedProperty".equals(tagLocalName)) {
|
||||||
addExtendedPropertyValue(reader, responseItem);
|
addExtendedPropertyValue(reader, responseItem);
|
||||||
} else if (tagLocalName.endsWith("MimeContent")) {
|
} else if (tagLocalName.endsWith("MimeContent")) {
|
||||||
@ -751,7 +761,7 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTagContent(XMLStreamReader reader) throws XMLStreamException {
|
protected String getTagContent(XMLStreamReader reader) throws XMLStreamException {
|
||||||
String tagLocalName = reader.getLocalName();
|
String tagLocalName = reader.getLocalName();
|
||||||
while (reader.hasNext() && !(reader.getEventType() == XMLStreamConstants.END_ELEMENT)) {
|
while (reader.hasNext() && !(reader.getEventType() == XMLStreamConstants.END_ELEMENT)) {
|
||||||
reader.next();
|
reader.next();
|
||||||
|
@ -18,20 +18,65 @@
|
|||||||
*/
|
*/
|
||||||
package davmail.exchange.ews;
|
package davmail.exchange.ews;
|
||||||
|
|
||||||
|
import javax.xml.stream.XMLStreamConstants;
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
import javax.xml.stream.XMLStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve Names method.
|
* Resolve Names method.
|
||||||
*/
|
*/
|
||||||
public class ResolveNamesMethod extends EWSMethod {
|
public class ResolveNamesMethod extends EWSMethod {
|
||||||
protected static final AttributeOption RETURN_FULL_CONTACT_DATA = new AttributeOption("ReturnFullContactData", "true");
|
protected static final AttributeOption RETURN_FULL_CONTACT_DATA = new AttributeOption("ReturnFullContactData", "true");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build Resolve Names method
|
* Build Resolve Names method
|
||||||
*
|
*
|
||||||
* @param value search value
|
* @param value search value
|
||||||
*/
|
*/
|
||||||
public ResolveNamesMethod(String value) {
|
public ResolveNamesMethod(String value) {
|
||||||
super("Contact", "ResolveNames");
|
super("Contact", "ResolveNames", "ResolutionSet");
|
||||||
addMethodOption(SearchScope.ActiveDirectory);
|
addMethodOption(SearchScope.ActiveDirectory);
|
||||||
addMethodOption(RETURN_FULL_CONTACT_DATA);
|
addMethodOption(RETURN_FULL_CONTACT_DATA);
|
||||||
unresolvedEntry = new ElementOption("m:UnresolvedEntry", value);
|
unresolvedEntry = new ElementOption("m:UnresolvedEntry", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Item handleItem(XMLStreamReader reader) throws XMLStreamException {
|
||||||
|
Item responseItem = new Item();
|
||||||
|
responseItem.type = "Contact";
|
||||||
|
// skip to Contact
|
||||||
|
while (reader.hasNext() && !isStartTag(reader, "Contact")) {
|
||||||
|
reader.next();
|
||||||
|
}
|
||||||
|
while (reader.hasNext() && !isEndTag(reader, "Contact")) {
|
||||||
|
int event = reader.next();
|
||||||
|
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||||
|
String tagLocalName = reader.getLocalName();
|
||||||
|
if ("EmailAddresses".equals(tagLocalName)) {
|
||||||
|
handleAddresses(reader, responseItem);
|
||||||
|
} else {
|
||||||
|
responseItem.put(tagLocalName, reader.getElementText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
|
||||||
|
while (reader.hasNext() && !isEndTag(reader, "EmailAddresses")) {
|
||||||
|
int event = reader.next();
|
||||||
|
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||||
|
String tagLocalName = reader.getLocalName();
|
||||||
|
if ("Entry".equals(tagLocalName)) {
|
||||||
|
String key = getAttributeValue(reader, "Key");
|
||||||
|
String value = reader.getElementText();
|
||||||
|
if (value.startsWith("smtp:") || value.startsWith("SMTP:")) {
|
||||||
|
value = value.substring(5);
|
||||||
|
}
|
||||||
|
responseItem.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package davmail.exchange.ews;
|
|||||||
import davmail.exchange.AbstractExchangeSessionTestCase;
|
import davmail.exchange.AbstractExchangeSessionTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Webdav specific unit tests
|
* Webdav specific unit tests
|
||||||
@ -34,5 +35,12 @@ public class TestEwsExchangeSession extends AbstractExchangeSessionTestCase {
|
|||||||
ewsSession = ((EwsExchangeSession) session);
|
ewsSession = ((EwsExchangeSession) session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testResolveNames() throws IOException {
|
||||||
|
ResolveNamesMethod resolveNamesMethod = new ResolveNamesMethod("smtp:g");
|
||||||
|
ewsSession.executeMethod(resolveNamesMethod);
|
||||||
|
List<EWSMethod.Item> items = resolveNamesMethod.getResponseItems();
|
||||||
|
for (EWSMethod.Item item:items) {
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user