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(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType, String graphId) {
114 this.distinguishedPropertySetId = distinguishedPropertySetId;
115 this.propertyName = propertyName;
116 this.propertyType = propertyType;
117 this.graphId = graphId;
118 }
119
120 public ExtendedFieldURI(int intPropertyTag, PropertyType propertyType, String graphId) {
121 this(intPropertyTag, propertyType);
122 this.graphId = graphId;
123 }
124
125 public void appendTo(StringBuilder buffer) {
126 buffer.append("<t:ExtendedFieldURI");
127 if (propertyTag != null) {
128 buffer.append(" PropertyTag=\"").append(propertyTag).append('"');
129 }
130 if (distinguishedPropertySetId != null) {
131 buffer.append(" DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append('"');
132 }
133 if (propertyName != null) {
134 buffer.append(" PropertyName=\"").append(propertyName).append('"');
135 }
136 if (propertyId != 0) {
137 buffer.append(" PropertyId=\"").append(propertyId).append('"');
138 }
139 if (propertyType != null) {
140 buffer.append(" PropertyType=\"").append(propertyType.toString()).append('"');
141 }
142 buffer.append("/>");
143 }
144
145 public void appendValue(StringBuilder buffer, String itemType, String value) {
146 if (itemType != null) {
147 appendTo(buffer);
148 buffer.append("<t:");
149 buffer.append(itemType);
150 buffer.append('>');
151 }
152 buffer.append("<t:ExtendedProperty>");
153 appendTo(buffer);
154 if (propertyType == PropertyType.StringArray) {
155 buffer.append("<t:Values>");
156 String[] values = value.split(",");
157 for (final String singleValue : values) {
158 buffer.append("<t:Value>");
159 buffer.append(StringUtil.xmlEncode(singleValue));
160 buffer.append("</t:Value>");
161
162 }
163 buffer.append("</t:Values>");
164 } else {
165 buffer.append("<t:Value>");
166 if ("0x10f3".equals(propertyTag)) {
167 buffer.append(StringUtil.xmlEncode(StringUtil.encodeUrlcompname(value)));
168 } else {
169 buffer.append(StringUtil.xmlEncode(value));
170 }
171 buffer.append("</t:Value>");
172 }
173 buffer.append("</t:ExtendedProperty>");
174 if (itemType != null) {
175 buffer.append("</t:");
176 buffer.append(itemType);
177 buffer.append('>');
178 }
179 }
180
181
182
183
184
185
186 public String getResponseName() {
187 if (propertyTag != null) {
188 return propertyTag;
189 } else if (propertyName != null) {
190 return propertyName;
191 } else {
192 return String.valueOf(propertyId);
193 }
194 }
195
196 @Override
197 public String getGraphId() {
198 if (graphId != null) {
199 return graphId;
200 }
201
202
203
204 String namespaceGuid = null;
205
206 if (distinguishedPropertySetId == DistinguishedPropertySetType.PublicStrings) {
207 namespaceGuid = "{00020329-0000-0000-c000-000000000046}";
208 }
209 if (distinguishedPropertySetId == DistinguishedPropertySetType.InternetHeaders) {
210 namespaceGuid = "{00020386-0000-0000-c000-000000000046}";
211 }
212 if (distinguishedPropertySetId == DistinguishedPropertySetType.Common) {
213 namespaceGuid = "{00062008-0000-0000-c000-000000000046}";
214 }
215 if (distinguishedPropertySetId == DistinguishedPropertySetType.Address) {
216 namespaceGuid = "{00062004-0000-0000-c000-000000000046}";
217 }
218 if (distinguishedPropertySetId == DistinguishedPropertySetType.Task) {
219 namespaceGuid = "{00062003-0000-0000-c000-000000000046}";
220 }
221
222 StringBuilder buffer = new StringBuilder();
223 if (namespaceGuid != null) {
224 buffer.append(propertyType.name()).append(" ").append(namespaceGuid);
225 if (propertyName != null) {
226 buffer.append(" Name ").append(propertyName);
227 } else {
228 buffer.append(" Id ").append("0x").append(Integer.toHexString(propertyId));
229 }
230 } else if (propertyTag != null) {
231 buffer.append(propertyType.name()).append(" ").append(propertyTag);
232 } else {
233 throw new IllegalStateException("Unsupported graph property for graph " + getResponseName());
234 }
235 return buffer.toString();
236 }
237
238 @Override
239 public boolean isMultiValued() {
240 return propertyType == PropertyType.StringArray;
241 }
242
243 public boolean isNumber() {
244 return propertyType == PropertyType.Short || propertyType == PropertyType.Integer || propertyType == PropertyType.Long || propertyType == PropertyType.Double;
245 }
246
247 public boolean isBinary() {
248 return propertyType == PropertyType.Binary;
249 }
250
251 @Override
252 public boolean isBoolean() {
253 return propertyType == PropertyType.Boolean;
254 }
255
256 }
257