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.Serializable;
23  import java.io.Writer;
24  
25  /**
26   * Item id.
27   */
28  public class ItemId implements Serializable {
29      protected final String name;
30      protected final String id;
31      protected final String changeKey;
32  
33      /**
34       * Build Item id from response item.
35       *
36       * @param item response item
37       */
38      public ItemId(EWSMethod.Item item) {
39          this("ItemId", item);
40      }
41  
42      /**
43       * Build Item id object from item id.
44       *
45       * @param itemId item id
46       */
47      public ItemId(String itemId) {
48          this("ItemId", itemId);
49      }
50  
51      /**
52       * Build Item id from response item.
53       *
54       * @param name item name
55       * @param item response item
56       */
57      public ItemId(String name, EWSMethod.Item item) {
58          this.name = name;
59          this.id = item.get("ItemId");
60          this.changeKey = item.get("ChangeKey");
61      }
62  
63      /**
64       * Build Item id object from item id.
65       *
66       * @param name item name
67       * @param itemId item id
68       */
69      public ItemId(String name, String itemId) {
70          this.name = name;
71          this.id = itemId;
72          this.changeKey = null;
73      }
74  
75      /**
76       * Build Item id object from item id and change key.
77       *
78       * @param name item name
79       * @param itemId item id
80       * @param changeKey change key
81       */
82      public ItemId(String name, String itemId, String changeKey) {
83          this.name = name;
84          this.id = itemId;
85          this.changeKey = changeKey;
86      }
87  
88      /**
89       * Write item id as XML.
90       *
91       * @param writer request writer
92       * @throws IOException on error
93       */
94      public void write(Writer writer) throws IOException {
95          writer.write("<t:");
96          writer.write(name);
97          writer.write(" Id=\"");
98          writer.write(id);
99          if (changeKey != null) {
100             writer.write("\" ChangeKey=\"");
101             writer.write(changeKey);
102         }
103         writer.write("\"/>");
104     }
105 }