1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.exchange.dav;
20
21 import davmail.Settings;
22 import davmail.util.StringUtil;
23 import org.apache.jackrabbit.webdav.property.DavPropertyName;
24 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
25 import org.apache.jackrabbit.webdav.property.PropEntry;
26 import org.apache.jackrabbit.webdav.xml.DomUtil;
27 import org.apache.jackrabbit.webdav.xml.Namespace;
28 import org.apache.jackrabbit.webdav.xml.XmlSerializable;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38 public class Field {
39
40 protected static final Map<DistinguishedPropertySetType, String> distinguishedPropertySetMap = new HashMap<>();
41
42 static {
43 distinguishedPropertySetMap.put(DistinguishedPropertySetType.Meeting, "6ed8da90-450b-101b-98da-00aa003f1305");
44 distinguishedPropertySetMap.put(DistinguishedPropertySetType.Appointment, "00062002-0000-0000-c000-000000000046");
45 distinguishedPropertySetMap.put(DistinguishedPropertySetType.Common, "00062008-0000-0000-c000-000000000046");
46 distinguishedPropertySetMap.put(DistinguishedPropertySetType.PublicStrings, "00020329-0000-0000-c000-000000000046");
47 distinguishedPropertySetMap.put(DistinguishedPropertySetType.Address, "00062004-0000-0000-c000-000000000046");
48 distinguishedPropertySetMap.put(DistinguishedPropertySetType.InternetHeaders, "00020386-0000-0000-c000-000000000046");
49 distinguishedPropertySetMap.put(DistinguishedPropertySetType.UnifiedMessaging, "4442858e-a9e3-4e80-b900-317a210cc15b");
50 distinguishedPropertySetMap.put(DistinguishedPropertySetType.Task, "00062003-0000-0000-c000-000000000046");
51 }
52
53 protected static final Namespace EMPTY = Namespace.getNamespace("");
54 protected static final Namespace XML = Namespace.getNamespace("xml:");
55 protected static final Namespace DAV = Namespace.getNamespace("DAV:");
56 protected static final Namespace URN_SCHEMAS_HTTPMAIL = Namespace.getNamespace("urn:schemas:httpmail:");
57 protected static final Namespace URN_SCHEMAS_MAILHEADER = Namespace.getNamespace("urn:schemas:mailheader:");
58
59 protected static final Namespace SCHEMAS_EXCHANGE = Namespace.getNamespace("http://schemas.microsoft.com/exchange/");
60 protected static final Namespace SCHEMAS_MAPI = Namespace.getNamespace("http://schemas.microsoft.com/mapi/");
61 protected static final Namespace SCHEMAS_MAPI_PROPTAG = Namespace.getNamespace("http://schemas.microsoft.com/mapi/proptag/");
62 protected static final Namespace SCHEMAS_MAPI_ID = Namespace.getNamespace("http://schemas.microsoft.com/mapi/id/");
63 protected static final Namespace SCHEMAS_MAPI_STRING = Namespace.getNamespace("http://schemas.microsoft.com/mapi/string/");
64 protected static final Namespace SCHEMAS_REPL = Namespace.getNamespace("http://schemas.microsoft.com/repl/");
65 protected static final Namespace URN_SCHEMAS_CONTACTS = Namespace.getNamespace("urn:schemas:contacts:");
66 protected static final Namespace URN_SCHEMAS_CALENDAR = Namespace.getNamespace("urn:schemas:calendar:");
67
68 protected static final Namespace SCHEMAS_MAPI_STRING_INTERNET_HEADERS =
69 Namespace.getNamespace(SCHEMAS_MAPI_STRING.getURI() +
70 '{' + distinguishedPropertySetMap.get(DistinguishedPropertySetType.InternetHeaders) + "}/");
71
72 protected static final Map<PropertyType, String> propertyTypeMap = new HashMap<>();
73
74 static {
75 propertyTypeMap.put(PropertyType.Integer, "0003");
76 propertyTypeMap.put(PropertyType.Boolean, "000b");
77 propertyTypeMap.put(PropertyType.SystemTime, "0040");
78 propertyTypeMap.put(PropertyType.String, "001f");
79 propertyTypeMap.put(PropertyType.Binary, "0102");
80 propertyTypeMap.put(PropertyType.Double, "0005");
81 }
82
83 @SuppressWarnings({"UnusedDeclaration"})
84 protected enum DistinguishedPropertySetType {
85 Meeting, Appointment, Common, PublicStrings, Address, InternetHeaders, CalendarAssistant, UnifiedMessaging, Task
86 }
87
88
89 protected static final Map<String, Field> fieldMap = new HashMap<>();
90
91 static {
92
93 createField(URN_SCHEMAS_HTTPMAIL, "inbox");
94 createField(URN_SCHEMAS_HTTPMAIL, "deleteditems");
95 createField(URN_SCHEMAS_HTTPMAIL, "sentitems");
96 createField(URN_SCHEMAS_HTTPMAIL, "sendmsg");
97 createField(URN_SCHEMAS_HTTPMAIL, "drafts");
98 createField(URN_SCHEMAS_HTTPMAIL, "calendar");
99 createField(URN_SCHEMAS_HTTPMAIL, "tasks");
100 createField(URN_SCHEMAS_HTTPMAIL, "contacts");
101 createField(URN_SCHEMAS_HTTPMAIL, "outbox");
102
103
104
105 createField("folderclass", SCHEMAS_EXCHANGE, "outlookfolderclass");
106 createField(DAV, "hassubs");
107 createField(DAV, "nosubs");
108 createField("count", DAV, "objectcount");
109 createField(URN_SCHEMAS_HTTPMAIL, "unreadcount");
110 createField(SCHEMAS_REPL, "contenttag");
111
112 createField("uidNext", 0x6751, PropertyType.Integer);
113 createField("highestUid", 0x6752, PropertyType.Integer);
114
115 createField(DAV, "isfolder");
116
117
118 createField(DAV, "uid");
119
120
121 createField("messageSize", 0x0e08, PropertyType.Integer);
122 createField("imapUid", 0x0e23, PropertyType.Integer);
123 createField("junk", 0x1083, PropertyType.Integer);
124 createField("flagStatus", 0x1090, PropertyType.Integer);
125 createField("messageFlags", 0x0e07, PropertyType.Integer);
126 createField("lastVerbExecuted", 0x1081, PropertyType.Integer);
127 createField("iconIndex", 0x1080, PropertyType.Integer);
128 createField(URN_SCHEMAS_HTTPMAIL, "read");
129
130
131 if (Settings.getBooleanProperty("davmail.popCommonDeleted", true)) {
132
133 createField("deleted", DistinguishedPropertySetType.Common, 0x8570, "deleted", PropertyType.String);
134 } else {
135 createField("deleted", DistinguishedPropertySetType.PublicStrings);
136 }
137
138
139 createField("date", 0x0e06, PropertyType.SystemTime);
140 createField(URN_SCHEMAS_MAILHEADER, "bcc");
141 createField(URN_SCHEMAS_HTTPMAIL, "datereceived");
142
143
144 createField("messageFormat", 0x5909, PropertyType.Integer);
145 createField("mailOverrideFormat", 0x5902, PropertyType.Integer);
146
147
148
149 createField(URN_SCHEMAS_HTTPMAIL, "subject");
150
151 createField("body", 0x1000, PropertyType.String);
152 createField("messageheaders", 0x007D, PropertyType.String);
153 createField(URN_SCHEMAS_HTTPMAIL, "from");
154
155 createField(URN_SCHEMAS_MAILHEADER, "to");
156 createField(URN_SCHEMAS_MAILHEADER, "cc");
157 createField(URN_SCHEMAS_MAILHEADER, "message-id");
158 createField(URN_SCHEMAS_MAILHEADER, "htmldescription");
159
160 createField("lastmodified", DAV, "getlastmodified");
161
162
163 createField(DAV, "displayname");
164 createField("urlcompname", 0x10f3, PropertyType.String);
165
166
167 createField("etag", DAV, "getetag");
168
169
170 createField(SCHEMAS_EXCHANGE, "permanenturl");
171 createField(URN_SCHEMAS_CALENDAR, "instancetype");
172 createField(URN_SCHEMAS_CALENDAR, "dtstart");
173 createField(URN_SCHEMAS_CALENDAR, "dtend");
174
175
176 createField("calendarversion", URN_SCHEMAS_CALENDAR, "version");
177 createField(URN_SCHEMAS_CALENDAR, "method");
178
179 createField("calendarlastmodified", URN_SCHEMAS_CALENDAR, "lastmodified");
180 createField(URN_SCHEMAS_CALENDAR, "dtstamp");
181 createField("calendaruid", URN_SCHEMAS_CALENDAR, "uid");
182 createField(URN_SCHEMAS_CALENDAR, "transparent");
183
184 createField(URN_SCHEMAS_CALENDAR, "organizer");
185 createField(URN_SCHEMAS_CALENDAR, "created");
186 createField(URN_SCHEMAS_CALENDAR, "alldayevent");
187
188 createField(URN_SCHEMAS_CALENDAR, "rrule");
189 createField(URN_SCHEMAS_CALENDAR, "exdate");
190
191 createField(SCHEMAS_MAPI, "reminderset");
192 createField(SCHEMAS_MAPI, "reminderdelta");
193
194
195 createField(SCHEMAS_MAPI, "allattendeesstring");
196 createField(SCHEMAS_MAPI, "required_attendees");
197 createField(SCHEMAS_MAPI, "apptendtime");
198 createField(SCHEMAS_MAPI, "apptstateflags");
199
200 createField(URN_SCHEMAS_CALENDAR, "isorganizer");
201 createField(URN_SCHEMAS_CALENDAR, "location");
202 createField(URN_SCHEMAS_CALENDAR, "attendeerole");
203 createField(URN_SCHEMAS_CALENDAR, "busystatus");
204 createField(URN_SCHEMAS_CALENDAR, "exrule");
205 createField(URN_SCHEMAS_CALENDAR, "recurrenceidrange");
206 createField(URN_SCHEMAS_CALENDAR, "rdate");
207 createField(URN_SCHEMAS_CALENDAR, "reminderoffset");
208 createField(URN_SCHEMAS_CALENDAR, "timezone");
209
210
211 createField(SCHEMAS_EXCHANGE, "sensitivity");
212 createField(URN_SCHEMAS_CALENDAR, "timezoneid");
213
214 createField("processed", 0x65e8, PropertyType.Boolean);
215
216 createField(DAV, "contentclass");
217 createField("internetContent", 0x6659, PropertyType.Binary);
218
219
220
221 createField(SCHEMAS_EXCHANGE, "outlookmessageclass");
222 createField(URN_SCHEMAS_HTTPMAIL, "subject");
223
224 createField(URN_SCHEMAS_CONTACTS, "middlename");
225 createField(URN_SCHEMAS_CONTACTS, "fileas");
226
227
228
229 createField(URN_SCHEMAS_CONTACTS, "homepostaladdress");
230 createField(URN_SCHEMAS_CONTACTS, "otherpostaladdress");
231 createField(URN_SCHEMAS_CONTACTS, "mailingaddressid");
232 createField(URN_SCHEMAS_CONTACTS, "workaddress");
233
234 createField(URN_SCHEMAS_CONTACTS, "alternaterecipient");
235
236 createField(SCHEMAS_EXCHANGE, "extensionattribute1");
237 createField(SCHEMAS_EXCHANGE, "extensionattribute2");
238 createField(SCHEMAS_EXCHANGE, "extensionattribute3");
239 createField(SCHEMAS_EXCHANGE, "extensionattribute4");
240
241 createField(URN_SCHEMAS_CONTACTS, "bday");
242 createField("anniversary", URN_SCHEMAS_CONTACTS, "weddinganniversary");
243 createField(URN_SCHEMAS_CONTACTS, "businesshomepage");
244 createField(URN_SCHEMAS_CONTACTS, "personalHomePage");
245 createField(URN_SCHEMAS_CONTACTS, "cn");
246 createField(URN_SCHEMAS_CONTACTS, "co");
247 createField(URN_SCHEMAS_CONTACTS, "department");
248
249
250 createField("smtpemail1", DistinguishedPropertySetType.Address, 0x8084, "smtpemail1");
251 createField("smtpemail2", DistinguishedPropertySetType.Address, 0x8094, "smtpemail2");
252 createField("smtpemail3", DistinguishedPropertySetType.Address, 0x80A4, "smtpemail3");
253
254
255 createField("email1", DistinguishedPropertySetType.Address, 0x8083, "email1");
256 createField("email2", DistinguishedPropertySetType.Address, 0x8093, "email2");
257 createField("email3", DistinguishedPropertySetType.Address, 0x80A3, "email3");
258
259
260 createField("email1type", DistinguishedPropertySetType.Address, 0x8082, "email1type");
261 createField("email2type", DistinguishedPropertySetType.Address, 0x8092, "email2type");
262 createField("email3type", DistinguishedPropertySetType.Address, 0x80A2, "email3type");
263
264 createField(URN_SCHEMAS_CONTACTS, "facsimiletelephonenumber");
265 createField(URN_SCHEMAS_CONTACTS, "givenName");
266 createField(URN_SCHEMAS_CONTACTS, "homepostofficebox");
267 createField(URN_SCHEMAS_CONTACTS, "homeCity");
268 createField(URN_SCHEMAS_CONTACTS, "homeCountry");
269 createField(URN_SCHEMAS_CONTACTS, "homePhone");
270 createField(URN_SCHEMAS_CONTACTS, "homePostalCode");
271 createField(URN_SCHEMAS_CONTACTS, "homeState");
272 createField(URN_SCHEMAS_CONTACTS, "homeStreet");
273 createField(URN_SCHEMAS_CONTACTS, "l");
274 createField(URN_SCHEMAS_CONTACTS, "manager");
275 createField(URN_SCHEMAS_CONTACTS, "mobile");
276 createField(URN_SCHEMAS_CONTACTS, "namesuffix");
277 createField(URN_SCHEMAS_CONTACTS, "nickname");
278 createField(URN_SCHEMAS_CONTACTS, "o");
279 createField(URN_SCHEMAS_CONTACTS, "pager");
280 createField(URN_SCHEMAS_CONTACTS, "personaltitle");
281 createField(URN_SCHEMAS_CONTACTS, "postalcode");
282 createField(URN_SCHEMAS_CONTACTS, "postofficebox");
283 createField(URN_SCHEMAS_CONTACTS, "profession");
284 createField(URN_SCHEMAS_CONTACTS, "roomnumber");
285 createField(URN_SCHEMAS_CONTACTS, "secretarycn");
286 createField(URN_SCHEMAS_CONTACTS, "sn");
287 createField(URN_SCHEMAS_CONTACTS, "spousecn");
288 createField(URN_SCHEMAS_CONTACTS, "st");
289 createField(URN_SCHEMAS_CONTACTS, "street");
290 createField(URN_SCHEMAS_CONTACTS, "telephoneNumber");
291 createField(URN_SCHEMAS_CONTACTS, "title");
292 createField("description", URN_SCHEMAS_HTTPMAIL, "textdescription");
293 createField("im", SCHEMAS_MAPI, "InstMsg");
294 createField(URN_SCHEMAS_CONTACTS, "othermobile");
295 createField(URN_SCHEMAS_CONTACTS, "internationalisdnnumber");
296
297 createField(URN_SCHEMAS_CONTACTS, "otherTelephone");
298 createField(URN_SCHEMAS_CONTACTS, "homefax");
299
300 createField(URN_SCHEMAS_CONTACTS, "otherstreet");
301 createField(URN_SCHEMAS_CONTACTS, "otherstate");
302 createField(URN_SCHEMAS_CONTACTS, "otherpostofficebox");
303 createField(URN_SCHEMAS_CONTACTS, "otherpostalcode");
304 createField(URN_SCHEMAS_CONTACTS, "othercountry");
305 createField(URN_SCHEMAS_CONTACTS, "othercity");
306
307 createField(URN_SCHEMAS_CONTACTS, "gender");
308
309 createField("keywords", SCHEMAS_EXCHANGE, "keywords-utf8", PropertyType.StringArray);
310
311
312
313 createField("private", DistinguishedPropertySetType.Common, 0x8506, "private", PropertyType.Boolean);
314 createField("sensitivity", 0x0036, PropertyType.Integer);
315
316 createField("haspicture", DistinguishedPropertySetType.Address, 0x8015, "haspicture", PropertyType.Boolean);
317
318 createField(URN_SCHEMAS_CALENDAR, "fburl");
319
320
321 createField("messageclass", 0x001a, PropertyType.String);
322 createField("roamingxmlstream", 0x7c08, PropertyType.Binary);
323 createField("roamingdictionary", 0x7c07, PropertyType.Binary);
324
325 createField(DAV, "ishidden");
326
327
328 createField("attachDataBinary", 0x3701, PropertyType.Binary);
329
330 createField("attachmentContactPhoto", 0x7FFF, PropertyType.Boolean);
331 createField("renderingPosition", 0x370B, PropertyType.Integer);
332
333 createField("attachExtension", 0x3703, PropertyType.String);
334
335 createField("xmozlastack", DistinguishedPropertySetType.PublicStrings);
336 createField("xmozsnoozetime", DistinguishedPropertySetType.PublicStrings);
337 createField("xmozsendinvitations", DistinguishedPropertySetType.PublicStrings);
338
339
340 createField(URN_SCHEMAS_MAILHEADER, "importance");
341 createField("percentcomplete", DistinguishedPropertySetType.Task, 0x8102, "percentcomplete", PropertyType.Double);
342 createField("taskstatus", DistinguishedPropertySetType.Task, 0x8101, "taskstatus", PropertyType.Integer);
343 createField("startdate", DistinguishedPropertySetType.Task, 0x8104, "startdate", PropertyType.SystemTime);
344 createField("duedate", DistinguishedPropertySetType.Task, 0x8105, "duedate", PropertyType.SystemTime);
345 createField("datecompleted", DistinguishedPropertySetType.Task, 0x810F, "datecompleted", PropertyType.SystemTime);
346 createField("iscomplete", DistinguishedPropertySetType.Task, 0x811C, "iscomplete", PropertyType.Boolean);
347
348
349 createField("commonstart", DistinguishedPropertySetType.Common, 0x8516, "commonstart", PropertyType.SystemTime);
350 createField("commonend", DistinguishedPropertySetType.Common, 0x8517, "commonend", PropertyType.SystemTime);
351 }
352
353 protected static String toHexString(int propertyTag) {
354 StringBuilder hexValue = new StringBuilder(Integer.toHexString(propertyTag));
355 while (hexValue.length() < 4) {
356 hexValue.insert(0, '0');
357 }
358 return hexValue.toString();
359 }
360
361 protected static void createField(String alias, int propertyTag, PropertyType propertyType) {
362 String name = 'x' + toHexString(propertyTag) + propertyTypeMap.get(propertyType);
363 Field field;
364 if (propertyType == PropertyType.Binary) {
365 field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name, propertyType, null, "bin.base64", name);
366 } else {
367 field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name, propertyType);
368 }
369 fieldMap.put(field.alias, field);
370 }
371
372 protected static void createField(String alias,@SuppressWarnings("SameParameterValue") DistinguishedPropertySetType propertySetType) {
373 Field field = new Field(Namespace.getNamespace(SCHEMAS_MAPI_STRING.getURI() +
374 '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), alias);
375 fieldMap.put(field.alias, field);
376 }
377
378 protected static void createField(String alias, @SuppressWarnings("SameParameterValue") DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias) {
379 createField(alias, propertySetType, propertyTag, responseAlias, null);
380 }
381
382 protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias, PropertyType propertyType) {
383 String name;
384 String updateAlias;
385 if (propertySetType == DistinguishedPropertySetType.Address) {
386
387 name = String.valueOf(propertyTag);
388 updateAlias = "_x0030_x" + toHexString(propertyTag);
389 } else if (propertySetType == DistinguishedPropertySetType.Task) {
390 name = "0x" + toHexString(propertyTag);
391 updateAlias = "0x0000" + toHexString(propertyTag);
392 } else {
393
394 name = "0x" + toHexString(propertyTag);
395 updateAlias = "_x0030_x" + toHexString(propertyTag);
396 }
397 Field field = new Field(alias, Namespace.getNamespace(SCHEMAS_MAPI_ID.getURI() +
398 '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, propertyType, responseAlias, null, updateAlias);
399 fieldMap.put(field.alias, field);
400 }
401
402 protected static void createField(Namespace namespace, String name) {
403 Field field = new Field(namespace, name);
404 fieldMap.put(field.alias, field);
405 }
406
407 protected static void createField(String alias, Namespace namespace, String name) {
408 Field field = new Field(alias, namespace, name, null);
409 fieldMap.put(field.alias, field);
410 }
411
412 @SuppressWarnings("SameParameterValue")
413 protected static void createField(String alias, Namespace namespace, String name, PropertyType propertyType) {
414 Field field = new Field(alias, namespace, name, propertyType);
415 fieldMap.put(field.alias, field);
416 }
417
418 private final DavPropertyName davPropertyName;
419 protected final String alias;
420 protected final String uri;
421 protected final String requestPropertyString;
422 protected final DavPropertyName responsePropertyName;
423 protected final DavPropertyName updatePropertyName;
424 protected final String cast;
425 protected final boolean isIntValue;
426 protected final boolean isMultivalued;
427 protected final boolean isBooleanValue;
428 protected final boolean isFloatValue;
429 protected final boolean isDateValue;
430
431
432
433
434
435
436
437 protected Field(Namespace namespace, String name) {
438 this(name, namespace, name, null);
439 }
440
441
442
443
444
445
446
447
448
449 protected Field(String alias, Namespace namespace, String name, PropertyType propertyType) {
450 this(alias, namespace, name, propertyType, null, null, name);
451 }
452
453
454
455
456
457
458
459
460
461
462
463
464 protected Field(String alias, Namespace namespace, String name, PropertyType propertyType, String responseAlias, String cast, String updateAlias) {
465 this.alias = alias;
466
467
468 davPropertyName = DavPropertyName.create(name, namespace);
469
470 updatePropertyName = DavPropertyName.create(updateAlias, namespace);
471
472
473 isMultivalued = propertyType != null && propertyType.toString().endsWith("Array");
474 isIntValue = propertyType == PropertyType.Long || propertyType == PropertyType.Integer || propertyType == PropertyType.Short;
475 isBooleanValue = propertyType == PropertyType.Boolean;
476 isFloatValue = propertyType == PropertyType.Float || propertyType == PropertyType.Double;
477 isDateValue = propertyType == PropertyType.SystemTime;
478
479 this.uri = namespace.getURI() + name;
480 if (responseAlias == null) {
481 this.requestPropertyString = '"' + uri + '"';
482 this.responsePropertyName = davPropertyName;
483 } else {
484 this.requestPropertyString = '"' + uri + "\" as " + responseAlias;
485 this.responsePropertyName = DavPropertyName.create(responseAlias, EMPTY);
486 }
487 this.cast = cast;
488 }
489
490
491
492
493
494
495 public String getUri() {
496 return uri;
497 }
498
499
500
501
502
503
504 public boolean isIntValue() {
505 return isIntValue;
506 }
507
508
509
510
511
512
513
514 public static Field get(String alias) {
515 Field field = fieldMap.get(alias);
516 if (field == null) {
517 throw new IllegalArgumentException("Unknown field: " + alias);
518 }
519 return field;
520 }
521
522
523
524
525
526
527
528 public static Field getHeader(String headerName) {
529 return new Field(SCHEMAS_MAPI_STRING_INTERNET_HEADERS, headerName);
530 }
531
532
533
534
535
536
537
538
539 public static PropEntry createDavProperty(String alias, String value) {
540 Field field = Field.get(alias);
541 if (value == null) {
542
543 return field.updatePropertyName;
544 } else if (field.isMultivalued) {
545
546 List<XmlSerializable> valueList = new ArrayList<>();
547 String[] values = value.split(",");
548 for (final String singleValue : values) {
549 valueList.add(document -> DomUtil.createElement(document, "v", XML, singleValue));
550 }
551
552 return new DefaultDavProperty<>(field.updatePropertyName, valueList);
553 } else if (field.isBooleanValue && !"haspicture".equals(alias)) {
554 if ("true".equals(value)) {
555 return new DefaultDavProperty<>(field.updatePropertyName, "1");
556 } else if ("false".equals(value)) {
557 return new DefaultDavProperty<>(field.updatePropertyName, "0");
558 } else {
559 throw new RuntimeException("Invalid value for " + field.alias + ": " + value);
560 }
561 } else {
562 return new DefaultDavProperty<>(field.updatePropertyName, value);
563 }
564 }
565
566
567
568
569
570
571
572
573
574 public static PropertyValue createPropertyValue(String alias, String value) {
575 Field field = Field.get(alias);
576 DavPropertyName davPropertyName = field.davPropertyName;
577 if (value == null) {
578
579 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName());
580 } else if (field.isMultivalued) {
581 StringBuilder buffer = new StringBuilder();
582
583 String[] values = value.split("\n");
584 for (final String singleValue : values) {
585 buffer.append("<v>");
586 buffer.append(StringUtil.xmlEncode(singleValue));
587 buffer.append("</v>");
588 }
589 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), buffer.toString());
590 } else if (field.isBooleanValue) {
591 if ("true".equals(value)) {
592 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "1", "boolean");
593 } else if ("false".equals(value)) {
594 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), "0", "boolean");
595 } else {
596 throw new RuntimeException("Invalid value for " + field.alias + ": " + value);
597 }
598 } else if (field.isFloatValue) {
599 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value), "float");
600 } else if (field.isIntValue) {
601 return new PropertyValue(field.updatePropertyName.getNamespace().getURI(), field.updatePropertyName.getName(), StringUtil.xmlEncode(value), "int");
602 } else if (field.isDateValue) {
603 return new PropertyValue(field.updatePropertyName.getNamespace().getURI(), field.updatePropertyName.getName(), StringUtil.xmlEncode(value), "dateTime.tz");
604 } else {
605 return new PropertyValue(davPropertyName.getNamespace().getURI(), davPropertyName.getName(), StringUtil.xmlEncode(value));
606 }
607 }
608
609
610
611
612
613
614
615 public static String getRequestPropertyString(String alias) {
616 return Field.get(alias).requestPropertyString;
617 }
618
619
620
621
622
623
624
625 public static DavPropertyName getPropertyName(String alias) {
626 return Field.get(alias).davPropertyName;
627 }
628
629
630
631
632
633
634
635 public static DavPropertyName getResponsePropertyName(String alias) {
636 return Field.get(alias).responsePropertyName;
637 }
638 }