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 java.io.IOException;
22  import java.io.Writer;
23  
24  /**
25   * Folder Id.
26   */
27  public class FolderId extends Option {
28      protected String changeKey;
29      protected String mailbox;
30  
31      /**
32       * Create FolderId with specified tag name.
33       *
34       * @param name      field tag name
35       * @param value     id value
36       * @param changeKey folder change key
37       * @param mailbox   shared mailbox name
38       */
39      protected FolderId(String name, String value, String changeKey, String mailbox) {
40          this(name, value, changeKey);
41          this.mailbox = mailbox;
42      }
43  
44      /**
45       * Create FolderId with specified tag name.
46       *
47       * @param name      field tag name
48       * @param value     id value
49       * @param changeKey folder change key
50       */
51      protected FolderId(String name, String value, String changeKey) {
52          super(name, value);
53          this.changeKey = changeKey;
54      }
55  
56      /**
57       * Build Folder id from response item.
58       *
59       * @param item    response item
60       */
61      public FolderId(EWSMethod.Item item) {
62          this("t:FolderId", item.get("FolderId"), item.get("ChangeKey"));
63      }
64  
65  
66      /**
67       * @inheritDoc
68       */
69      @Override
70      public void write(Writer writer) throws IOException {
71          writer.write('<');
72          writer.write(name);
73          writer.write(" Id=\"");
74          writer.write(value);
75          if (changeKey != null) {
76              writer.write("\" ChangeKey=\"");
77              writer.write(changeKey);
78          }
79          if (mailbox == null) {
80              writer.write("\"/>");
81          } else {
82              writer.write("\"><t:Mailbox><t:EmailAddress>");
83              writer.write(mailbox);
84              writer.write("</t:EmailAddress></t:Mailbox></");
85              writer.write(name);
86              writer.write('>');
87          }
88      }
89  
90  }