1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 19:22:22 -05:00

Refactor XMLStreamUtil

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1392 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-08-28 20:21:31 +00:00
parent 0529be03a1
commit 4962684d0f
8 changed files with 138 additions and 109 deletions

View File

@ -36,7 +36,6 @@ import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.util.URIUtil; import org.apache.commons.httpclient.util.URIUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
@ -1375,12 +1374,10 @@ public class CaldavConnection extends AbstractConnection {
protected void parseXmlBody() throws IOException { protected void parseXmlBody() throws IOException {
XMLStreamReader streamReader = null; XMLStreamReader streamReader = null;
try { try {
XMLInputFactory inputFactory = XMLStreamUtil.getXmlInputFactory(); streamReader = XMLStreamUtil.createXMLStreamReader(body);
streamReader = inputFactory.createXMLStreamReader(new StringReader(body));
while (streamReader.hasNext()) { while (streamReader.hasNext()) {
int event = streamReader.next(); streamReader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(streamReader)) {
String tagLocalName = streamReader.getLocalName(); String tagLocalName = streamReader.getLocalName();
if ("prop".equals(tagLocalName)) { if ("prop".equals(tagLocalName)) {
handleProp(streamReader); handleProp(streamReader);
@ -1420,21 +1417,18 @@ public class CaldavConnection extends AbstractConnection {
public void handleCompFilter(XMLStreamReader reader) throws XMLStreamException { public void handleCompFilter(XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "comp-filter")) { while (reader.hasNext() && !isEndTag(reader, "comp-filter")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader, "time-range")) {
String tagLocalName = reader.getLocalName(); timeRangeStart = reader.getAttributeValue(null, "start");
if ("time-range".equals(tagLocalName)) { timeRangeEnd = reader.getAttributeValue(null, "end");
timeRangeStart = reader.getAttributeValue(null, "start");
timeRangeEnd = reader.getAttributeValue(null, "end");
}
} }
} }
} }
public void handleProp(XMLStreamReader reader) throws XMLStreamException { public void handleProp(XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "prop")) { while (reader.hasNext() && !isEndTag(reader, "prop")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
String tagText = null; String tagText = null;
if (reader.hasText()) { if (reader.hasText()) {

View File

@ -22,8 +22,10 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -122,4 +124,60 @@ public final class XMLStreamUtil {
return (reader.getEventType() == XMLStreamConstants.START_ELEMENT) && (reader.getLocalName().equals(tagLocalName)); return (reader.getEventType() == XMLStreamConstants.START_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
} }
/**
* Test if reader is on a start tag.
*
* @param reader xml stream reader
* @return true if reader is on a start tag
*/
public static boolean isStartTag(XMLStreamReader reader) {
return (reader.getEventType() == XMLStreamConstants.START_ELEMENT);
}
/**
* Test if reader is on an end tag named tagLocalName.
*
* @param reader xml stream reader
* @param tagLocalName tag local name
* @return true if reader is on an end tag named tagLocalName
*/
public static boolean isEndTag(XMLStreamReader reader, String tagLocalName) {
return (reader.getEventType() == XMLStreamConstants.END_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
}
/**
* Create XML stream reader for byte array
*
* @param xmlContent xml content as byte array
* @return XML stream reader
* @throws XMLStreamException on error
*/
public static XMLStreamReader createXMLStreamReader(byte[] xmlContent) throws XMLStreamException {
return createXMLStreamReader(new ByteArrayInputStream(xmlContent));
}
/**
* Create XML stream reader for string
*
* @param xmlContent xml content as string
* @return XML stream reader
* @throws XMLStreamException on error
*/
public static XMLStreamReader createXMLStreamReader(String xmlContent) throws XMLStreamException {
XMLInputFactory xmlInputFactory = XMLStreamUtil.getXmlInputFactory();
return xmlInputFactory.createXMLStreamReader(new StringReader(xmlContent));
}
/**
* Create XML stream reader for inputStream
*
* @param inputStream xml content inputStream
* @return XML stream reader
* @throws XMLStreamException on error
*/
public static XMLStreamReader createXMLStreamReader(InputStream inputStream) throws XMLStreamException {
XMLInputFactory xmlInputFactory = XMLStreamUtil.getXmlInputFactory();
return xmlInputFactory.createXMLStreamReader(inputStream);
}
} }

View File

@ -53,7 +53,6 @@ import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimePart; import javax.mail.internet.MimePart;
import javax.mail.util.SharedByteArrayInputStream; import javax.mail.util.SharedByteArrayInputStream;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.*; import java.io.*;
@ -1981,10 +1980,9 @@ public class DavExchangeSession extends ExchangeSession {
String timezoneName = null; String timezoneName = null;
XMLStreamReader reader; XMLStreamReader reader;
try { try {
XMLInputFactory xmlInputFactory = XMLStreamUtil.getXmlInputFactory(); reader = XMLStreamUtil.createXMLStreamReader(roamingdictionary);
reader = xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(roamingdictionary));
while (reader.hasNext()) { while (reader.hasNext()) {
reader.next(); reader.nextTag();
if (XMLStreamUtil.isStartTag(reader, "e") if (XMLStreamUtil.isStartTag(reader, "e")
&& "18-timezone".equals( XMLStreamUtil.getAttributeValue(reader, "k"))) { && "18-timezone".equals( XMLStreamUtil.getAttributeValue(reader, "k"))) {
String value = XMLStreamUtil.getAttributeValue(reader, "v"); String value = XMLStreamUtil.getAttributeValue(reader, "v");

View File

@ -27,8 +27,6 @@ import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
import org.apache.jackrabbit.webdav.xml.Namespace; import org.apache.jackrabbit.webdav.xml.Namespace;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.*; import java.io.*;
@ -166,14 +164,6 @@ public class ExchangePropPatchMethod extends PostMethod {
return "PROPPATCH"; return "PROPPATCH";
} }
protected boolean isStartTag(XMLStreamReader reader, String tagLocalName) {
return (reader.getEventType() == XMLStreamConstants.START_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
}
protected boolean isEndTag(XMLStreamReader reader, String tagLocalName) {
return (reader.getEventType() == XMLStreamConstants.END_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
}
List<MultiStatusResponse> responses; List<MultiStatusResponse> responses;
@Override @Override
@ -183,8 +173,7 @@ public class ExchangePropPatchMethod extends PostMethod {
responses = new ArrayList<MultiStatusResponse>(); responses = new ArrayList<MultiStatusResponse>();
XMLStreamReader reader; XMLStreamReader reader;
try { try {
XMLInputFactory xmlInputFactory = XMLStreamUtil.getXmlInputFactory(); reader = XMLStreamUtil.createXMLStreamReader(new FilterInputStream(getResponseBodyAsStream()) {
reader = xmlInputFactory.createXMLStreamReader(new FilterInputStream(getResponseBodyAsStream()) {
final byte[] lastbytes = new byte[3]; final byte[] lastbytes = new byte[3];
@Override @Override
@ -206,8 +195,8 @@ public class ExchangePropPatchMethod extends PostMethod {
}); });
while (reader.hasNext()) { while (reader.hasNext()) {
reader.next(); reader.nextTag();
if (isStartTag(reader, "response")) { if (XMLStreamUtil.isStartTag(reader, "response")) {
handleResponse(reader); handleResponse(reader);
} }
} }
@ -223,9 +212,9 @@ public class ExchangePropPatchMethod extends PostMethod {
protected void handleResponse(XMLStreamReader reader) throws XMLStreamException { protected void handleResponse(XMLStreamReader reader) throws XMLStreamException {
String href = null; String href = null;
String responseStatus = ""; String responseStatus = "";
while (reader.hasNext() && !isEndTag(reader, "response")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "response")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("href".equals(tagLocalName)) { if ("href".equals(tagLocalName)) {
href = reader.getElementText(); href = reader.getElementText();
@ -243,9 +232,9 @@ public class ExchangePropPatchMethod extends PostMethod {
protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
int propstatStatus = 0; int propstatStatus = 0;
while (reader.hasNext() && !isEndTag(reader, "propstat")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("status".equals(tagLocalName)) { if ("status".equals(tagLocalName)) {
if ("HTTP/1.1 200 OK".equals(reader.getElementText())) { if ("HTTP/1.1 200 OK".equals(reader.getElementText())) {
@ -263,9 +252,9 @@ public class ExchangePropPatchMethod extends PostMethod {
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "prop")){ while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")){
int event = reader.nextTag(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI()); Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace)); multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace));

View File

@ -29,7 +29,6 @@ import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
@ -661,29 +660,17 @@ public abstract class EWSMethod extends PostMethod {
) { ) {
errorDetail = result; errorDetail = result;
} }
if (isStartTag(reader, "faultstring")) { if (XMLStreamUtil.isStartTag(reader, "faultstring")) {
errorDetail = reader.getElementText(); errorDetail = reader.getElementText();
} }
} }
protected boolean isStartTag(XMLStreamReader reader) {
return (reader.getEventType() == XMLStreamConstants.START_ELEMENT);
}
protected boolean isStartTag(XMLStreamReader reader, String tagLocalName) {
return (reader.getEventType() == XMLStreamConstants.START_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
}
protected boolean isEndTag(XMLStreamReader reader, String tagLocalName) {
return (reader.getEventType() == XMLStreamConstants.END_ELEMENT) && (reader.getLocalName().equals(tagLocalName));
}
protected Item handleItem(XMLStreamReader reader) throws XMLStreamException { protected Item handleItem(XMLStreamReader reader) throws XMLStreamException {
Item responseItem = new Item(); Item responseItem = new Item();
responseItem.type = reader.getLocalName(); responseItem.type = reader.getLocalName();
while (reader.hasNext() && !isEndTag(reader, responseItem.type)) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, responseItem.type)) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
String value = null; String value = null;
if ("ExtendedProperty".equals(tagLocalName)) { if ("ExtendedProperty".equals(tagLocalName)) {
@ -712,9 +699,9 @@ public abstract class EWSMethod extends PostMethod {
protected List<FileAttachment> handleAttachments(XMLStreamReader reader) throws XMLStreamException { protected List<FileAttachment> handleAttachments(XMLStreamReader reader) throws XMLStreamException {
List<FileAttachment> attachments = new ArrayList<FileAttachment>(); List<FileAttachment> attachments = new ArrayList<FileAttachment>();
while (reader.hasNext() && !(isEndTag(reader, "Attachments"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Attachments"))) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("FileAttachment".equals(tagLocalName)) { if ("FileAttachment".equals(tagLocalName)) {
attachments.add(handleFileAttachment(reader)); attachments.add(handleFileAttachment(reader));
@ -726,9 +713,9 @@ public abstract class EWSMethod extends PostMethod {
protected FileAttachment handleFileAttachment(XMLStreamReader reader) throws XMLStreamException { protected FileAttachment handleFileAttachment(XMLStreamReader reader) throws XMLStreamException {
FileAttachment fileAttachment = new FileAttachment(); FileAttachment fileAttachment = new FileAttachment();
while (reader.hasNext() && !(isEndTag(reader, "FileAttachment"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "FileAttachment"))) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("AttachmentId".equals(tagLocalName)) { if ("AttachmentId".equals(tagLocalName)) {
fileAttachment.attachmentId = getAttributeValue(reader, "Id"); fileAttachment.attachmentId = getAttributeValue(reader, "Id");
@ -751,9 +738,9 @@ public abstract class EWSMethod extends PostMethod {
protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException { protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException {
String propertyTag = null; String propertyTag = null;
String propertyValue = null; String propertyValue = null;
while (reader.hasNext() && !(isEndTag(reader, "ExtendedProperty"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "ExtendedProperty"))) {
reader.next(); reader.nextTag();
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("ExtendedFieldURI".equals(tagLocalName)) { if ("ExtendedFieldURI".equals(tagLocalName)) {
propertyTag = getAttributeValue(reader, "PropertyTag"); propertyTag = getAttributeValue(reader, "PropertyTag");
@ -768,9 +755,9 @@ public abstract class EWSMethod extends PostMethod {
propertyValue = reader.getElementText(); propertyValue = reader.getElementText();
} else if ("Values".equals(tagLocalName)) { } else if ("Values".equals(tagLocalName)) {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
while (reader.hasNext() && !(isEndTag(reader, "Values"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Values"))) {
reader.next(); reader.nextTag();
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
if (buffer.length() > 0) { if (buffer.length() > 0) {
buffer.append(','); buffer.append(',');
@ -819,19 +806,18 @@ public abstract class EWSMethod extends PostMethod {
responseItems = new ArrayList<Item>(); responseItems = new ArrayList<Item>();
XMLStreamReader reader; XMLStreamReader reader;
try { try {
XMLInputFactory xmlInputFactory = XMLStreamUtil.getXmlInputFactory(); reader = XMLStreamUtil.createXMLStreamReader(getResponseBodyAsStream());
reader = xmlInputFactory.createXMLStreamReader(getResponseBodyAsStream());
while (reader.hasNext()) { while (reader.hasNext()) {
reader.next(); reader.nextTag();
handleErrors(reader); handleErrors(reader);
if (serverVersion == null && isStartTag(reader, "ServerVersionInfo")) { if (serverVersion == null && XMLStreamUtil.isStartTag(reader, "ServerVersionInfo")) {
String majorVersion = getAttributeValue(reader, "MajorVersion"); String majorVersion = getAttributeValue(reader, "MajorVersion");
if ("14".equals(majorVersion)) { if ("14".equals(majorVersion)) {
serverVersion = "Exchange2010"; serverVersion = "Exchange2010";
} else { } else {
serverVersion = "Exchange2007_SP1"; serverVersion = "Exchange2007_SP1";
} }
} else if (isStartTag(reader, responseCollectionName)) { } else if (XMLStreamUtil.isStartTag(reader, responseCollectionName)) {
handleItems(reader); handleItems(reader);
} else { } else {
handleCustom(reader); handleCustom(reader);
@ -855,9 +841,9 @@ public abstract class EWSMethod extends PostMethod {
} }
private void handleItems(XMLStreamReader reader) throws XMLStreamException { private void handleItems(XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, responseCollectionName)) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, responseCollectionName)) {
reader.next(); reader.nextTag();
if (isStartTag(reader)) { if (XMLStreamUtil.isStartTag(reader)) {
responseItems.add(handleItem(reader)); responseItems.add(handleItem(reader));
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package davmail.exchange.ews; package davmail.exchange.ews;
import davmail.exchange.XMLStreamUtil;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.IOException; import java.io.IOException;
@ -97,7 +99,7 @@ public class GetUserAvailabilityMethod extends EWSMethod {
@Override @Override
protected void handleCustom(XMLStreamReader reader) throws XMLStreamException { protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
if (isStartTag(reader, "MergedFreeBusy")) { if (XMLStreamUtil.isStartTag(reader, "MergedFreeBusy")) {
this.mergedFreeBusy = reader.getElementText(); this.mergedFreeBusy = reader.getElementText();
} }
} }

View File

@ -18,7 +18,8 @@
*/ */
package davmail.exchange.ews; package davmail.exchange.ews;
import javax.xml.stream.XMLStreamConstants; import davmail.exchange.XMLStreamUtil;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.IOException; import java.io.IOException;
@ -48,16 +49,16 @@ public class GetUserConfigurationMethod extends EWSMethod {
@Override @Override
protected void handleCustom(XMLStreamReader reader) throws XMLStreamException { protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
if (isStartTag(reader, "UserConfiguration")) { if (XMLStreamUtil.isStartTag(reader, "UserConfiguration")) {
responseItems.add(handleUserConfiguration(reader)); responseItems.add(handleUserConfiguration(reader));
} }
} }
private Item handleUserConfiguration(XMLStreamReader reader) throws XMLStreamException { private Item handleUserConfiguration(XMLStreamReader reader) throws XMLStreamException {
Item responseItem = new Item(); Item responseItem = new Item();
while (reader.hasNext() && !(isEndTag(reader, "UserConfiguration"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "UserConfiguration"))) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("DictionaryEntry".equals(tagLocalName)) { if ("DictionaryEntry".equals(tagLocalName)) {
handleDictionaryEntry(reader, responseItem); handleDictionaryEntry(reader, responseItem);
@ -69,9 +70,9 @@ public class GetUserConfigurationMethod extends EWSMethod {
private void handleDictionaryEntry(XMLStreamReader reader, Item responseItem) throws XMLStreamException { private void handleDictionaryEntry(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
String key = null; String key = null;
while (reader.hasNext() && !(isEndTag(reader, "DictionaryEntry"))) { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "DictionaryEntry"))) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("Value".equals(tagLocalName)) { if ("Value".equals(tagLocalName)) {
if (key == null) { if (key == null) {

View File

@ -18,7 +18,8 @@
*/ */
package davmail.exchange.ews; package davmail.exchange.ews;
import javax.xml.stream.XMLStreamConstants; import davmail.exchange.XMLStreamUtil;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
@ -45,12 +46,12 @@ public class ResolveNamesMethod extends EWSMethod {
Item responseItem = new Item(); Item responseItem = new Item();
responseItem.type = "Contact"; responseItem.type = "Contact";
// skip to Contact // skip to Contact
while (reader.hasNext() && !isStartTag(reader, "Resolution")) { while (reader.hasNext() && !XMLStreamUtil.isStartTag(reader, "Resolution")) {
reader.next(); reader.nextTag();
} }
while (reader.hasNext() && !isEndTag(reader, "Resolution")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "Resolution")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("Mailbox".equals(tagLocalName)) { if ("Mailbox".equals(tagLocalName)) {
handleMailbox(reader, responseItem); handleMailbox(reader, responseItem);
@ -63,9 +64,9 @@ public class ResolveNamesMethod extends EWSMethod {
} }
protected void handleMailbox(XMLStreamReader reader, Item responseItem) throws XMLStreamException { protected void handleMailbox(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "Mailbox")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "Mailbox")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("Name".equals(tagLocalName)) { if ("Name".equals(tagLocalName)) {
responseItem.put(tagLocalName, reader.getElementText()); responseItem.put(tagLocalName, reader.getElementText());
@ -75,9 +76,9 @@ public class ResolveNamesMethod extends EWSMethod {
} }
protected void handleContact(XMLStreamReader reader, Item responseItem) throws XMLStreamException { protected void handleContact(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "Contact")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "Contact")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("EmailAddresses".equals(tagLocalName)) { if ("EmailAddresses".equals(tagLocalName)) {
handleEmailAddresses(reader, responseItem); handleEmailAddresses(reader, responseItem);
@ -93,9 +94,9 @@ public class ResolveNamesMethod extends EWSMethod {
} }
protected void handlePhysicalAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException { protected void handlePhysicalAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "PhysicalAddresses")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "PhysicalAddresses")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
// TODO // TODO
} }
@ -103,9 +104,9 @@ public class ResolveNamesMethod extends EWSMethod {
} }
protected void handlePhoneNumbers(XMLStreamReader reader, Item responseItem) throws XMLStreamException { protected void handlePhoneNumbers(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "PhoneNumbers")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "PhoneNumbers")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
// TODO // TODO
} }
@ -113,9 +114,9 @@ public class ResolveNamesMethod extends EWSMethod {
} }
protected void handleEmailAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException { protected void handleEmailAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
while (reader.hasNext() && !isEndTag(reader, "EmailAddresses")) { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "EmailAddresses")) {
int event = reader.next(); reader.nextTag();
if (event == XMLStreamConstants.START_ELEMENT) { if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if ("Entry".equals(tagLocalName)) { if ("Entry".equals(tagLocalName)) {
String key = getAttributeValue(reader, "Key"); String key = getAttributeValue(reader, "Key");