View Javadoc
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  package davmail.exchange.ews;
20  
21  import davmail.exchange.XMLStreamUtil;
22  
23  import javax.xml.stream.XMLStreamException;
24  import javax.xml.stream.XMLStreamReader;
25  import java.io.IOException;
26  import java.io.Writer;
27  
28  /**
29   * Get User Configuration method.
30   */
31  public class GetUserConfigurationMethod extends EWSMethod {
32  
33      /**
34       * Get User Configuration method.
35       */
36      public GetUserConfigurationMethod() {
37          super("UserConfiguration", "GetUserConfiguration");
38          folderId = DistinguishedFolderId.getInstance(null, DistinguishedFolderId.Name.root);
39      }
40  
41      @Override
42      protected void writeSoapBody(Writer writer) throws IOException {
43          writer.write("<m:UserConfigurationName Name=\"OWA.UserOptions\">");
44          folderId.write(writer);
45          writer.write("</m:UserConfigurationName>");
46          writer.write("<m:UserConfigurationProperties>All</m:UserConfigurationProperties>");
47      }
48  
49      @Override
50      protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
51          if (XMLStreamUtil.isStartTag(reader, "UserConfiguration")) {
52              responseItems.add(handleUserConfiguration(reader));
53          }
54      }
55  
56      private Item handleUserConfiguration(XMLStreamReader reader) throws XMLStreamException {
57          Item responseItem = new Item();
58          while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "UserConfiguration"))) {
59              reader.next();
60              if (XMLStreamUtil.isStartTag(reader)) {
61                  String tagLocalName = reader.getLocalName();
62                  if ("DictionaryEntry".equals(tagLocalName)) {
63                      handleDictionaryEntry(reader, responseItem);
64                  }
65              }
66          }
67          return responseItem;
68      }
69  
70      private void handleDictionaryEntry(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
71          String key = null;
72          while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "DictionaryEntry"))) {
73              reader.next();
74              if (XMLStreamUtil.isStartTag(reader)) {
75                  String tagLocalName = reader.getLocalName();
76                  if ("Value".equals(tagLocalName)) {
77                      if (key == null) {
78                          key = reader.getElementText();
79                      } else {
80                          responseItem.put(key, XMLStreamUtil.getElementText(reader));
81                      }
82                  }
83              }
84          }
85      }
86  
87  }