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      protected String graphId;
33  
34      /**
35       * Create indexed field uri.
36       *
37       * @param fieldURI       base field uri
38       * @param fieldIndex     field name
39       * @param fieldItemType  field item type
40       * @param collectionName collection name
41       */
42      public IndexedFieldURI(String fieldURI, String fieldIndex, String fieldItemType, String collectionName) {
43          this.fieldURI = fieldURI;
44          this.fieldIndex = fieldIndex;
45          this.fieldItemType = fieldItemType;
46          this.collectionName = collectionName;
47      }
48  
49      public IndexedFieldURI(String fieldURI, String fieldIndex, String fieldItemType, String collectionName, String graphId) {
50          this(fieldURI, fieldIndex, fieldItemType, collectionName);
51          this.graphId = graphId;
52      }
53  
54      public void appendTo(StringBuilder buffer) {
55          buffer.append("<t:IndexedFieldURI FieldURI=\"").append(fieldURI);
56          buffer.append("\" FieldIndex=\"").append(fieldIndex);
57          buffer.append("\"/>");
58      }
59  
60      public void appendValue(StringBuilder buffer, String itemType, String value) {
61          if (itemType != null) {
62              // append IndexedFieldURI
63              appendTo(buffer);
64              buffer.append("<t:").append(fieldItemType).append('>');
65              buffer.append("<t:").append(collectionName).append('>');
66          }
67          if (value != null && value.length() > 0) {
68              buffer.append("<t:Entry Key=\"").append(fieldIndex).append("\">");
69              buffer.append(StringUtil.xmlEncodeAttribute(value));
70              buffer.append("</t:Entry>");
71          }
72          if (itemType != null) {
73              buffer.append("</t:").append(collectionName).append('>');
74              buffer.append("</t:").append(fieldItemType).append('>');
75          }
76      }
77  
78      public String getResponseName() {
79          return fieldIndex;
80      }
81  
82      @Override
83      public String getGraphId() {
84          return graphId;
85      }
86  
87      @Override
88      public boolean isMultiValued() {
89          return true;
90      }
91  
92      @Override
93      public boolean isNumber() {
94          // TODO
95          throw new UnsupportedOperationException();
96      }
97  
98      @Override
99      public boolean isBoolean() {
100         throw new UnsupportedOperationException();
101     }
102 }