Skip to content

Commit c03f29f

Browse files
author
pborissow
committed
- Added lastModified attribute to FolderItems.
- Refactored getItems method in the Folder class (getItems is a now non-static method). - Moved getItem method from the Folder class to the FolderItem constructor. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-exchange@134 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent f711028 commit c03f29f

File tree

4 files changed

+306
-117
lines changed

4 files changed

+306
-117
lines changed

src/javaxt/exchange/Contact.java

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ protected Contact(){}
7575
* effectively creating a clone.
7676
*/
7777
public Contact(javaxt.exchange.Contact contact){
78+
79+
//General information
7880
this.id = contact.id;
81+
this.updates = contact.updates;
82+
this.lastModified = contact.lastModified;
83+
84+
//Contact specific information
7985
this.firstName = contact.firstName;
8086
this.lastName = contact.lastName;
8187
this.fullName = contact.fullName;
@@ -86,7 +92,6 @@ public Contact(javaxt.exchange.Contact contact){
8692
this.phoneNumbers = contact.phoneNumbers;
8793
this.physicalAddresses = contact.physicalAddresses;
8894
this.birthday = contact.birthday;
89-
this.updates = contact.updates;
9095
}
9196

9297

@@ -932,14 +937,9 @@ public String getTitle(){
932937
/** Used to save/update a contact. Returns the Exchange ID for the item.
933938
*/
934939
public String save(Connection conn) throws ExchangeException {
935-
936-
if (id==null){
937-
return create(conn);
938-
}
939-
else{
940-
update(conn);
941-
return id;
942-
}
940+
if (id==null) create(conn);
941+
else update(conn);
942+
return id;
943943
}
944944

945945

@@ -1005,25 +1005,18 @@ private void update(Connection conn) throws ExchangeException {
10051005
System.out.println(msg + "\r\n");
10061006

10071007
updates.clear();
1008-
//if (true) return;
10091008

10101009
conn.execute(msg.toString());
1011-
//javaxt.http.Response response = conn.execute(msg.toString());
1012-
1013-
//String txt = response.getText();
1014-
//System.out.println(txt);
1015-
10161010
}
10171011

10181012

10191013

10201014
//**************************************************************************
10211015
//** create
10221016
//**************************************************************************
1023-
/** Used to create a new contact. Returns an id for the newly created
1024-
* contact or null is there was an error.
1017+
/** Used to create a new contact.
10251018
*/
1026-
private String create(Connection conn) throws ExchangeException {
1019+
private void create(Connection conn) throws ExchangeException {
10271020

10281021
StringBuffer msg = new StringBuffer();
10291022
msg.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
@@ -1126,30 +1119,12 @@ private String create(Connection conn) throws ExchangeException {
11261119
if (nodes!=null && nodes.getLength()>0){
11271120
id = javaxt.xml.DOM.getAttributeValue(nodes.item(0), "Id");
11281121
}
1129-
1130-
return id;
1122+
1123+
if (id==null) throw new ExchangeException("Failed to parse ItemId while saving the contact.");
11311124
}
11321125

11331126

1134-
//**************************************************************************
1135-
//** delete
1136-
//**************************************************************************
1137-
/** Used to delete a contact.
1138-
*/
1139-
public void delete(Connection conn) throws ExchangeException {
1140-
String msg =
1141-
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
1142-
+ "<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\">"
1143-
//+ "<soap:Header><t:RequestServerVersion Version=\"Exchange2007_SP1\"/></soap:Header>"
1144-
+ "<soap:Body>"
1145-
+ "<m:DeleteItem DeleteType=\"MoveToDeletedItems\">"
1146-
+ "<m:ItemIds>"
1147-
+ "<t:ItemId Id=\"" + id + "\"/></m:ItemIds>" //ChangeKey=\"EQAAABYAAAA9IPsqEJarRJBDywM9WmXKAAV+D0Dq\"
1148-
+ "</m:DeleteItem>"
1149-
+ "</soap:Body>"
1150-
+ "</soap:Envelope>";
1151-
conn.execute(msg);
1152-
}
1127+
11531128

11541129

11551130
public String toString(){

src/javaxt/exchange/ContactsFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Contact[] getContacts() throws ExchangeException {
4747
public Contact[] getContacts(int numEntries, int offset) throws ExchangeException {
4848

4949
java.util.ArrayList<Contact> contacts = new java.util.ArrayList<Contact>();
50-
org.w3c.dom.NodeList nodes = getItems(conn, numEntries, offset).getElementsByTagName("t:Contact");
50+
org.w3c.dom.NodeList nodes = getItems(numEntries, offset).getElementsByTagName("t:Contact");
5151
//org.w3c.dom.NodeList nodes = new javaxt.io.File("/temp/exchange-findItem.xml").getXML().getElementsByTagName("t:Contact");
5252

5353
int numRecordsReturned = 0;

src/javaxt/exchange/Folder.java

Lines changed: 141 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
public class Folder {
1212

1313
private String id;
14-
private String changeKey;
15-
private Integer count;
14+
private Connection conn;
15+
//private String changeKey;
16+
//private Integer count;
1617

1718
protected Folder(){}
1819

@@ -25,78 +26,100 @@ protected Folder(){}
2526
*/
2627
public Folder(String folderName, Connection conn) throws ExchangeException {
2728

28-
folderName = getDistinguishedFolderId(folderName);
29+
this.conn = conn;
30+
31+
String folderID = getDistinguishedFolderId(folderName);
32+
if (folderID==null) folderID = folderName;
2933

3034
String msg =
3135
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
3236
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
3337
+ "<soap:Body>"
3438
+ "<GetFolder xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
3539
+ "<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>"
3755
+ "</soap:Body>"
3856
+ "</soap:Envelope>";
39-
40-
41-
4257
parseXML(conn.execute(msg));
4358
}
4459

4560

46-
47-
//**************************************************************************
48-
//** Constructor
49-
//**************************************************************************
50-
/** Creates a new instance of Folder. */
51-
61+
/*
5262
public Folder(String xml) {
5363
this(javaxt.xml.DOM.createDocument(xml));
5464
}
5565
5666
public Folder(org.w3c.dom.Document xml){
5767
parseXML(xml);
5868
}
59-
69+
*/
6070

6171
private void parseXML(org.w3c.dom.Document xml){
62-
6372
org.w3c.dom.Node folderID = javaxt.xml.DOM.getElementsByTagName("FolderId", xml)[0]; //xml.getElementsByTagName("t:FolderId").item(0);
6473
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-
}
7374
}
7475

75-
public String getID(){
76+
//**************************************************************************
77+
//** getID
78+
//**************************************************************************
79+
/** Returns the unique Exchange ID for this folder. */
80+
81+
public String getExchangeID(){
7682
return id;
7783
}
7884

85+
/*
7986
public String getChangeKey(){
8087
return changeKey;
8188
}
8289
8390
public Integer getCount(){
8491
return count;
8592
}
93+
*/
8694

8795

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 {
90103

91104
String msg =
92105
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
93106
+ "<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>"
95107
+ "<soap:Body>"
96108
+ "<m:FindItem Traversal=\"Shallow\">"
97-
+ "<m:ItemShape><t:BaseShape>Default</t:BaseShape>"
109+
/*
110+
+ "<m:ItemShape><t:BaseShape>Default</t:BaseShape>" //<--"Default" vs "AllProperties"
98111
+ "<t:AdditionalProperties><t:FieldURI FieldURI=\"item:ItemClass\"/></t:AdditionalProperties>"
99112
+ "</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+
100123
+ "<m:IndexedPageItemView MaxEntriesReturned=\"" + maxEntries + "\" Offset=\"" + offset + "\" BasePoint=\"Beginning\"/><m:ParentFolderIds>"
101124
+ "<t:FolderId Id=\"" + id + "\"/>"
102125
+ "</m:ParentFolderIds>"
@@ -108,51 +131,127 @@ protected org.w3c.dom.Document getItems(Connection conn, int maxEntries, int off
108131
}
109132

110133

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+
112142
String msg =
113143
"<?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\">"
117145
+ "<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>"
122165
+ "</soap:Body>"
123166
+ "</soap:Envelope>";
124-
125-
//return conn.execute(msg);
167+
126168
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>();
127172

128173
org.w3c.dom.Node[] items = javaxt.xml.DOM.getElementsByTagName("Items", xml);
129174
if (items.length>0){
130175
org.w3c.dom.NodeList nodes = items[0].getChildNodes();
131176
for (int i=0; i<nodes.getLength(); i++){
132177
org.w3c.dom.Node node = nodes.item(i);
133178
if (node.getNodeType()==1){
134-
return node;
179+
FolderItem item = new FolderItem(node);
180+
index.put(item.getExchangeID(), item.getLastModifiedTime());
135181
}
136182
}
137183

138-
}
184+
}
185+
186+
return index;
187+
}
188+
139189

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+
*/
141223
}
142224

143225

226+
//**************************************************************************
227+
//** getDistinguishedFolderIds
228+
//**************************************************************************
229+
/** Returns a list of Distinguished Folder IDs.
230+
*/
144231
public static String[] getDistinguishedFolderIds(){
145232
return DistinguishedFolderIds;
146233
}
147234

235+
236+
//**************************************************************************
237+
//** getDistinguishedFolderId
238+
//**************************************************************************
239+
/** Returns the DistinguishedFolderID for a given folder.
240+
*/
148241
public static String getDistinguishedFolderId(String folderName){
149242
for (String folderID : DistinguishedFolderIds){
150243
if (folderID.equalsIgnoreCase(folderName)) return folderID;
151244
}
152245
return null;
153246
}
154247

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+
*/
156255
private static String[] DistinguishedFolderIds = new String[]{
157256
"archivedeleteditems",
158257
"archivemsgfolderroot",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy