1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.exchange.ews;
20
21 import davmail.util.StringUtil;
22
23
24
25
26 public class ExtendedFieldURI implements FieldURI {
27
28 @SuppressWarnings({"UnusedDeclaration"})
29 protected enum PropertyType {
30 ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray,
31 Double, DoubleArray, Error, Float, FloatArray, Integer, IntegerArray, Long, LongArray, Null, Object,
32 ObjectArray, Short, ShortArray, SystemTime, SystemTimeArray, String, StringArray
33 }
34
35 @SuppressWarnings({"UnusedDeclaration"})
36 public enum DistinguishedPropertySetType {
37 Meeting, Appointment, Common, PublicStrings, Address, InternetHeaders, CalendarAssistant, UnifiedMessaging, Task
38 }
39
40
41 protected String propertyTag;
42 protected DistinguishedPropertySetType distinguishedPropertySetId;
43 protected String propertyName;
44 protected int propertyId;
45 protected final PropertyType propertyType;
46
47 private String graphId;
48
49
50
51
52
53
54
55 public ExtendedFieldURI(int intPropertyTag, PropertyType propertyType) {
56 this.propertyTag = "0x" + Integer.toHexString(intPropertyTag);
57 this.propertyType = propertyType;
58 }
59
60
61
62
63
64
65
66
67 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, int propertyId, PropertyType propertyType) {
68 this.distinguishedPropertySetId = distinguishedPropertySetId;
69 this.propertyId = propertyId;
70 this.propertyType = propertyType;
71 }
72
73
74
75
76
77
78
79
80
81 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, int propertyId, PropertyType propertyType, String graphId) {
82 this.distinguishedPropertySetId = distinguishedPropertySetId;
83 this.propertyId = propertyId;
84 this.propertyType = propertyType;
85 this.graphId = graphId;
86 }
87
88
89
90
91
92
93
94 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName) {
95 this.distinguishedPropertySetId = distinguishedPropertySetId;
96 this.propertyName = propertyName;
97 this.propertyType = PropertyType.String;
98 }
99
100
101
102
103
104
105
106
107 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType) {
108 this.distinguishedPropertySetId = distinguishedPropertySetId;
109 this.propertyName = propertyName;
110 this.propertyType = propertyType;
111 }
112
113 public ExtendedFieldURI(int intPropertyTag, PropertyType propertyType, String graphId) {
114 this(intPropertyTag, propertyType);
115 this.graphId = graphId;
116 }
117
118 public void appendTo(StringBuilder buffer) {
119 buffer.append("<t:ExtendedFieldURI");
120 if (propertyTag != null) {
121 buffer.append(" PropertyTag=\"").append(propertyTag).append('"');
122 }
123 if (distinguishedPropertySetId != null) {
124 buffer.append(" DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append('"');
125 }
126 if (propertyName != null) {
127 buffer.append(" PropertyName=\"").append(propertyName).append('"');
128 }
129 if (propertyId != 0) {
130 buffer.append(" PropertyId=\"").append(propertyId).append('"');
131 }
132 if (propertyType != null) {
133 buffer.append(" PropertyType=\"").append(propertyType.toString()).append('"');
134 }
135 buffer.append("/>");
136 }
137
138 public void appendValue(StringBuilder buffer, String itemType, String value) {
139 if (itemType != null) {
140 appendTo(buffer);
141 buffer.append("<t:");
142 buffer.append(itemType);
143 buffer.append('>');
144 }
145 buffer.append("<t:ExtendedProperty>");
146 appendTo(buffer);
147 if (propertyType == PropertyType.StringArray) {
148 buffer.append("<t:Values>");
149 String[] values = value.split(",");
150 for (final String singleValue : values) {
151 buffer.append("<t:Value>");
152 buffer.append(StringUtil.xmlEncode(singleValue));
153 buffer.append("</t:Value>");
154
155 }
156 buffer.append("</t:Values>");
157 } else {
158 buffer.append("<t:Value>");
159 if ("0x10f3".equals(propertyTag)) {
160 buffer.append(StringUtil.xmlEncode(StringUtil.encodeUrlcompname(value)));
161 } else {
162 buffer.append(StringUtil.xmlEncode(value));
163 }
164 buffer.append("</t:Value>");
165 }
166 buffer.append("</t:ExtendedProperty>");
167 if (itemType != null) {
168 buffer.append("</t:");
169 buffer.append(itemType);
170 buffer.append('>');
171 }
172 }
173
174
175
176
177
178
179 public String getResponseName() {
180 if (propertyTag != null) {
181 return propertyTag;
182 } else if (propertyName != null) {
183 return propertyName;
184 } else {
185 return String.valueOf(propertyId);
186 }
187 }
188
189 @Override
190 public String getGraphId() {
191 if (graphId != null) {
192 return graphId;
193 }
194
195
196
197 String namespaceGuid = null;
198
199 if (distinguishedPropertySetId == DistinguishedPropertySetType.PublicStrings) {
200 namespaceGuid = "{00020329-0000-0000-c000-000000000046}";
201 }
202 if (distinguishedPropertySetId == DistinguishedPropertySetType.InternetHeaders) {
203 namespaceGuid = "{00020386-0000-0000-c000-000000000046}";
204 }
205 if (distinguishedPropertySetId == DistinguishedPropertySetType.Common) {
206 namespaceGuid = "{00062008-0000-0000-c000-000000000046}";
207 }
208 if (distinguishedPropertySetId == DistinguishedPropertySetType.Address) {
209 namespaceGuid = "{00062004-0000-0000-c000-000000000046}";
210 }
211 if (distinguishedPropertySetId == DistinguishedPropertySetType.Task) {
212 namespaceGuid = "{00062003-0000-0000-c000-000000000046}";
213 }
214
215 StringBuilder buffer = new StringBuilder();
216 if (namespaceGuid != null) {
217 buffer.append(propertyType.name()).append(" ").append(namespaceGuid);
218 if (propertyName != null) {
219 buffer.append(" Name ").append(propertyName);
220 } else {
221 buffer.append(" Id ").append("0x").append(Integer.toHexString(propertyId));
222 }
223 } else if (propertyTag != null) {
224 buffer.append(propertyType.name()).append(" ").append(propertyTag);
225 } else {
226 throw new IllegalStateException("Unsupported graph property for graph " + getResponseName());
227 }
228 return buffer.toString();
229 }
230
231 @Override
232 public boolean isMultiValued() {
233 return propertyType == PropertyType.StringArray;
234 }
235
236 public boolean isNumber() {
237 return propertyType == PropertyType.Short || propertyType == PropertyType.Integer || propertyType == PropertyType.Long || propertyType == PropertyType.Double;
238 }
239
240 @Override
241 public boolean isBoolean() {
242 return propertyType == PropertyType.Boolean;
243 }
244
245 }
246