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  
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  import java.io.IOException;
27  import java.io.Writer;
28  
29  public class GetUserPhotoMethod extends EWSMethod  {
30      public enum SizeRequested {
31          HR48x48, HR64x64, HR96x96, HR120x120, HR240x240, HR360x360,
32          HR432x432, HR504x504, HR648x648
33      }
34  
35      protected String email;
36      protected SizeRequested sizeRequested;
37  
38      protected String contentType = null;
39      protected String pictureData = null;
40  
41      /**
42       * Get User Configuration method.
43       */
44      public GetUserPhotoMethod(String email, SizeRequested sizeRequested) {
45          super("GetUserPhoto", "GetUserPhoto");
46          this.email = email;
47          this.sizeRequested = sizeRequested;
48      }
49  
50      @Override
51      protected void writeSoapBody(Writer writer) throws IOException {
52          writer.write("<m:Email>");
53          writer.write(email);
54          writer.write("</m:Email>");
55  
56          writer.write("<m:SizeRequested>");
57          writer.write(sizeRequested.toString());
58          writer.write("</m:SizeRequested>");
59  
60      }
61  
62      @Override
63      protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
64          if (XMLStreamUtil.isStartTag(reader, "PictureData")) {
65              pictureData = reader.getElementText();
66              if (pictureData.isEmpty()) {
67                  pictureData = null;
68              }
69          }
70          if (XMLStreamUtil.isStartTag(reader, "ContentType")) {
71              contentType = reader.getElementText();
72          }
73  
74      }
75  
76      public String getContentType() {
77          return contentType;
78      }
79  
80      public String getPictureData() {
81          return pictureData;
82      }
83  }