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.XMLStreamReader;
24  import java.io.IOException;
25  import java.io.Writer;
26  
27  /**
28   * GetUserAvailability method.
29   */
30  public class GetUserAvailabilityMethod extends EWSMethod {
31      protected final String attendee;
32      protected final String start;
33      protected final String end;
34      protected String mergedFreeBusy;
35      protected final int interval;
36  
37      /**
38       * Build EWS method
39       *
40       * @param attendee attendee email address
41       * @param start    start date in Exchange zulu format
42       * @param end      end date in Exchange zulu format
43       * @param interval freebusy interval in minutes
44       */
45      public GetUserAvailabilityMethod(String attendee, String start, String end, int interval) {
46          super("FreeBusy", "GetUserAvailabilityRequest");
47          this.attendee = attendee;
48          this.start = start;
49          this.end = end;
50          this.interval = interval;
51      }
52  
53      @Override
54      protected void writeSoapBody(Writer writer) throws IOException {
55          // write UTC timezone
56          writer.write("<t:TimeZone>" +
57                  "<t:Bias>0</t:Bias>" +
58                  "<t:StandardTime>" +
59                  "<t:Bias>0</t:Bias>" +
60                  "<t:Time>02:00:00</t:Time>" +
61                  "<t:DayOrder>1</t:DayOrder>" +
62                  "<t:Month>3</t:Month>" +
63                  "<t:DayOfWeek>Sunday</t:DayOfWeek>" +
64                  "</t:StandardTime>" +
65                  "<t:DaylightTime>" +
66                  "<t:Bias>0</t:Bias>" +
67                  "<t:Time>02:00:00</t:Time>" +
68                  "<t:DayOrder>1</t:DayOrder>" +
69                  "<t:Month>10</t:Month>" +
70                  "<t:DayOfWeek>Sunday</t:DayOfWeek>" +
71                  "</t:DaylightTime>" +
72                  "</t:TimeZone>");
73          // write attendee address
74          writer.write("<m:MailboxDataArray>" +
75                  "<t:MailboxData>" +
76                  "<t:Email>" +
77                  "<t:Address>");
78          writer.write(attendee);
79          writer.write("</t:Address>" +
80                  "</t:Email>" +
81                  "<t:AttendeeType>Required</t:AttendeeType>" +
82                  "</t:MailboxData>" +
83                  "</m:MailboxDataArray>");
84          // freebusy range
85          writer.write("<t:FreeBusyViewOptions>" +
86                  "<t:TimeWindow>" +
87                  "<t:StartTime>");
88          writer.write(start);
89          writer.write("</t:StartTime>" +
90                  "<t:EndTime>");
91          writer.write(end);
92          writer.write("</t:EndTime>" +
93                  "</t:TimeWindow>" +
94                  "<t:MergedFreeBusyIntervalInMinutes>" + interval + "</t:MergedFreeBusyIntervalInMinutes>" +
95                  "<t:RequestedView>MergedOnly</t:RequestedView>" +
96                  "</t:FreeBusyViewOptions>");
97      }
98  
99      @Override
100     protected void handleCustom(XMLStreamReader reader) {
101         if (XMLStreamUtil.isStartTag(reader, "MergedFreeBusy")) {
102             this.mergedFreeBusy = XMLStreamUtil.getElementText(reader);
103         }
104     }
105 
106     /**
107      * Get merged freebusy string.
108      *
109      * @return freebusy string
110      */
111     public String getMergedFreeBusy() {
112         return mergedFreeBusy;
113     }
114 }