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 protected static 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 propertySetId;
44 protected String propertyName;
45 protected int propertyId;
46 protected final PropertyType propertyType;
47
48
49
50
51
52
53
54 public ExtendedFieldURI(int intPropertyTag, PropertyType propertyType) {
55 this.propertyTag = "0x" + Integer.toHexString(intPropertyTag);
56 this.propertyType = propertyType;
57 }
58
59
60
61
62
63
64
65
66 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, int propertyId, PropertyType propertyType) {
67 this.distinguishedPropertySetId = distinguishedPropertySetId;
68 this.propertyId = propertyId;
69 this.propertyType = propertyType;
70 }
71
72
73
74
75
76
77
78 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName) {
79 this.distinguishedPropertySetId = distinguishedPropertySetId;
80 this.propertyName = propertyName;
81 this.propertyType = PropertyType.String;
82 }
83
84
85
86
87
88
89
90
91 public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType) {
92 this.distinguishedPropertySetId = distinguishedPropertySetId;
93 this.propertyName = propertyName;
94 this.propertyType = propertyType;
95 }
96
97 public void appendTo(StringBuilder buffer) {
98 buffer.append("<t:ExtendedFieldURI");
99 if (propertyTag != null) {
100 buffer.append(" PropertyTag=\"").append(propertyTag).append('"');
101 }
102 if (distinguishedPropertySetId != null) {
103 buffer.append(" DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append('"');
104 }
105 if (propertySetId != null) {
106 buffer.append(" PropertySetId=\"").append(propertySetId).append('"');
107 }
108 if (propertyName != null) {
109 buffer.append(" PropertyName=\"").append(propertyName).append('"');
110 }
111 if (propertyId != 0) {
112 buffer.append(" PropertyId=\"").append(String.valueOf(propertyId)).append('"');
113 }
114 if (propertyType != null) {
115 buffer.append(" PropertyType=\"").append(propertyType.toString()).append('"');
116 }
117 buffer.append("/>");
118 }
119
120 public void appendValue(StringBuilder buffer, String itemType, String value) {
121 if (itemType != null) {
122 appendTo(buffer);
123 buffer.append("<t:");
124 buffer.append(itemType);
125 buffer.append('>');
126 }
127 buffer.append("<t:ExtendedProperty>");
128 appendTo(buffer);
129 if (propertyType == PropertyType.StringArray) {
130 buffer.append("<t:Values>");
131 String[] values = value.split(",");
132 for (final String singleValue : values) {
133 buffer.append("<t:Value>");
134 buffer.append(StringUtil.xmlEncode(singleValue));
135 buffer.append("</t:Value>");
136
137 }
138 buffer.append("</t:Values>");
139 } else {
140 buffer.append("<t:Value>");
141 if ("0x10f3".equals(propertyTag)) {
142 buffer.append(StringUtil.xmlEncode(StringUtil.encodeUrlcompname(value)));
143 } else {
144 buffer.append(StringUtil.xmlEncode(value));
145 }
146 buffer.append("</t:Value>");
147 }
148 buffer.append("</t:ExtendedProperty>");
149 if (itemType != null) {
150 buffer.append("</t:");
151 buffer.append(itemType);
152 buffer.append('>');
153 }
154 }
155
156
157
158
159
160
161 public String getResponseName() {
162 if (propertyTag != null) {
163 return propertyTag;
164 } else if (propertyName != null) {
165 return propertyName;
166 } else {
167 return String.valueOf(propertyId);
168 }
169 }
170
171 }
172