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.util.StringUtil;
22  
23  /**
24   * Indexed FieldURI
25   */
26  public class IndexedFieldURI implements FieldURI {
27      protected final String fieldURI;
28      protected final String fieldIndex;
29      protected final String fieldItemType;
30      protected final String collectionName;
31  
32      /**
33       * Create indexed field uri.
34       *
35       * @param fieldURI       base field uri
36       * @param fieldIndex     field name
37       * @param fieldItemType  field item type
38       * @param collectionName collection name
39       */
40      public IndexedFieldURI(String fieldURI, String fieldIndex, String fieldItemType, String collectionName) {
41          this.fieldURI = fieldURI;
42          this.fieldIndex = fieldIndex;
43          this.fieldItemType = fieldItemType;
44          this.collectionName = collectionName;
45      }
46  
47      public void appendTo(StringBuilder buffer) {
48          buffer.append("<t:IndexedFieldURI FieldURI=\"").append(fieldURI);
49          buffer.append("\" FieldIndex=\"").append(fieldIndex);
50          buffer.append("\"/>");
51      }
52  
53      public void appendValue(StringBuilder buffer, String itemType, String value) {
54          if (itemType != null) {
55              // append IndexedFieldURI
56              appendTo(buffer);
57              buffer.append("<t:").append(fieldItemType).append('>');
58              buffer.append("<t:").append(collectionName).append('>');
59          }
60          if (value != null && value.length() > 0) {
61              buffer.append("<t:Entry Key=\"").append(fieldIndex).append("\">");
62              buffer.append(StringUtil.xmlEncodeAttribute(value));
63              buffer.append("</t:Entry>");
64          }
65          if (itemType != null) {
66              buffer.append("</t:").append(collectionName).append('>');
67              buffer.append("</t:").append(fieldItemType).append('>');
68          }
69      }
70  
71      public String getResponseName() {
72          return fieldIndex;
73      }
74  }