11
11
public class Folder {
12
12
13
13
private String id ;
14
- private String changeKey ;
15
- private Integer count ;
14
+ private Connection conn ;
15
+ //private String changeKey;
16
+ //private Integer count;
16
17
17
18
protected Folder (){}
18
19
@@ -25,78 +26,100 @@ protected Folder(){}
25
26
*/
26
27
public Folder (String folderName , Connection conn ) throws ExchangeException {
27
28
28
- folderName = getDistinguishedFolderId (folderName );
29
+ this .conn = conn ;
30
+
31
+ String folderID = getDistinguishedFolderId (folderName );
32
+ if (folderID ==null ) folderID = folderName ;
29
33
30
34
String msg =
31
35
"<?xml version=\" 1.0\" encoding=\" utf-8\" ?>"
32
36
+ "<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\" http://schemas.microsoft.com/exchange/services/2006/types\" >"
33
37
+ "<soap:Body>"
34
38
+ "<GetFolder xmlns=\" http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\" http://schemas.microsoft.com/exchange/services/2006/types\" >"
35
39
+ "<FolderShape><t:BaseShape>Default</t:BaseShape></FolderShape>"
36
- + "<FolderIds><t:DistinguishedFolderId Id=\" " + folderName + "\" /></FolderIds></GetFolder>"
40
+
41
+
42
+ //This returns the LastModifiedTime for the folder. Unfortunately, this
43
+ //does not reflect changes made to items in this folder
44
+ /*
45
+ + "<FolderShape>"
46
+ + "<t:BaseShape>Default</t:BaseShape>"
47
+ + "<t:AdditionalProperties>"
48
+ + "<t:ExtendedFieldURI PropertyTag=\"0x3008\" PropertyType=\"SystemTime\" />"
49
+ + "</t:AdditionalProperties>"
50
+ + "</FolderShape>"
51
+ */
52
+
53
+
54
+ + "<FolderIds><t:DistinguishedFolderId Id=\" " + folderID + "\" /></FolderIds></GetFolder>"
37
55
+ "</soap:Body>"
38
56
+ "</soap:Envelope>" ;
39
-
40
-
41
-
42
57
parseXML (conn .execute (msg ));
43
58
}
44
59
45
60
46
-
47
- //**************************************************************************
48
- //** Constructor
49
- //**************************************************************************
50
- /** Creates a new instance of Folder. */
51
-
61
+ /*
52
62
public Folder(String xml) {
53
63
this(javaxt.xml.DOM.createDocument(xml));
54
64
}
55
65
56
66
public Folder(org.w3c.dom.Document xml){
57
67
parseXML(xml);
58
68
}
59
-
69
+ */
60
70
61
71
private void parseXML (org .w3c .dom .Document xml ){
62
-
63
72
org .w3c .dom .Node folderID = javaxt .xml .DOM .getElementsByTagName ("FolderId" , xml )[0 ]; //xml.getElementsByTagName("t:FolderId").item(0);
64
73
this .id = javaxt .xml .DOM .getAttributeValue (folderID , "Id" );
65
- this .changeKey = javaxt .xml .DOM .getAttributeValue (folderID , "ChangeKey" );
66
-
67
- try {
68
- String count = javaxt .xml .DOM .getNodeValue (xml .getElementsByTagName ("t:TotalCount" ).item (0 ));
69
- this .count = javaxt .utils .string .cint (count );
70
- }
71
- catch (Exception e ){
72
- }
73
74
}
74
75
75
- public String getID (){
76
+ //**************************************************************************
77
+ //** getID
78
+ //**************************************************************************
79
+ /** Returns the unique Exchange ID for this folder. */
80
+
81
+ public String getExchangeID (){
76
82
return id ;
77
83
}
78
84
85
+ /*
79
86
public String getChangeKey(){
80
87
return changeKey;
81
88
}
82
89
83
90
public Integer getCount(){
84
91
return count;
85
92
}
93
+ */
86
94
87
95
88
-
89
- protected org .w3c .dom .Document getItems (Connection conn , int maxEntries , int offset ) throws ExchangeException {
96
+ //**************************************************************************
97
+ //** getItems
98
+ //**************************************************************************
99
+ /** Returns an XML document with shallow representations of items found in
100
+ * this folder.
101
+ */
102
+ protected org .w3c .dom .Document getItems (int maxEntries , int offset ) throws ExchangeException {
90
103
91
104
String msg =
92
105
"<?xml version=\" 1.0\" encoding=\" utf-8\" ?>"
93
106
+ "<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\" http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:m=\" http://schemas.microsoft.com/exchange/services/2006/messages\" >"
94
- //+ "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/></soap:Header>"
95
107
+ "<soap:Body>"
96
108
+ "<m:FindItem Traversal=\" Shallow\" >"
97
- + "<m:ItemShape><t:BaseShape>Default</t:BaseShape>"
109
+ /*
110
+ + "<m:ItemShape><t:BaseShape>Default</t:BaseShape>" //<--"Default" vs "AllProperties"
98
111
+ "<t:AdditionalProperties><t:FieldURI FieldURI=\"item:ItemClass\"/></t:AdditionalProperties>"
99
112
+ "</m:ItemShape>"
113
+ */
114
+ + "<m:ItemShape>"
115
+ + "<t:BaseShape>Default</t:BaseShape>" //<--"Default" vs "AllProperties"
116
+ + "<t:AdditionalProperties>"
117
+ + "<t:FieldURI FieldURI=\" item:ItemClass\" />"
118
+ //+ "<t:FieldURI FieldURI=\"item:LastModifiedTime\"/>" //value="item:LastModifiedTime" //<--This doesn't work...
119
+ + "<t:ExtendedFieldURI PropertyTag=\" 0x3008\" PropertyType=\" SystemTime\" />" //<--This returns the LastModifiedTime!
120
+ + "</t:AdditionalProperties>"
121
+ + "</m:ItemShape>"
122
+
100
123
+ "<m:IndexedPageItemView MaxEntriesReturned=\" " + maxEntries + "\" Offset=\" " + offset + "\" BasePoint=\" Beginning\" /><m:ParentFolderIds>"
101
124
+ "<t:FolderId Id=\" " + id + "\" />"
102
125
+ "</m:ParentFolderIds>"
@@ -108,51 +131,127 @@ protected org.w3c.dom.Document getItems(Connection conn, int maxEntries, int off
108
131
}
109
132
110
133
111
- protected static org .w3c .dom .Node getItem (String itemID , Connection conn ) throws ExchangeException {
134
+ //**************************************************************************
135
+ //** getIndex
136
+ //**************************************************************************
137
+ /** Returns a hashmap of all the items found in this folder. The hashmap key
138
+ * is the item id and the corresponding value is the last modification date.
139
+ */
140
+ public java .util .HashMap <String , javaxt .utils .Date > getIndex () throws ExchangeException {
141
+
112
142
String msg =
113
143
"<?xml version=\" 1.0\" encoding=\" utf-8\" ?>"
114
- + "<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" "
115
- + "xmlns:t=\" http://schemas.microsoft.com/exchange/services/2006/types\" "
116
- + "xmlns:m=\" http://schemas.microsoft.com/exchange/services/2006/messages\" >"
144
+ + "<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\" http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:m=\" http://schemas.microsoft.com/exchange/services/2006/messages\" >"
117
145
+ "<soap:Body>"
118
- + "<m:GetItem>"
119
- + "<m:ItemShape><t:BaseShape>AllProperties</t:BaseShape></m:ItemShape>"
120
- + "<m:ItemIds><t:ItemId Id=\" " + itemID + "\" /></m:ItemIds>"
121
- + "</m:GetItem>"
146
+ + "<m:FindItem Traversal=\" Shallow\" >"
147
+ + "<m:ItemShape>"
148
+ + "<t:BaseShape>IdOnly</t:BaseShape>" //<--"Default" vs "AllProperties"
149
+ + "<t:AdditionalProperties>"
150
+ + "<t:ExtendedFieldURI PropertyTag=\" 0x3008\" PropertyType=\" SystemTime\" />" //<--This returns the LastModifiedTime!
151
+ + "</t:AdditionalProperties>"
152
+ + "</m:ItemShape>"
153
+
154
+ + "<m:SortOrder>"
155
+ + "<t:FieldOrder Order=\" Descending\" >"
156
+ + "<t:ExtendedFieldURI PropertyTag=\" 0x3008\" PropertyType=\" SystemTime\" />"
157
+ + "</t:FieldOrder>"
158
+ + "</m:SortOrder>"
159
+
160
+ //+ "<m:IndexedPageItemView MaxEntriesReturned=\"1\" Offset=\"0\" BasePoint=\"Beginning\"/>"
161
+ + "<m:ParentFolderIds>"
162
+ + "<t:FolderId Id=\" " + id + "\" />"
163
+ + "</m:ParentFolderIds>"
164
+ + "</m:FindItem>"
122
165
+ "</soap:Body>"
123
166
+ "</soap:Envelope>" ;
124
-
125
- //return conn.execute(msg);
167
+
126
168
org .w3c .dom .Document xml = conn .execute (msg );
169
+ //new javaxt.io.File("/temp/exchange-sort.xml").write(xml);
170
+
171
+ java .util .HashMap <String , javaxt .utils .Date > index = new java .util .HashMap <String , javaxt .utils .Date >();
127
172
128
173
org .w3c .dom .Node [] items = javaxt .xml .DOM .getElementsByTagName ("Items" , xml );
129
174
if (items .length >0 ){
130
175
org .w3c .dom .NodeList nodes = items [0 ].getChildNodes ();
131
176
for (int i =0 ; i <nodes .getLength (); i ++){
132
177
org .w3c .dom .Node node = nodes .item (i );
133
178
if (node .getNodeType ()==1 ){
134
- return node ;
179
+ FolderItem item = new FolderItem (node );
180
+ index .put (item .getExchangeID (), item .getLastModifiedTime ());
135
181
}
136
182
}
137
183
138
- }
184
+ }
185
+
186
+ return index ;
187
+ }
188
+
139
189
140
- throw new ExchangeException ("Failed to find Items" );
190
+ protected void findItem (){
191
+ /*
192
+ <m:FindItem Traversal="Shallow"
193
+ xmlns:m=".../messages"
194
+ xmlns:t=".../types">
195
+ <m:ItemShape>
196
+ <t:BaseShape>IdOnly</t:BaseShape>
197
+ <t:AdditionalProperties>
198
+ <t:FieldURI FieldURI="item:Subject" />
199
+ <t:FieldURI FieldURI="calendar:CalendarItemType" />
200
+ </t:AdditionalProperties>
201
+ </m:ItemShape>
202
+ <m:Restriction>
203
+ <t:And>
204
+ <t:IsGreaterThan>
205
+ <t:FieldURI FieldURI="calendar:Start" />
206
+ <t:FieldURIOrConstant>
207
+ <t:Constant Value="2006-10-16T00:00:00-08:00" />
208
+ </t:FieldURIOrConstant>
209
+ </t:IsGreaterThan>
210
+ <t:IsLessThan>
211
+ <t:FieldURI FieldURI="calendar:End" />
212
+ <t:FieldURIOrConstant>
213
+ <t:Constant Value="2006-10-20T23:59:59-08:00" />
214
+ </t:FieldURIOrConstant>
215
+ </t:IsLessThan>
216
+ </t:And>
217
+ </m:Restriction>
218
+ <m:ParentFolderIds>
219
+ <t:DistinguishedFolderId Id="calendar"/>
220
+ </m:ParentFolderIds>
221
+ </m:FindItem>
222
+ */
141
223
}
142
224
143
225
226
+ //**************************************************************************
227
+ //** getDistinguishedFolderIds
228
+ //**************************************************************************
229
+ /** Returns a list of Distinguished Folder IDs.
230
+ */
144
231
public static String [] getDistinguishedFolderIds (){
145
232
return DistinguishedFolderIds ;
146
233
}
147
234
235
+
236
+ //**************************************************************************
237
+ //** getDistinguishedFolderId
238
+ //**************************************************************************
239
+ /** Returns the DistinguishedFolderID for a given folder.
240
+ */
148
241
public static String getDistinguishedFolderId (String folderName ){
149
242
for (String folderID : DistinguishedFolderIds ){
150
243
if (folderID .equalsIgnoreCase (folderName )) return folderID ;
151
244
}
152
245
return null ;
153
246
}
154
247
155
- //http://msdn.microsoft.com/en-us/library/exchangewebservices.distinguishedfolderidnametype%28v=exchg.140%29.aspx
248
+
249
+ //**************************************************************************
250
+ //** DistinguishedFolderIds
251
+ //**************************************************************************
252
+ /** Static list of Distinguished Folder IDs. Source:
253
+ * http://msdn.microsoft.com/en-us/library/exchangewebservices.distinguishedfolderidnametype%28v=exchg.140%29.aspx
254
+ */
156
255
private static String [] DistinguishedFolderIds = new String []{
157
256
"archivedeleteditems" ,
158
257
"archivemsgfolderroot" ,
0 commit comments