1 /*
2 * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3 * Copyright (C) 2010 Mickael Guessant
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 package davmail.exchange.ews;
21
22 import davmail.exchange.XMLStreamUtil;
23
24 import javax.xml.stream.XMLStreamException;
25 import javax.xml.stream.XMLStreamReader;
26
27 /**
28 * ConvertId implementation to retrieve primary mailbox address
29 */
30 public class ConvertIdMethod extends EWSMethod {
31
32 /**
33 * Build Resolve Names method
34 *
35 * @param value search value
36 */
37 public ConvertIdMethod(String value) {
38 super("SourceIds", "ConvertId", "ResponseMessages");
39 addMethodOption(new AttributeOption("DestinationFormat", "EwsId"));
40 unresolvedEntry = new ElementOption("m:SourceIds",
41 new AlternateId("EwsId", value));
42 }
43
44 @Override
45 protected Item handleItem(XMLStreamReader reader) throws XMLStreamException {
46 Item responseItem = new Item();
47 responseItem.type = "AlternateId";
48 // skip to AlternateId
49 while (reader.hasNext() && !XMLStreamUtil.isStartTag(reader, "AlternateId")) {
50 reader.next();
51 }
52 if (XMLStreamUtil.isStartTag(reader, "AlternateId")) {
53 String mailbox = reader.getAttributeValue(null, "Mailbox");
54 if (mailbox != null) {
55 responseItem.put("Mailbox", mailbox);
56 }
57 while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "AlternateId")) {
58 reader.next();
59 }
60 }
61 return responseItem;
62 }
63
64 }