KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > exchange > items > contact > dao > ContactDAO


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.exchange.items.contact.dao;
20
21 import java.io.IOException JavaDoc;
22 import java.text.MessageFormat JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import sync4j.exchange.httptransport.WebDavHttpTransport;
27 import sync4j.exchange.items.contact.model.Contact;
28 import sync4j.exchange.items.common.dao.ItemDAO;
29 import sync4j.exchange.xml.XmlParseException;
30 import sync4j.exchange.xml.XmlParser;
31
32 import sync4j.exchange.util.StringTools;
33
34 import sync4j.exchange.DataAccessException;
35
36 import sync4j.foundation.pdi.contact.Address;
37 import sync4j.foundation.pdi.contact.BusinessDetail;
38 import sync4j.foundation.pdi.contact.ContactDetail;
39 import sync4j.foundation.pdi.contact.Email;
40 import sync4j.foundation.pdi.contact.Name;
41 import sync4j.foundation.pdi.contact.Note;
42 import sync4j.foundation.pdi.contact.PersonalDetail;
43 import sync4j.foundation.pdi.contact.Note;
44 import sync4j.foundation.pdi.contact.Phone;
45 import sync4j.foundation.pdi.contact.Title;
46 import sync4j.foundation.pdi.contact.WebPage;
47
48 import sync4j.framework.server.store.NotFoundException;
49
50 /*
51  * This class implements methods to access contacts data
52  * in exchange server datastore
53  *
54  * @author Fabio Maggi @ Funambol
55  * @version $Id: ContactDAO.java,v 1.22 2005/06/27 15:08:53 fabius Exp $
56  *
57  **/

58 public class ContactDAO extends ItemDAO {
59
60     //---------------------------------------------------------------- Constants
61

62     private static final String JavaDoc TAG_ANNIVERSARY
63         = "weddinganniversary" ;
64     private static final String JavaDoc TAG_BIRTHDAY = "bday" ;
65     private static final String JavaDoc TAG_CATEGORIES = "keywordsutf8" ;
66     private static final String JavaDoc TAG_CHILDREN = "childrensnames" ;
67     private static final String JavaDoc TAG_DEPARTMENT = "department" ;
68     private static final String JavaDoc TAG_FILEAS = "fileas" ;
69     public static final String JavaDoc TAG_FIRSTNAME = "givenname" ;
70     private static final String JavaDoc TAG_HOBBY = "hobbies" ;
71     private static final String JavaDoc TAG_HOME_CITY = "homecity" ;
72     private static final String JavaDoc TAG_HOME_COUNTRY = "homecountry" ;
73     private static final String JavaDoc TAG_HOME_POST_OFFICE_BOX
74         ="homepostofficebox" ;
75     private static final String JavaDoc TAG_HOME_STATE = "homestate" ;
76     private static final String JavaDoc TAG_HOME_POSTAL_CODE = "homepostalcode" ;
77     private static final String JavaDoc TAG_HOME_STREET = "homestreet" ;
78     private static final String JavaDoc TAG_IMPORTANCE = "importance" ;
79     private static final String JavaDoc TAG_INITIALS = "initials" ;
80     private static final String JavaDoc TAG_JOBTITLE = "title" ;
81     private static final String JavaDoc TAG_LANGUAGE = "language" ;
82     public static final String JavaDoc TAG_LASTNAME = "sn" ;
83     public static final String JavaDoc TAG_MIDDLENAME = "middlename" ;
84     private static final String JavaDoc TAG_MILEAGE = "mileage" ;
85     private static final String JavaDoc TAG_SUFFIX = "namesuffix" ;
86     private static final String JavaDoc TAG_NICKNAME = "nickname" ;
87     private static final String JavaDoc TAG_OFFICE_LOCATION = "roomnumber" ;
88     private static final String JavaDoc TAG_ORGANIZATION = "organization" ;
89     private static final String JavaDoc TAG_ORGANIZATION_ID_NUMBER
90         = "employeenumber" ;
91     private static final String JavaDoc TAG_OTHER_CITY = "othercity" ;
92     private static final String JavaDoc TAG_OTHER_COUNTRY = "othercountry" ;
93     private static final String JavaDoc TAG_OTHER_POSTALCODE = "otherpostalcode" ;
94     private static final String JavaDoc TAG_OTHER_POST_OFFICE_BOX
95         = "otherpostofficebox" ;
96     private static final String JavaDoc TAG_OTHER_STATE = "otherstate" ;
97     private static final String JavaDoc TAG_OTHER_STREET = "otherstreet" ;
98     private static final String JavaDoc TAG_SECRETARY = "secretarycn" ;
99     private static final String JavaDoc TAG_SENSITIVITY = "sensitivity" ;
100     private static final String JavaDoc TAG_SPOUSECN = "spousecn" ;
101     private static final String JavaDoc TAG_TITLE = "personaltitle" ;
102     private static final String JavaDoc TAG_WORK_CITY = "city" ;
103     private static final String JavaDoc TAG_WORK_COUNTRY = "country" ;
104     private static final String JavaDoc TAG_WORK_POSTALCODE = "postalcode" ;
105     private static final String JavaDoc TAG_WORK_POST_OFFICE_BOX
106         = "postofficebox" ;
107     private static final String JavaDoc TAG_WORK_STATE = "state" ;
108     private static final String JavaDoc TAG_WORK_STREET = "street" ;
109
110     private static final String JavaDoc
111         TAG_YOMI_COMPANY_NAME = "yomiorganization" ;
112     private static final String JavaDoc TAG_YOMI_FIRST_NAME = "yomilastname" ;
113     private static final String JavaDoc TAG_YOMI_LAST_NAME = "yomifirstname" ;
114
115     private static final String JavaDoc TAG_CALL_BACK_PHONE = "callbackphone" ;
116     private static final String JavaDoc
117             TAG_FAC_SIMILE_TELEPHONE_NUMBER
118             = "facsimiletelephonenumber" ;
119     private static final String JavaDoc TAG_HOME_FAX = "homefax" ;
120     private static final String JavaDoc TAG_HOME_PHONE = "homephone" ;
121     private static final String JavaDoc TAG_HOME_PHONE2 = "homephone2" ;
122     private static final String JavaDoc TAG_ISDN_NUMBER
123         = "internationalisdnnumber" ;
124     private static final String JavaDoc TAG_MANAGER = "manager" ;
125     private static final String JavaDoc TAG_MOBILE = "mobile" ;
126     private static final String JavaDoc
127            TAG_ORGANIZATION_MAIN_PHONE
128            = "organizationmainphone" ;
129     private static final String JavaDoc TAG_OTHER_FAX = "otherfax" ;
130     private static final String JavaDoc TAG_OTHER_MOBILE = "othermobile" ;
131     private static final String JavaDoc TAG_OTHER_TELEPHONE
132            = "othertelephone" ;
133     private static final String JavaDoc TAG_PAGER = "pager" ;
134     private static final String JavaDoc TAG_PROFESSION = "profession" ;
135     private static final String JavaDoc TAG_SECRETARY_PHONE = "secretaryphone" ;
136     private static final String JavaDoc TAG_TELEPHONE_NUMBER = "telephonenumber" ;
137     private static final String JavaDoc TAG_TELEPHONE_NUMBER2 = "telephonenumber2" ;
138     private static final String JavaDoc TAG_TELEX_NUMBER = "telexnumber" ;
139
140     private static final String JavaDoc TAG_COMPUTER_NETWORK_NAME
141         = "computernetworkname" ;
142
143     private static final String JavaDoc
144         TAG_BUSINESS_HOME_PAGE
145         = "businesshomepage" ;
146     private static final String JavaDoc
147             TAG_PERSONAL_HOME_PAGE
148         = "personalHomePage" ;
149
150     public static final String JavaDoc TAG_EMAIL1 = "email1" ;
151     private static final String JavaDoc TAG_EMAIL2 = "email2" ;
152     private static final String JavaDoc TAG_EMAIL3 = "email3" ;
153
154     private static final String JavaDoc TAG_EMAIL1_ADDRESS_TYPE
155         = "email1addrtype" ;
156     private static final String JavaDoc TAG_EMAIL2_ADDRESS_TYPE
157         = "email2addrtype" ;
158     private static final String JavaDoc TAG_EMAIL3_ADDRESS_TYPE
159         = "email3addrtype" ;
160
161     private static final String JavaDoc TAG_RESPONSE = "a:response" ;
162     private static final String JavaDoc TAG_REPLUID = "repluid" ;
163     private static final String JavaDoc TAG_LAST_MODIFIED = "getlastmodified" ;
164
165
166     private static final String JavaDoc WEBDAV_MSG_SELECT_CONTACTS =
167     "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
168     "<D:searchrequest xmlns:D =\"DAV:\">\n" +
169     "<D:sql>\n" +
170     "Select " +
171     "\"http://schemas.microsoft.com/repl/repl-uid\" AS repluid, " +
172     "\"urn:schemas:contacts:weddinganniversary\" AS "
173         + TAG_ANNIVERSARY + ", " +
174     "\"urn:schemas:contacts:bday\" AS " + TAG_BIRTHDAY + ", " +
175     "\"urn:schemas:contacts:childrensnames\" AS " + TAG_CHILDREN + ", " +
176     "\"urn:schemas:contacts:fileas\" AS " + TAG_FILEAS + ", " +
177     "\"urn:schemas:contacts:givenName\" AS " + TAG_FIRSTNAME + ", " +
178     "\"http://schemas.microsoft.com/exchange/keywords-utf8\" AS "
179                                                     + TAG_CATEGORIES + ", " +
180     "\"urn:schemas:contacts:hobbies\" AS " + TAG_HOBBY + ", " +
181     "\"urn:schemas:httpmail:importance\" AS " + TAG_IMPORTANCE + ", " +
182     "\"urn:schemas:contacts:initials\" AS " + TAG_INITIALS + ", " +
183     "\"urn:schemas:contacts:sn\" AS " + TAG_LASTNAME + ", " +
184     "\"urn:schemas:contacts:language\" AS " + TAG_LANGUAGE + ", " +
185     "\"urn:schemas:contacts:title\" AS " + TAG_JOBTITLE + ", " +
186     "\"urn:schemas:contacts:middlename\" AS " + TAG_MIDDLENAME + ", " +
187     "\"urn:schemas:contacts:mileage\" AS " + TAG_MILEAGE + ", " +
188     "\"urn:schemas:contacts:nickname\" AS " + TAG_NICKNAME + ", " +
189     "\"urn:schemas:contacts:o\" AS " + TAG_ORGANIZATION + ", " +
190     "\"urn:schemas:contacts:sensitivity\" AS " + TAG_SENSITIVITY + ", " +
191     "\"urn:schemas:contacts:spousecn\" AS " + TAG_SPOUSECN + ", " +
192     "\"urn:schemas:contacts:namesuffix\" AS " + TAG_SUFFIX + ", " +
193     "\"urn:schemas:contacts:personaltitle\" AS " + TAG_TITLE + ", " +
194     "\"http://schemas.microsoft.com/exchange/yomiorganization\" AS "
195                                                     + TAG_YOMI_COMPANY_NAME + ", " +
196     "\"http://schemas.microsoft.com/exchange/yomifirstname\" AS "
197                                                     + TAG_YOMI_FIRST_NAME + ", " +
198     "\"http://schemas.microsoft.com/exchange/yomilastname\" AS "
199                                                     + TAG_YOMI_LAST_NAME + ", " +
200     "\"urn:schemas:contacts:homeStreet\" AS " + TAG_HOME_STREET + ", " +
201     "\"urn:schemas:contacts:homeCity\" AS " + TAG_HOME_CITY + ", " +
202     "\"urn:schemas:contacts:homeState\" AS " + TAG_HOME_STATE + ", " +
203     "\"urn:schemas:contacts:homePostalCode\" AS " + TAG_HOME_POSTAL_CODE + ", " +
204     "\"urn:schemas:contacts:homepostofficebox\" AS "+
205         TAG_HOME_POST_OFFICE_BOX + ", " +
206     "\"urn:schemas:contacts:homeCountry\" AS " + TAG_HOME_COUNTRY + ", " +
207
208     "\"urn:schemas:contacts:street\" AS " + TAG_WORK_STREET + ", " +
209     "\"urn:schemas:contacts:l\" AS " + TAG_WORK_CITY + ", " +
210     "\"urn:schemas:contacts:st\" AS " + TAG_WORK_STATE + ", " +
211     "\"urn:schemas:contacts:postalcode\" AS " + TAG_WORK_POSTALCODE + ", " +
212     "\"urn:schemas:contacts:postofficebox\" AS " +
213         TAG_WORK_POST_OFFICE_BOX + ", " +
214     "\"urn:schemas:contacts:co\" AS " + TAG_WORK_COUNTRY + ", " +
215
216     "\"urn:schemas:contacts:otherstreet\" AS " + TAG_OTHER_STREET + ", " +
217     "\"urn:schemas:contacts:othercity\" AS " + TAG_OTHER_CITY + ", " +
218     "\"urn:schemas:contacts:otherstate\" AS " + TAG_OTHER_STATE + ", " +
219     "\"urn:schemas:contacts:otherpostalcode\" AS " + TAG_OTHER_POSTALCODE + ", " +
220     "\"urn:schemas:contacts:otherpostofficebox\" AS "
221         + TAG_OTHER_POST_OFFICE_BOX + ", " +
222     "\"urn:schemas:contacts:othercountry\" AS " + TAG_OTHER_COUNTRY + ", " +
223
224     "\"urn:schemas:contacts:callbackphone\" AS " + TAG_CALL_BACK_PHONE + ", " +
225     "\"urn:schemas:contacts:facsimiletelephonenumber\" " +
226             "AS " +
227               TAG_FAC_SIMILE_TELEPHONE_NUMBER + ", " +
228     "\"urn:schemas:contacts:homefax\" AS " + TAG_HOME_FAX + ", " +
229     "\"urn:schemas:contacts:homePhone\" AS " + TAG_HOME_PHONE + ", " +
230     "\"urn:schemas:contacts:homephone2\" AS " + TAG_HOME_PHONE2 + ", " +
231     "\"urn:schemas:contacts:mobile\" AS " + TAG_MOBILE + ", " +
232     "\"urn:schemas:contacts:internationalisdnnumber\" AS " +
233              TAG_ISDN_NUMBER + ", " +
234     "\"urn:schemas:contacts:organizationmainphone\" " +
235             "AS " +
236             TAG_ORGANIZATION_MAIN_PHONE + ", " +
237     "\"urn:schemas:contacts:otherfax\" AS " + TAG_OTHER_FAX + ", " +
238     "\"urn:schemas:contacts:othermobile\" AS " + TAG_OTHER_MOBILE + ", " +
239     "\"urn:schemas:contacts:otherTelephone\" AS " + TAG_OTHER_TELEPHONE + ", " +
240     "\"urn:schemas:contacts:pager\" AS " + TAG_PAGER + ", " +
241     "\"urn:schemas:contacts:secretaryphone\" AS " + TAG_SECRETARY_PHONE + ", " +
242     "\"urn:schemas:contacts:telephoneNumber\" AS " + TAG_TELEPHONE_NUMBER + ", " +
243     "\"urn:schemas:contacts:telephonenumber2\" AS " + TAG_TELEPHONE_NUMBER2 + ", " +
244     "\"urn:schemas:contacts:telexnumber\" AS " + TAG_TELEX_NUMBER + ", " +
245
246     "\"urn:schemas:contacts:businesshomepage\" AS " + TAG_BUSINESS_HOME_PAGE + ", " +
247     "\"urn:schemas:contacts:personalHomePage\" AS " + TAG_PERSONAL_HOME_PAGE + ", " +
248
249     "\"urn:schemas:contacts:department\" AS " + TAG_DEPARTMENT + ", " +
250     "\"urn:schemas:contacts:roomnumber\" AS " + TAG_OFFICE_LOCATION + ", " +
251     "\"urn:schemas:contacts:employeenumber\" AS " +
252         TAG_ORGANIZATION_ID_NUMBER + ", " +
253     "\"urn:schemas:contacts:profession\" AS " + TAG_PROFESSION + ", " +
254     "\"urn:schemas:contacts:manager\" AS " + TAG_MANAGER + ", " +
255     "\"urn:schemas:contacts:secretarycn\" AS " + TAG_SECRETARY + ", " +
256
257     "\"urn:schemas:contacts:email1\" AS " + TAG_EMAIL1 + ", " +
258     "\"urn:schemas:contacts:email2\" AS " + TAG_EMAIL2 + ", " +
259     "\"urn:schemas:contacts:email3\" AS " + TAG_EMAIL3 + ", " +
260     "\"urn:schemas:contacts:email1addrtype\" AS " +
261         TAG_EMAIL1_ADDRESS_TYPE + ", " +
262     "\"urn:schemas:contacts:email2addrtype\" AS " +
263         TAG_EMAIL2_ADDRESS_TYPE + ", " +
264     "\"urn:schemas:contacts:email3addrtype\" AS " +
265         TAG_EMAIL3_ADDRESS_TYPE + ", " +
266
267     "\"urn:schemas:contacts:computernetworkname\" AS "
268         + TAG_COMPUTER_NETWORK_NAME + ", " +
269     "\"DAV:displayname\", " +
270     "\"DAV:getlastmodified\" AS getlastmodified, " +
271     "\"DAV:isfolder\" AS isfolder " +
272     "FROM \"/{0}/{1}/{2}\" " +
273     "{3} " +
274     "</D:sql>\n" +
275     "</D:searchrequest>" ;
276
277     private static final String JavaDoc
278         FIELD_PREFIX = "urn:schemas:contacts:" ;
279
280     private static final String JavaDoc
281         WEBDAV_INIT_EX = "EX:" ;
282     private static final String JavaDoc
283         WEBDAV_INIT_HG = "HG:" ;
284     private static final String JavaDoc
285         WEBDAV_INIT_HM = "HM:" ;
286     private static final String JavaDoc
287         WEBDAV_INIT_HN = "HN:" ;
288     private static final String JavaDoc
289         WEBDAV_INIT_HO = "HO:" ;
290
291     private static final String JavaDoc
292         WEBDAV_INIT_MAPI = "mapi:" ;
293
294     private static final String JavaDoc
295         WEBDAV_TAG_ANNIVERSARY = WEBDAV_INIT_HM +
296                                         "weddinganniversary" ;
297     private static final String JavaDoc
298         WEBDAV_TAG_ASSISTANT = WEBDAV_INIT_HM +
299                                         "secretarycn" ;
300     private static final String JavaDoc
301         WEBDAV_TAG_BIRTHDAY = WEBDAV_INIT_HM +
302                                         "bday" ;
303     private static final String JavaDoc
304         WEBDAV_TAG_CATEGORIES = WEBDAV_INIT_EX +
305                                         "keywords-utf8" ;
306     private static final String JavaDoc
307         WEBDAV_TAG_CHILDREN = WEBDAV_INIT_HM +
308                                         "childrensnames" ;
309     private static final String JavaDoc
310         WEBDAV_TAG_CN = WEBDAV_INIT_HM +
311                                         "cn" ;
312     private static final String JavaDoc
313         WEBDAV_TAG_COMPANY = WEBDAV_INIT_HM +
314                                         "o" ;
315     private static final String JavaDoc
316         WEBDAV_TAG_DEPARTMENT = WEBDAV_INIT_HM +
317                                         "department" ;
318     private static final String JavaDoc
319         WEBDAV_TAG_FILE_AS = WEBDAV_INIT_HM +
320                                         "fileas" ;
321     private static final String JavaDoc
322         WEBDAV_TAG_FIRST_NAME = WEBDAV_INIT_HM +
323                                         "givenName" ;
324     private static final String JavaDoc
325         WEBDAV_TAG_HOBBY = WEBDAV_INIT_HM +
326                                         "hobbies" ;
327     private static final String JavaDoc
328         WEBDAV_TAG_HOME_CITY = WEBDAV_INIT_HM +
329                                         "homeCity" ;
330     private static final String JavaDoc
331         WEBDAV_TAG_HOME_COUNTRY = WEBDAV_INIT_HM +
332                                         "homeCountry" ;
333     private static final String JavaDoc
334         WEBDAV_TAG_HOME_POSTALCODE = WEBDAV_INIT_HM +
335                                         "homePostalCode" ;
336     private static final String JavaDoc
337         WEBDAVTAG_HOME_POST_OFFICE_BOX
338                                       = WEBDAV_INIT_HM +
339                                         "homepostofficebox" ;
340     private static final String JavaDoc
341         WEBDAV_TAG_HOME_STATE = WEBDAV_INIT_HM +
342                                         "homeState" ;
343     private static final String JavaDoc
344         WEBDAV_TAG_HOME_STREET = WEBDAV_INIT_HM +
345                                         "homeStreet" ;
346     private static final String JavaDoc
347         WEBDAV_TAG_IMPORTANCE = WEBDAV_INIT_HN +
348                                         "importance" ;
349     private static final String JavaDoc
350         WEBDAV_TAG_INITIALS = WEBDAV_INIT_HM +
351                                         "initials" ;
352     private static final String JavaDoc
353         WEBDAV_TAG_JOB_TITLE = WEBDAV_INIT_HM +
354                                         "title" ;
355     private static final String JavaDoc
356         WEBDAV_TAG_LANGUAGE = WEBDAV_INIT_HM +
357                                         "language";
358     private static final String JavaDoc
359         WEBDAV_TAG_LAST_NAME = WEBDAV_INIT_HM +
360                                         "sn" ;
361     private static final String JavaDoc
362         WEBDAV_TAG_MANAGER = WEBDAV_INIT_HM +
363                                         "manager" ;
364     private static final String JavaDoc
365         WEBDAV_TAG_MIDDLE_NAME = WEBDAV_INIT_HM +
366                                         "middlename" ;
367     private static final String JavaDoc
368         WEBDAV_TAG_MILEAGE = WEBDAV_INIT_EX +
369                                         "mileage" ;
370     private static final String JavaDoc
371         WEBDAV_TAG_NICKNAME = WEBDAV_INIT_HM +
372                                         "nickname" ;
373     private static final String JavaDoc
374         WEBDAV_TAG_OFFICE_LOCATION = WEBDAV_INIT_HM +
375                                         "roomnumber" ;
376     private static final String JavaDoc
377         WEBDAV_TAG_OTHER_CITY = WEBDAV_INIT_HM +
378                                         "othercity" ;
379     private static final String JavaDoc
380         WEBDAV_TAG_OTHER_COUNTRY = WEBDAV_INIT_HM +
381                                         "othercountry" ;
382     private static final String JavaDoc
383         WEBDAV_TAG_OTHER_POSTALCODE = WEBDAV_INIT_HM +
384                                         "otherpostalcode" ;
385     private static final String JavaDoc
386         WEBDAV_TAG_OTHER_POST_OFFICE_BOX
387                                       = WEBDAV_INIT_HM +
388                                         "otherpostofficebox" ;
389
390     private static final String JavaDoc
391         WEBDAV_TAG_OTHER_STATE = WEBDAV_INIT_HM +
392                                         "otherstate" ;
393     private static final String JavaDoc
394         WEBDAV_TAG_OTHER_STREET = WEBDAV_INIT_HM +
395                                         "otherstreet" ;
396     private static final String JavaDoc
397         WEBDAV_TAG_ORGANIZATION_ID_NUMBER
398                                       = WEBDAV_INIT_HM +
399                                         "employeenumber" ;
400     private static final String JavaDoc
401         WEBDAV_TAG_PROFESSION = WEBDAV_INIT_HM +
402                                         "profession" ;
403     private static final String JavaDoc
404         WEBDAV_TAG_SENSITIVITY = WEBDAV_INIT_MAPI +
405                                         "sensitivity" ;
406     private static final String JavaDoc
407         WEBDAV_TAG_SPOUSE = WEBDAV_INIT_HM +
408                                         "spousecn" ;
409     private static final String JavaDoc
410         WEBDAV_TAG_SUBJECT1 = WEBDAV_INIT_HN +
411                                         "subject" ;
412     private static final String JavaDoc
413         WEBDAV_TAG_SUBJECT2 = WEBDAV_INIT_HO +
414                                         "subject" ;
415     private static final String JavaDoc
416         WEBDAV_TAG_SUFFIX = WEBDAV_INIT_HM +
417                                         "namesuffix" ;
418     private static final String JavaDoc
419         WEBDAV_TAG_TITLE = WEBDAV_INIT_HM +
420                                         "personaltitle" ;
421     private static final String JavaDoc
422         WEBDAV_TAG_WORK_CITY = WEBDAV_INIT_HM +
423                                         "l" ;
424     private static final String JavaDoc
425         WEBDAV_TAG_WORK_COUNTRY = WEBDAV_INIT_HM +
426                                         "co" ;
427     private static final String JavaDoc
428         WEBDAV_TAG_WORK_POSTALCODE = WEBDAV_INIT_HM +
429                                         "postalcode" ;
430     private static final String JavaDoc
431         WEBDAV_TAG_WORK_POST_OFFICE_BOX = WEBDAV_INIT_HM +
432                                         "postofficebox" ;
433     private static final String JavaDoc
434         WEBDAV_TAG_WORK_STATE = WEBDAV_INIT_HM +
435                                         "st" ;
436     private static final String JavaDoc
437         WEBDAV_TAG_WORK_STREET = WEBDAV_INIT_HM +
438                                         "street" ;
439
440     private static final String JavaDoc
441         WEBDAV_TAG_YOMI_COMAPANY_NAME = WEBDAV_INIT_EX +
442                                         "yomiorganization" ;
443     private static final String JavaDoc
444         WEBDAV_TAG_YOMI_FIRST_NAME = WEBDAV_INIT_EX +
445                                         "yomifirstname" ;
446     private static final String JavaDoc
447         WEBDAV_TAG_YOMI_LAST_NAME = WEBDAV_INIT_EX +
448                                         "yomilastname" ;
449     private static final String JavaDoc
450         WEBDAV_TAG_ASSISTANT_PHONE = WEBDAV_INIT_HM +
451                                         "secretaryphone" ;
452     private static final String JavaDoc
453         WEBDAV_TAG_CALLBACK_PHONE = WEBDAV_INIT_HM +
454                                         "callbackphone" ;
455     private static final String JavaDoc
456         WEBDAV_TAG_COMPANY_PHONE = WEBDAV_INIT_HM +
457                                         "organizationmainphone" ;
458     private static final String JavaDoc
459         WEBDAV_TAG_HOME_FAX = WEBDAV_INIT_HM +
460                                         "homefax" ;
461     private static final String JavaDoc
462         WEBDAV_TAG_HOME_OTHER_PHONE = WEBDAV_INIT_HM +
463                                         "homephone2" ;
464     private static final String JavaDoc
465         WEBDAV_TAG_HOME_PHONE = WEBDAV_INIT_HM +
466                                         "homePhone" ;
467     private static final String JavaDoc
468         WEBDAV_TAG_MOBILE_OTHER_PHONE = WEBDAV_INIT_HM +
469                                         "othermobile" ;
470     private static final String JavaDoc
471         WEBDAV_TAG_MOBILE_PHONE = WEBDAV_INIT_HM +
472                                         "mobile" ;
473     private static final String JavaDoc
474         WEBDAV_TAG_OTHER_FAX = WEBDAV_INIT_HM +
475                                         "otherfax" ;
476     private static final String JavaDoc
477         WEBDAV_TAG_OTHER_PHONE = WEBDAV_INIT_HM +
478                                         "otherTelephone" ;
479     private static final String JavaDoc
480         WEBDAV_TAG_PAGER = WEBDAV_INIT_HM +
481                                         "pager" ;
482     private static final String JavaDoc
483         WEBDAV_TAG_TELEX_NUMBER = WEBDAV_INIT_HM +
484                                         "telexnumber" ;
485     private static final String JavaDoc
486         WEBDAV_TAG_WORK_FAX = WEBDAV_INIT_HM +
487                                         "facsimiletelephonenumber" ;
488     private static final String JavaDoc
489         WEBDAV_TAG_WORK_OTHER_PHONE = WEBDAV_INIT_HM +
490                                         "telephonenumber2" ;
491     private static final String JavaDoc
492         WEBDAV_TAG_WORK_PHONE = WEBDAV_INIT_HM +
493                                         "telephoneNumber" ;
494
495     private static final String JavaDoc
496         WEBDAV_TAG_BUSINESS_HOME_PAGE = WEBDAV_INIT_HM +
497                                         "businesshomepage" ;
498     private static final String JavaDoc
499         WEBDAV_TAG_PERSONAL_HOME_PAGE = WEBDAV_INIT_HM +
500                                         "personalHomePage" ;
501     private static final String JavaDoc
502         WEBDAV_TAG_EMAIL1 = WEBDAV_INIT_HM +
503                                         "email1" ;
504     private static final String JavaDoc
505         WEBDAV_TAG_EMAIL2 = WEBDAV_INIT_HM +
506                                         "email2" ;
507     private static final String JavaDoc
508         WEBDAV_TAG_EMAIL3 = WEBDAV_INIT_HM +
509                                         "email3" ;
510     private static final String JavaDoc
511         WEBDAV_TAG_EMAIL1_ADDRESS_TYPE = WEBDAV_INIT_MAPI +
512                                         "email1addrtype" ;
513     private static final String JavaDoc
514         WEBDAV_TAG_EMAIL2_ADDRESS_TYPE = WEBDAV_INIT_MAPI +
515                                         "email2addrtype" ;
516     private static final String JavaDoc
517         WEBDAV_TAG_EMAIL3_ADDRESS_TYPE = WEBDAV_INIT_MAPI +
518                                         "email3addrtype" ;
519
520     private static final String JavaDoc
521         WEBDAV_TAG_COMPUTER_NETWORK_NAME
522                                       = WEBDAV_INIT_HM +
523                                         "computernetworkname" ;
524
525     private static final String JavaDoc
526         FIELD_TYPE_ASSISTANT_NUMBER =
527         "AssistantTelephoneNumber" ;
528     private static final String JavaDoc
529         FIELD_TYPE_BUSINESS_FAX_NUMBER =
530         "BusinessFaxNumber" ;
531     private static final String JavaDoc
532         FIELD_TYPE_BUSINESS_OTHER_TELEPHONE_NUMBER =
533         "Business2TelephoneNumber" ;
534     private static final String JavaDoc
535         FIELD_TYPE_BUSINESS_TELEPHONE_NUMBER =
536         "BusinessTelephoneNumber" ;
537     private static final String JavaDoc
538         FIELD_TYPE_CALLBACK_NUMBER =
539         "CallbackTelephoneNumber" ;
540     private static final String JavaDoc
541         FIELD_TYPE_CAR_TELEPHONE_NUMBER =
542         "CarTelephoneNumber" ;
543     private static final String JavaDoc
544         FIELD_TYPE_COMPANY_MAIN_TELEPHONE_NUMBER =
545         "CompanyMainTelephoneNumber" ;
546     public static final String JavaDoc
547         FIELD_TYPE_EMAIL1_ADDRESS =
548         "Email1Address" ;
549     public static final String JavaDoc
550         FIELD_TYPE_EMAIL2_ADDRESS =
551         "Email2Address" ;
552     private static final String JavaDoc
553         FIELD_TYPE_EMAIL3_ADDRESS =
554         "Email3Address" ;
555     private static final String JavaDoc
556         FIELD_TYPE_JOB_TITLE =
557         "JobTitle" ;
558
559     private static final String JavaDoc
560         FIELD_TYPE_PERSONAL_HOME_PAGE =
561         "HomeWebPage" ;
562     private static final String JavaDoc
563         FIELD_TYPE_BUSINESS_HOME_PAGE =
564         "WebPage" ;
565     private static final String JavaDoc
566         FIELD_TYPE_HOME_TELEPHONE_NUMBER =
567         "HomeTelephoneNumber" ;
568     private static final String JavaDoc
569         FIELD_TYPE_HOME_OTHER_TELEPHONE_NUMBER =
570         "Home2TelephoneNumber" ;
571     private static final String JavaDoc
572         FIELD_TYPE_HOME_FAX_NUMBER =
573         "HomeFaxNumber" ;
574     private static final String JavaDoc
575         FIELD_TYPE_MOBILE_TELEPHONE_NUMBER =
576         "MobileTelephoneNumber" ;
577     private static final String JavaDoc
578         FIELD_TYPE_NOTE =
579         "Body" ;
580     private static final String JavaDoc
581         FIELD_TYPE_OTHER_TELEPHONE_NUMBER =
582         "OtherTelephoneNumber" ;
583     private static final String JavaDoc
584         FIELD_TYPE_OTHER_FAX_NUMBER =
585         "OtherFaxNumber" ;
586     private static final String JavaDoc
587         FIELD_TYPE_PAGER_NUMBER =
588         "PagerNumber" ;
589     private static final String JavaDoc
590         FIELD_TYPE_STATUS =
591         "status" ;
592
593     //------------------------------------------------------------- Private data
594

595     private WebDavHttpTransport webDavHttp = null ;
596
597     //------------------------------------------------------------- Costructors
598

599     public ContactDAO(String JavaDoc exchangeServerHost ,
600                       int exchangeServerPort)
601         throws DataAccessException {
602
603         this.webDavHttp = new WebDavHttpTransport(exchangeServerHost,
604                                                           exchangeServerPort);
605     }
606
607     //------------------------------------------------------------- Public methods
608

609     /**
610      * insert / update contact<br>
611      *
612      * @param c
613      * @param username
614      * @param credentials
615      * @param exchangeFolder
616      *
617      * @return new / updated contact
618      *
619      * @throws sync4j.exchange.util.DataAccessException
620      **/

621     public Contact setContact(Contact c ,
622                               String JavaDoc username ,
623                               String JavaDoc credentials ,
624                               String JavaDoc exchangeFolder )
625     throws DataAccessException {
626
627         PersonalDetail personalDetail = null ;
628         BusinessDetail businessDetail = null ;
629         Address homeAddressBook = null ;
630         Address workAddressBook = null ;
631         Address otherAddressBook = null ;
632
633         Name name = null ;
634         Phone phone = null;
635         Email email = null;
636         WebPage webPage = null;
637
638         List JavaDoc webPages = null ;
639         List JavaDoc emails = null ;
640         List JavaDoc webPagesPersonal = null ;
641         List JavaDoc emailsBusiness = null ;
642         List JavaDoc phonesPersonal = null ;
643         List JavaDoc phonesBusiness = null ;
644
645         String JavaDoc response = null ;
646
647         String JavaDoc id = null ;
648
649         StringBuffer JavaDoc webDavContactMsg = null ;
650         String JavaDoc webDavHeaderMsg = null ;
651
652         String JavaDoc anniversary = null ;
653         String JavaDoc birthday = null ;
654         String JavaDoc categories = null ;
655         String JavaDoc children = null ;
656         String JavaDoc firstName = null ;
657         String JavaDoc hobby = null ;
658         Short JavaDoc importance = null ;
659         String JavaDoc initials = null ;
660         String JavaDoc language = null ;
661         String JavaDoc lastName = null ;
662         String JavaDoc middleName = null ;
663         Integer JavaDoc mileage = null ;
664         String JavaDoc displayName = null ;
665         String JavaDoc jobTitle = null ;
666         String JavaDoc organization = null ;
667         Short JavaDoc sensitivity = null ;
668         String JavaDoc suffix = null ;
669         String JavaDoc title = null ;
670         String JavaDoc homeStreet = null ;
671         String JavaDoc homeCity = null ;
672         String JavaDoc homeState = null ;
673         String JavaDoc homePostalCode = null ;
674         String JavaDoc homePostOfficeBox = null ;
675         String JavaDoc homeCountry = null ;
676         String JavaDoc officeStreet = null ;
677         String JavaDoc officeCity = null ;
678         String JavaDoc officeState = null ;
679         String JavaDoc officeCountry = null ;
680         String JavaDoc officePostalCode = null ;
681         String JavaDoc officePostOfficeBox = null ;
682         String JavaDoc officeLocation = null ;
683         String JavaDoc otherStreet = null ;
684         String JavaDoc otherCity = null ;
685         String JavaDoc otherState = null ;
686         String JavaDoc otherPostalCode = null ;
687         String JavaDoc otherPostOfficeBox = null ;
688         String JavaDoc otherCountry = null ;
689         String JavaDoc officePhone = null ;
690         String JavaDoc homePhone = null ;
691         String JavaDoc mobilePhone = null ;
692         String JavaDoc assistantPhone = null ;
693         String JavaDoc officeOtherPhone = null ;
694         String JavaDoc officeFax = null ;
695         String JavaDoc callBackPhone = null ;
696         String JavaDoc mobileOtherPhone = null ;
697         String JavaDoc organizationPhone = null ;
698         String JavaDoc homeOtherPhone = null ;
699         String JavaDoc homeFax = null ;
700         String JavaDoc otherPhone = null ;
701         String JavaDoc otherFax = null ;
702         String JavaDoc pager = null ;
703         String JavaDoc personalHomePage = null ;
704         String JavaDoc businessHomePage = null ;
705         String JavaDoc department = null ;
706         String JavaDoc profession = null ;
707         String JavaDoc nickName = null ;
708         String JavaDoc spouse = null ;
709         String JavaDoc manager = null ;
710         String JavaDoc assistant = null ;
711         String JavaDoc emailAddress1 = null ;
712         String JavaDoc emailAddress2 = null ;
713         String JavaDoc emailAddress3 = null ;
714
715         String JavaDoc phoneType = null ;
716         String JavaDoc webPageType = null ;
717
718         String JavaDoc value = null ;
719
720         String JavaDoc server = null ;
721         String JavaDoc resource = null ;
722
723         server = getServerFromExchangeFolder (exchangeFolder );
724         resource = getResourceFromExchangeFolder (exchangeFolder );
725
726         XmlParser p = new XmlParser();
727
728         personalDetail = c.getPersonalDetail () ;
729         businessDetail = c.getBusinessDetail () ;
730         name = c.getName () ;
731
732         importance = c.getImportance () ;
733         sensitivity = c.getSensitivity () ;
734         mileage = c.getMileage () ;
735         language = c.getLanguages () ;
736         categories = c.getCategories () ;
737
738         if (personalDetail != null) {
739             homeAddressBook = personalDetail.getAddress () ;
740             otherAddressBook = personalDetail.getOtherAddress () ;
741             webPages = personalDetail.getWebPages () ;
742             emails = personalDetail.getEmails () ;
743             phonesPersonal = personalDetail.getPhones () ;
744             spouse = personalDetail.getSpouse () ;
745             children = personalDetail.getChildren () ;
746             birthday = personalDetail.getBirthday () ;
747             anniversary = personalDetail.getAnniversary () ;
748             hobby = personalDetail.getHobbies () ;
749             webPagesPersonal = personalDetail.getWebPages () ;
750         }
751
752         if (businessDetail != null) {
753             workAddressBook = businessDetail.getAddress () ;
754             phonesBusiness = businessDetail.getPhones () ;
755             emailsBusiness = businessDetail.getEmails () ;
756         }
757
758         if (businessDetail != null) {
759             assistant = businessDetail.getAssistant () ;
760             manager = businessDetail.getManager () ;
761             officeLocation = businessDetail.getOfficeLocation () ;
762
763             if (businessDetail.getCompany() != null) {
764                 organization = businessDetail.getCompany ().
765                                             getPropertyValueAsString() ;
766             }
767             if (businessDetail.getDepartment() != null) {
768                 department = businessDetail.getDepartment ().
769                                             getPropertyValueAsString() ;
770             }
771             if (businessDetail.getRole() != null) {
772                 profession = businessDetail.getRole ().
773                                             getPropertyValueAsString() ;
774             }
775         }
776
777         if (name != null) {
778             if (name.getFirstName() != null) {
779                 firstName = name.getFirstName ().
780                                         getPropertyValueAsString() ;
781             }
782             if (name.getMiddleName() != null) {
783                 middleName = name.getMiddleName ().
784                                         getPropertyValueAsString() ;
785             }
786             if (name.getLastName() != null) {
787                 lastName = name.getLastName ().
788                                         getPropertyValueAsString() ;
789             }
790             if (name.getDisplayName() != null) {
791                 displayName = name.getDisplayName ().
792                                         getPropertyValueAsString() ;
793             }
794             if (name.getNickname() != null) {
795                 nickName = name.getNickname ().
796                                         getPropertyValueAsString() ;
797             }
798
799             if (name.getInitials() != null) {
800                 initials = name.getInitials ().
801                                         getPropertyValueAsString() ;
802             }
803
804             if (name.getSuffix() != null) {
805                 suffix = name.getSuffix ().
806                                         getPropertyValueAsString() ;
807             }
808             if (name.getSalutation() != null) {
809                 title = name.getSalutation ().
810                                         getPropertyValueAsString() ;
811             }
812
813         }
814
815         if (businessDetail.getTitles() !=null &&
816             businessDetail.getTitles().size() > 0 &&
817             ((Title) businessDetail.getTitles().get(0)) != null) {
818             jobTitle = ((Title) businessDetail.getTitles().get(0)).
819                                                 getPropertyValueAsString();
820         } else {
821             jobTitle = null;
822         }
823
824         if (emails != null) {
825
826             for (int i=0, l = emails.size(); i < l; i++) {
827
828                 email = (Email) emails.get(i);
829
830                 if ((FIELD_TYPE_EMAIL1_ADDRESS).equals(email.getEmailType())) {
831                     emailAddress1 = email.getPropertyValueAsString();
832                 } else if ((FIELD_TYPE_EMAIL2_ADDRESS).
833                             equals(email.getEmailType())) {
834                     emailAddress2 = email.getPropertyValueAsString();
835                 } else if ((FIELD_TYPE_EMAIL3_ADDRESS).
836                             equals(email.getEmailType())) {
837                     emailAddress3 = email.getPropertyValueAsString();
838                 }
839
840             }
841
842         }
843
844         //
845
// phones
846
//
847
if (phonesPersonal != null) {
848
849             for (int i=0, l = phonesPersonal.size(); i < l; i++) {
850
851                 phone = (Phone) phonesPersonal.get(i);
852
853                 phoneType = phone.getPhoneType();
854
855                 if ((FIELD_TYPE_HOME_TELEPHONE_NUMBER).
856                                 equals(phoneType)) {
857                     homePhone = phone.getPropertyValueAsString();
858                 } if ((FIELD_TYPE_HOME_OTHER_TELEPHONE_NUMBER).
859                                 equals(phoneType)) {
860                     homeOtherPhone = phone.getPropertyValueAsString();
861                 } else if ((FIELD_TYPE_HOME_FAX_NUMBER).
862                                 equals(phoneType)) {
863                     homeFax = phone.getPropertyValueAsString();
864                 } else if ((FIELD_TYPE_MOBILE_TELEPHONE_NUMBER).
865                                 equals(phoneType)) {
866                     mobilePhone = phone.getPropertyValueAsString();
867                 } else if ((FIELD_TYPE_CAR_TELEPHONE_NUMBER).
868                                 equals(phoneType)) {
869                     mobileOtherPhone = phone.getPropertyValueAsString();
870                 } else if ((FIELD_TYPE_OTHER_TELEPHONE_NUMBER).
871                                 equals(phoneType)) {
872                     otherPhone = phone.getPropertyValueAsString();
873                 } else if ((FIELD_TYPE_OTHER_FAX_NUMBER).
874                                 equals(phoneType)) {
875                     otherFax = phone.getPropertyValueAsString();
876                 } else {
877                     //
878
// no save uknown property
879
//
880
continue;
881                 }
882
883             }
884
885         }
886
887         //
888
// phones business
889
//
890
if (phonesBusiness != null) {
891
892             for (int i=0, l = phonesBusiness.size(); i < l; i++) {
893
894                 phone = (Phone) phonesBusiness.get(i);
895
896                 phoneType = phone.getPhoneType();
897
898                 if ((FIELD_TYPE_BUSINESS_TELEPHONE_NUMBER).
899                             equals(phoneType)) {
900                     officePhone = phone.getPropertyValueAsString();
901                 } else if ((FIELD_TYPE_BUSINESS_OTHER_TELEPHONE_NUMBER).
902                             equals(phoneType)) {
903                     officeOtherPhone = phone.getPropertyValueAsString();
904                 } else if ((FIELD_TYPE_BUSINESS_FAX_NUMBER).
905                             equals(phoneType)) {
906                     officeFax = phone.getPropertyValueAsString();
907                 } else if ((FIELD_TYPE_COMPANY_MAIN_TELEPHONE_NUMBER).
908                             equals(phoneType)) {
909                     organizationPhone = phone.getPropertyValueAsString();
910                 } else if ((FIELD_TYPE_PAGER_NUMBER).
911                             equals(phoneType)) {
912                     pager = phone.getPropertyValueAsString();
913                 } else if ((FIELD_TYPE_ASSISTANT_NUMBER).
914                             equals(phoneType)) {
915                     assistantPhone = phone.getPropertyValueAsString();
916                 } else if ((FIELD_TYPE_CALLBACK_NUMBER).
917                             equals(phoneType)) {
918                     callBackPhone = phone.getPropertyValueAsString();
919                 } else {
920                     //
921
// no save uknown property
922
//
923
continue;
924                 }
925
926             }
927
928         }
929
930         //
931
// webPages personal
932
//
933

934         if (webPagesPersonal != null) {
935
936             for (int i=0, l = webPagesPersonal.size(); i < l; i++) {
937
938                 webPage = (WebPage) webPagesPersonal.get(i);
939
940                 webPageType = webPage.getWebPageType();
941
942                 if ((FIELD_TYPE_PERSONAL_HOME_PAGE).equals(webPageType)) {
943                     personalHomePage = webPage.getPropertyValueAsString();
944                 } else if ((FIELD_TYPE_BUSINESS_HOME_PAGE).equals(webPageType)) {
945                     businessHomePage = webPage.getPropertyValueAsString();
946                  } {
947                     //
948
// no save uknown property
949
//
950
continue;
951                 }
952
953             }
954
955         }
956
957         if (homeAddressBook != null) {
958
959             if (homeAddressBook.getStreet() != null) {
960                 homeStreet = homeAddressBook.getStreet().
961                                             getPropertyValueAsString();
962             }
963             if (homeAddressBook.getCity() != null) {
964                 homeCity = homeAddressBook.getCity().
965                                             getPropertyValueAsString();
966             }
967             if (homeAddressBook.getPostalCode() != null) {
968                 homePostalCode = homeAddressBook.getPostalCode().
969                                             getPropertyValueAsString();
970             }
971             if (homeAddressBook.getPostOfficeAddress() != null) {
972                 homePostOfficeBox = homeAddressBook.
973                                         getPostOfficeAddress().
974                                                 getPropertyValueAsString();
975             }
976             if (homeAddressBook.getState() != null) {
977                 homeState = homeAddressBook.getState().
978                                             getPropertyValueAsString();
979             }
980             if (homeAddressBook.getCountry()!= null) {
981                 homeCountry = homeAddressBook.getCountry().
982                                             getPropertyValueAsString();
983             }
984
985         }
986
987         if (otherAddressBook != null) {
988
989             if (otherAddressBook.getStreet() != null) {
990                 otherStreet = otherAddressBook.getStreet().
991                                         getPropertyValueAsString();
992             }
993             if (otherAddressBook.getCity() != null) {
994                 otherCity = otherAddressBook.getCity().
995                                         getPropertyValueAsString();
996             }
997             if (otherAddressBook.getPostalCode() != null) {
998                 otherPostalCode = otherAddressBook.getPostalCode().
999                                         getPropertyValueAsString();
1000            }
1001            if (otherAddressBook.getPostOfficeAddress() != null) {
1002                otherPostOfficeBox = otherAddressBook.
1003                                        getPostOfficeAddress().
1004                                                getPropertyValueAsString();
1005            }
1006            if (otherAddressBook.getState() != null) {
1007                otherState = otherAddressBook.getState().
1008                                        getPropertyValueAsString();
1009            }
1010            if (homeAddressBook.getCountry()!= null) {
1011                otherCountry = otherAddressBook.getCountry().
1012                                        getPropertyValueAsString();
1013            }
1014
1015        }
1016
1017        if (workAddressBook != null) {
1018
1019            if (workAddressBook.getStreet() != null) {
1020                officeStreet = workAddressBook.getStreet().
1021                                    getPropertyValueAsString();
1022            }
1023            if (workAddressBook.getCity() != null) {
1024                officeCity = workAddressBook.getCity().
1025                                    getPropertyValueAsString();
1026            }
1027            if (workAddressBook.getPostalCode() != null) {
1028                officePostalCode = workAddressBook.getPostalCode().
1029                                    getPropertyValueAsString();
1030            }
1031            if (workAddressBook.getPostOfficeAddress() != null) {
1032                officePostOfficeBox = workAddressBook.
1033                                        getPostOfficeAddress().
1034                                                getPropertyValueAsString();
1035            }
1036            if (workAddressBook.getState() != null) {
1037                officeState = workAddressBook.getState().
1038                                    getPropertyValueAsString();
1039            }
1040            if (workAddressBook.getCountry()!= null) {
1041                officeCountry = workAddressBook.getCountry().
1042                                    getPropertyValueAsString();
1043            }
1044
1045        }
1046
1047        webDavContactMsg = new StringBuffer JavaDoc();
1048
1049        webDavContactMsg.
1050            append
1051                ("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
1052                 "<D:propertyupdate xmlns:D=\"DAV:\" " +
1053                 "xmlns:EX=\"http://schemas.microsoft.com/exchange/\" " +
1054                 "xmlns:HM=\"urn:schemas:contacts:\" " +
1055                 "xmlns:HG=\"urn:schemas:calendar:\" " +
1056                 "xmlns:HN=\"urn:schemas:httpmail:\" " +
1057                 "xmlns:x=\"xml:\" " +
1058                 "xmlns:mapi=\"http://schemas.microsoft.com/mapi/\" " +
1059                 "xmlns:HO=\"urn:schemas:mailheader:\">\n" +
1060                 "<D:set>\n" +
1061                 "<D:prop>\n" +
1062                 "<D:contentclass>urn:content-classes:person</D:contentclass>\n" +
1063                 "<EX:outlookmessageclass>IPM.Contact</EX:outlookmessageclass>\n") ;
1064
1065
1066        firstName = StringTools.escapeXml(firstName );
1067        lastName = StringTools.escapeXml(lastName );
1068        middleName = StringTools.escapeXml(middleName );
1069        initials = StringTools.escapeXml(initials );
1070
1071        //
1072
// full name variables
1073
//
1074
String JavaDoc fnTitle = title ;
1075        String JavaDoc fnFirstName = firstName ;
1076        String JavaDoc fnMiddleName = middleName ;
1077        String JavaDoc fnLastName = lastName ;
1078        String JavaDoc fnSuffix = suffix ;
1079
1080        if ((title != null && title.length () > 0 ) &&
1081            ((firstName != null && firstName.length () > 0 ) ||
1082            (middleName != null && middleName.length () > 0 ) ||
1083            (lastName != null && lastName.length () > 0 ) ||
1084            (suffix != null && suffix.length () > 0 ))) {
1085
1086            fnTitle = fnTitle + " ";
1087
1088        }
1089
1090        if ((firstName != null && firstName.length () > 0 ) &&
1091            ((middleName != null && middleName.length () > 0 ) ||
1092            (lastName != null && lastName.length () > 0 ) ||
1093            (suffix != null && suffix.length () > 0 ))) {
1094
1095            fnFirstName = fnFirstName + " ";
1096
1097        }
1098
1099        if ((middleName != null && middleName.length () > 0 ) &&
1100            ((lastName != null && lastName.length () > 0 ) ||
1101            (suffix != null && suffix.length () > 0 ))) {
1102
1103            fnMiddleName = fnMiddleName + " ";
1104
1105        }
1106
1107        if ((lastName != null && lastName.length () > 0) &&
1108            (suffix != null && suffix.length () > 0)) {
1109
1110            fnLastName = fnLastName + " ";
1111
1112        }
1113
1114        value = "";
1115
1116        if (fnTitle != null) {
1117            value = fnTitle;
1118        }
1119
1120        if (fnFirstName != null) {
1121            value = value + fnFirstName;
1122        }
1123
1124        if (fnMiddleName != null) {
1125            value = value + fnMiddleName;
1126        }
1127
1128        if (fnLastName != null) {
1129            value = value + fnLastName;
1130        }
1131
1132        if (fnSuffix != null) {
1133            value = value + fnSuffix;
1134        }
1135
1136        if (value != null && value.length() > 0) {
1137            webDavContactMsg.append("<" +
1138                                    WEBDAV_TAG_CN +
1139                                    ">" +
1140                                    value +
1141                                    "</" +
1142                                    WEBDAV_TAG_CN +
1143                                    ">\n" );
1144        }
1145
1146        value = null;
1147        value = (lastName != null ? lastName : "") +
1148                (((firstName != null && firstName.length() > 0)
1149                    && (lastName != null && lastName.length() > 0))
1150                    ? ", " : "") +
1151                (firstName != null ? firstName : "") +
1152                (((middleName != null && middleName.length() > 0)
1153                    && (firstName !=null && firstName.length() > 0))
1154                    ? " " : "") +
1155                (middleName != null ? middleName : "") ;
1156
1157        if (value != null) {
1158            webDavContactMsg.append("<" +
1159                                    WEBDAV_TAG_FILE_AS +
1160                                    ">" +
1161                                    value +
1162                                    "</" +
1163                                    WEBDAV_TAG_FILE_AS +
1164                                    ">\n" );
1165        }
1166
1167        value = null;
1168        value = (lastName != null ? lastName : "") +
1169                (((firstName != null && firstName.length() > 0)
1170                    && (lastName != null && lastName.length() > 0))
1171                    ? " " : "") +
1172                (firstName != null ? firstName : "") ;
1173
1174        if (value != null) {
1175            webDavContactMsg.append("<" +
1176                                    WEBDAV_TAG_SUBJECT1 +
1177                                    ">" +
1178                                    value +
1179                                    "</" +
1180                                    WEBDAV_TAG_SUBJECT1 +
1181                                    ">\n" );
1182        }
1183
1184        value = null;
1185        value = (lastName != null ? lastName : "") +
1186                (((firstName != null && firstName.length() > 0)
1187                    && (lastName != null && lastName.length() > 0 ))
1188                    ? " " : "") +
1189                (firstName != null ? firstName : "") ; ;
1190
1191        if (value != null) {
1192            webDavContactMsg.append("<" +
1193                                    WEBDAV_TAG_SUBJECT2 +
1194                                    ">" +
1195                                    value +
1196                                    "</" +
1197                                    WEBDAV_TAG_SUBJECT2 +
1198                                    ">\n" );
1199        }
1200
1201        if (firstName != null) {
1202            webDavContactMsg.append("<" +
1203                                    WEBDAV_TAG_FIRST_NAME +
1204                                    ">" +
1205                                    firstName +
1206                                    "</" +
1207                                    WEBDAV_TAG_FIRST_NAME +
1208                                    ">\n" );
1209        }
1210
1211        if (lastName != null) {
1212            webDavContactMsg.append("<" +
1213                                    WEBDAV_TAG_LAST_NAME +
1214                                    ">" +
1215                                    lastName +
1216                                    "</" +
1217                                    WEBDAV_TAG_LAST_NAME +
1218                                    ">\n" );
1219        }
1220
1221        if (middleName != null) {
1222            webDavContactMsg.append("<" +
1223                                    WEBDAV_TAG_MIDDLE_NAME +
1224                                    ">" +
1225                                    middleName +
1226                                    "</" +
1227                                    WEBDAV_TAG_MIDDLE_NAME +
1228                                    ">\n" );
1229        }
1230
1231        if (language != null) {
1232            language = StringTools.escapeXml(language);
1233            webDavContactMsg.append("<" +
1234                                    WEBDAV_TAG_LANGUAGE +
1235                                    ">" +
1236                                    language +
1237                                    "</" +
1238                                    WEBDAV_TAG_LANGUAGE +
1239                                    ">\n" );
1240        }
1241
1242        if (suffix != null) {
1243            suffix = StringTools.escapeXml(suffix);
1244            webDavContactMsg.append("<" +
1245                                    WEBDAV_TAG_SUFFIX +
1246                                    ">" +
1247                                    suffix +
1248                                    "</" +
1249                                    WEBDAV_TAG_SUFFIX +
1250                                    ">\n" );
1251        }
1252
1253        if (title != null) {
1254            title = StringTools.escapeXml(title);
1255            webDavContactMsg.append("<" +
1256                                    WEBDAV_TAG_TITLE +
1257                                    ">" +
1258                                    title +
1259                                    "</" +
1260                                    WEBDAV_TAG_TITLE +
1261                                    ">\n" );
1262        }
1263
1264        if (initials != null) {
1265                    webDavContactMsg.append("<" +
1266                                            WEBDAV_TAG_INITIALS +
1267                                            ">" +
1268                                            initials +
1269                                            "</" +
1270                                            WEBDAV_TAG_INITIALS +
1271                                            ">\n" );
1272        }
1273
1274        if (importance != null) {
1275                    webDavContactMsg.append("<" +
1276                                        WEBDAV_TAG_IMPORTANCE +
1277                                        ">" +
1278                                        String.valueOf(importance) +
1279                                        "</" +
1280                                        WEBDAV_TAG_IMPORTANCE +
1281                                        ">\n" );
1282        }
1283
1284        if (sensitivity != null) {
1285                    webDavContactMsg.append("<" +
1286                                        WEBDAV_TAG_SENSITIVITY +
1287                                        ">" +
1288                                        String.valueOf(sensitivity) +
1289                                        "</" +
1290                                        WEBDAV_TAG_SENSITIVITY +
1291                                        ">\n" );
1292        }
1293
1294        if (mileage != null) {
1295                    webDavContactMsg.append("<" +
1296                                        WEBDAV_TAG_MILEAGE +
1297                                        ">" +
1298                                        String.valueOf(mileage) +
1299                                        "</" +
1300                                        WEBDAV_TAG_MILEAGE +
1301                                        ">\n" );
1302        }
1303
1304
1305        try {
1306
1307            if (anniversary != null) {
1308                webDavContactMsg.append("<" +
1309                                        WEBDAV_TAG_ANNIVERSARY +
1310                                        ">" +
1311                                        XmlParser.
1312                                            PDIToWebDavAnniversary
1313                                                (anniversary) +
1314                                        "</" +
1315                                        WEBDAV_TAG_ANNIVERSARY +
1316                                        ">\n" );
1317            }
1318
1319            if (birthday != null) {
1320                webDavContactMsg.append("<" +
1321                                        WEBDAV_TAG_BIRTHDAY +
1322                                        ">" +
1323                                        XmlParser.
1324                                            PDIToWebDavAnniversary
1325                                                (birthday) +
1326                                        "</" +
1327                                        WEBDAV_TAG_BIRTHDAY +
1328                                        ">\n" );
1329            }
1330
1331        } catch (Exception JavaDoc e) {
1332            throw new DataAccessException(e.getMessage());
1333        }
1334
1335        if (categories != null) {
1336
1337            categories = StringTools.escapeXml(categories);
1338            webDavContactMsg.append("<" +
1339                                    WEBDAV_TAG_CATEGORIES +
1340                                    ">" +
1341                                    XmlParser.
1342                                        fieldToMultipleTag
1343                                            (categories) +
1344                                    "</" +
1345                                    WEBDAV_TAG_CATEGORIES +
1346                                    ">\n" );
1347        }
1348
1349        if (children != null) {
1350            children = StringTools.escapeXml(children);
1351            webDavContactMsg.append("<" +
1352                                    WEBDAV_TAG_CHILDREN +
1353                                    ">" +
1354                                    XmlParser.
1355                                        fieldToMultipleTag
1356                                            (children) +
1357                                    "</" +
1358                                    WEBDAV_TAG_CHILDREN +
1359                                    ">\n" );
1360        }
1361
1362        if (hobby != null) {
1363            hobby = StringTools.escapeXml(hobby);
1364            webDavContactMsg.append("<" +
1365                                    WEBDAV_TAG_HOBBY +
1366                                    ">" +
1367                                    hobby +
1368                                    "</" +
1369                                    WEBDAV_TAG_HOBBY +
1370                                    ">\n" );
1371        }
1372
1373        if (jobTitle != null) {
1374            jobTitle = StringTools.escapeXml(jobTitle);
1375            webDavContactMsg.append("<" +
1376                                    WEBDAV_TAG_JOB_TITLE +
1377                                    ">" +
1378                                    jobTitle +
1379                                    "</" +
1380                                    WEBDAV_TAG_JOB_TITLE +
1381                                    ">\n" );
1382        }
1383
1384        if (officeLocation != null) {
1385            officeLocation = StringTools.escapeXml(officeLocation);
1386            webDavContactMsg.append("<" +
1387                                    WEBDAV_TAG_OFFICE_LOCATION +
1388                                    ">" +
1389                                    officeLocation +
1390                                    "</" +
1391                                    WEBDAV_TAG_OFFICE_LOCATION +
1392                                    ">\n" );
1393        }
1394
1395        if (organization != null) {
1396            organization = StringTools.escapeXml(organization);
1397            webDavContactMsg.append("<" +
1398                                    WEBDAV_TAG_COMPANY +
1399                                    ">" +
1400                                    organization +
1401                                    "</" +
1402                                    WEBDAV_TAG_COMPANY +
1403                                    ">\n" );
1404        }
1405
1406        if (homeStreet != null) {
1407            homeStreet = StringTools.escapeXml(homeStreet);
1408            webDavContactMsg.append("<" +
1409                                    WEBDAV_TAG_HOME_STREET +
1410                                    ">" +
1411                                    homeStreet +
1412                                    "</" +
1413                                    WEBDAV_TAG_HOME_STREET +
1414                                    ">\n" );
1415        }
1416
1417        if (homeCity != null) {
1418            homeCity = StringTools.escapeXml(homeCity);
1419            webDavContactMsg.append("<" +
1420                                    WEBDAV_TAG_HOME_CITY +
1421                                    ">" +
1422                                    homeCity +
1423                                    "</" +
1424                                    WEBDAV_TAG_HOME_CITY +
1425                                    ">\n" );
1426        }
1427
1428        if (homeState != null) {
1429            homeState = StringTools.escapeXml(homeState);
1430            webDavContactMsg.append("<" +
1431                                    WEBDAV_TAG_HOME_STATE +
1432                                    ">" +
1433                                    homeState +
1434                                    "</" +
1435                                    WEBDAV_TAG_HOME_STATE +
1436                                    ">\n" );
1437        }
1438
1439        if (homePostalCode != null) {
1440            homePostalCode = StringTools.escapeXml(homePostalCode);
1441            webDavContactMsg.append("<" +
1442                                    WEBDAV_TAG_HOME_POSTALCODE +
1443                                    ">" +
1444                                    homePostalCode +
1445                                    "</" +
1446                                    WEBDAV_TAG_HOME_POSTALCODE +
1447                                    ">\n" );
1448        }
1449
1450        if (homePostOfficeBox != null) {
1451            homePostOfficeBox = StringTools.escapeXml(homePostOfficeBox);
1452            webDavContactMsg.append("<" +
1453                                    WEBDAVTAG_HOME_POST_OFFICE_BOX +
1454                                    ">" +
1455                                    homePostOfficeBox +
1456                                    "</" +
1457                                    WEBDAVTAG_HOME_POST_OFFICE_BOX +
1458                                    ">\n" );
1459        }
1460
1461        if (homeCountry != null) {
1462            homeCountry = StringTools.escapeXml(homeCountry);
1463            webDavContactMsg.append("<" +
1464                                    WEBDAV_TAG_HOME_COUNTRY +
1465                                    ">" +
1466                                    homeCountry +
1467                                    "</" +
1468                                    WEBDAV_TAG_HOME_COUNTRY +
1469                                    ">\n" );
1470        }
1471
1472        if (officeStreet != null) {
1473            officeStreet = StringTools.escapeXml(officeStreet);
1474            webDavContactMsg.append("<" +
1475                                    WEBDAV_TAG_WORK_STREET +
1476                                    ">" +
1477                                    officeStreet +
1478                                    "</" +
1479                                    WEBDAV_TAG_WORK_STREET +
1480                                    ">\n" );
1481        }
1482
1483        if (officeCity != null) {
1484            officeCity = StringTools.escapeXml(officeCity);
1485            webDavContactMsg.append("<" +
1486                                    WEBDAV_TAG_WORK_CITY +
1487                                    ">" +
1488                                    officeCity +
1489                                    "</" +
1490                                    WEBDAV_TAG_WORK_CITY +
1491                                    ">\n" );
1492        }
1493
1494        if (officeState != null) {
1495            officeState = StringTools.escapeXml(officeState);
1496            webDavContactMsg.append("<" +
1497                                    WEBDAV_TAG_WORK_STATE +
1498                                    ">" +
1499                                    officeState +
1500                                    "</" +
1501                                    WEBDAV_TAG_WORK_STATE +
1502                                    ">\n" );
1503        }
1504
1505        if (officePostalCode != null) {
1506            officePostalCode = StringTools.escapeXml(officePostalCode);
1507            webDavContactMsg.append("<" +
1508                                    WEBDAV_TAG_WORK_POSTALCODE +
1509                                    ">" +
1510                                    officePostalCode +
1511                                    "</" +
1512                                    WEBDAV_TAG_WORK_POSTALCODE +
1513                                    ">\n" );
1514        }
1515
1516        if (officePostOfficeBox != null) {
1517            officePostOfficeBox = StringTools.escapeXml(officePostOfficeBox);
1518            webDavContactMsg.append("<" +
1519                                    WEBDAV_TAG_WORK_POST_OFFICE_BOX +
1520                                    ">" +
1521                                    officePostOfficeBox +
1522                                    "</" +
1523                                    WEBDAV_TAG_WORK_POST_OFFICE_BOX +
1524                                    ">\n" );
1525        }
1526
1527        if (officeCountry != null) {
1528            officeCountry = StringTools.escapeXml(officeCountry);
1529            webDavContactMsg.append("<" +
1530                                    WEBDAV_TAG_WORK_COUNTRY +
1531                                    ">" +
1532                                    officeCountry +
1533                                    "</" +
1534                                    WEBDAV_TAG_WORK_COUNTRY +
1535                                    ">\n" );
1536        }
1537
1538        if (otherStreet != null) {
1539            otherStreet = StringTools.escapeXml(otherStreet);
1540            webDavContactMsg.append("<" +
1541                                    WEBDAV_TAG_OTHER_STREET +
1542                                    ">" +
1543                                    otherStreet +
1544                                    "</" +
1545                                    WEBDAV_TAG_OTHER_STREET +
1546                                    ">\n" );
1547        }
1548
1549        if (otherCity != null) {
1550            otherCity = StringTools.escapeXml(otherCity);
1551            webDavContactMsg.append("<" +
1552                                    WEBDAV_TAG_OTHER_CITY +
1553                                    ">" +
1554                                    otherCity +
1555                                    "</" +
1556                                    WEBDAV_TAG_OTHER_CITY +
1557                                    ">\n" );
1558        }
1559
1560        if (otherState != null) {
1561            otherState = StringTools.escapeXml(otherState);
1562            webDavContactMsg.append("<" +
1563                                    WEBDAV_TAG_OTHER_STATE +
1564                                    ">" +
1565                                    otherState +
1566                                    "</" +
1567                                    WEBDAV_TAG_OTHER_STATE +
1568                                    ">\n" );
1569        }
1570
1571        if (otherPostalCode != null) {
1572            otherPostalCode = StringTools.escapeXml(otherPostalCode);
1573            webDavContactMsg.append("<" +
1574                                    WEBDAV_TAG_OTHER_POSTALCODE +
1575                                    ">" +
1576                                    otherPostalCode +
1577                                    "</" +
1578                                    WEBDAV_TAG_OTHER_POSTALCODE +
1579                                    ">\n" );
1580        }
1581
1582        if (otherPostOfficeBox != null) {
1583            otherPostOfficeBox = StringTools.escapeXml(otherPostOfficeBox);
1584            webDavContactMsg.append("<" +
1585                                    WEBDAV_TAG_OTHER_POST_OFFICE_BOX +
1586                                    ">" +
1587                                    otherPostOfficeBox +
1588                                    "</" +
1589                                    WEBDAV_TAG_OTHER_POST_OFFICE_BOX +
1590                                    ">\n" );
1591        }
1592
1593
1594        if (otherCountry != null) {
1595            otherCountry = StringTools.escapeXml(otherCountry);
1596            webDavContactMsg.append("<" +
1597                                    WEBDAV_TAG_OTHER_COUNTRY +
1598                                    ">" +
1599                                    otherCountry +
1600                                    "</" +
1601                                    WEBDAV_TAG_OTHER_COUNTRY +
1602                                    ">\n" );
1603        }
1604
1605        if (officePhone != null) {
1606            officePhone = StringTools.escapeXml(officePhone);
1607            webDavContactMsg.append("<" +
1608                                    WEBDAV_TAG_WORK_PHONE +
1609                                    ">" +
1610                                    officePhone +
1611                                    "</" +
1612                                    WEBDAV_TAG_WORK_PHONE +
1613                                    ">\n" );
1614        }
1615
1616        if (homePhone != null) {
1617            homePhone = StringTools.escapeXml(homePhone);
1618            webDavContactMsg.append("<" +
1619                                    WEBDAV_TAG_HOME_PHONE +
1620                                    ">" +
1621                                    homePhone +
1622                                    "</" +
1623                                    WEBDAV_TAG_HOME_PHONE +
1624                                    ">\n" );
1625        }
1626
1627        if (mobilePhone != null) {
1628            mobilePhone = StringTools.escapeXml(mobilePhone);
1629            webDavContactMsg.append("<" +
1630                                    WEBDAV_TAG_MOBILE_PHONE +
1631                                    ">" +
1632                                    mobilePhone +
1633                                    "</" +
1634                                    WEBDAV_TAG_MOBILE_PHONE +
1635                                    ">\n" );
1636        }
1637
1638        if (assistantPhone != null) {
1639            assistantPhone = StringTools.escapeXml(assistantPhone);
1640            webDavContactMsg.append("<" +
1641                                    WEBDAV_TAG_ASSISTANT_PHONE +
1642                                    ">" +
1643                                    assistantPhone +
1644                                    "</" +
1645                                    WEBDAV_TAG_ASSISTANT_PHONE +
1646                                    ">\n" );
1647        }
1648
1649        if (officeOtherPhone != null) {
1650            officeOtherPhone = StringTools.escapeXml(officeOtherPhone);
1651            webDavContactMsg.append("<" +
1652                                    WEBDAV_TAG_WORK_OTHER_PHONE +
1653                                    ">" +
1654                                    officeOtherPhone +
1655                                    "</" +
1656                                    WEBDAV_TAG_WORK_OTHER_PHONE +
1657                                    ">\n" );
1658        }
1659
1660        if (officeFax != null) {
1661            officeFax = StringTools.escapeXml(officeFax);
1662            webDavContactMsg.append("<" +
1663                                    WEBDAV_TAG_WORK_FAX +
1664                                    ">" +
1665                                    officeFax +
1666                                    "</" +
1667                                    WEBDAV_TAG_WORK_FAX +
1668                                    ">\n" );
1669        }
1670
1671        if (callBackPhone != null) {
1672            callBackPhone = StringTools.escapeXml(callBackPhone);
1673            webDavContactMsg.append("<" +
1674                                    WEBDAV_TAG_CALLBACK_PHONE +
1675                                    ">" +
1676                                    callBackPhone +
1677                                    "</" +
1678                                    WEBDAV_TAG_CALLBACK_PHONE +
1679                                    ">\n" );
1680        }
1681
1682        if (mobileOtherPhone != null) {
1683            mobileOtherPhone = StringTools.escapeXml(mobileOtherPhone);
1684            webDavContactMsg.append("<" +
1685                                    WEBDAV_TAG_MOBILE_OTHER_PHONE +
1686                                    ">" +
1687                                    mobileOtherPhone +
1688                                    "</" +
1689                                    WEBDAV_TAG_MOBILE_OTHER_PHONE +
1690                                    ">\n" );
1691        }
1692
1693
1694        if (organizationPhone != null) {
1695            organizationPhone = StringTools.escapeXml(organizationPhone);
1696            webDavContactMsg.append("<" +
1697                                    WEBDAV_TAG_COMPANY_PHONE +
1698                                    ">" +
1699                                    organizationPhone +
1700                                    "</" +
1701                                    WEBDAV_TAG_COMPANY_PHONE +
1702                                    ">\n" );
1703        }
1704
1705        if (homeOtherPhone != null) {
1706            homeOtherPhone = StringTools.escapeXml(homeOtherPhone);
1707            webDavContactMsg.append("<" +
1708                                    WEBDAV_TAG_HOME_OTHER_PHONE +
1709                                    ">" +
1710                                    homeOtherPhone +
1711                                    "</" +
1712                                    WEBDAV_TAG_HOME_OTHER_PHONE +
1713                                    ">\n" );
1714        }
1715
1716        if (homeFax != null) {
1717            homeFax = StringTools.escapeXml(homeFax);
1718            webDavContactMsg.append("<" +
1719                                    WEBDAV_TAG_HOME_FAX +
1720                                    ">" +
1721                                    homeFax +
1722                                    "</" +
1723                                    WEBDAV_TAG_HOME_FAX +
1724                                    ">\n" );
1725        }
1726
1727        if (otherPhone != null) {
1728            otherPhone = StringTools.escapeXml(otherPhone);
1729            webDavContactMsg.append("<" +
1730                                    WEBDAV_TAG_OTHER_PHONE +
1731                                    ">" +
1732                                    otherPhone +
1733                                    "</" +
1734                                    WEBDAV_TAG_OTHER_PHONE +
1735                                    ">\n" );
1736        }
1737
1738        if (otherFax != null) {
1739            otherFax = StringTools.escapeXml(otherFax);
1740            webDavContactMsg.append("<" +
1741                                    WEBDAV_TAG_OTHER_FAX +
1742                                    ">" +
1743                                    otherFax +
1744                                    "</" +
1745                                    WEBDAV_TAG_OTHER_FAX +
1746                                    ">\n" );
1747        }
1748
1749        if (pager != null) {
1750            pager = StringTools.escapeXml(pager);
1751            webDavContactMsg.append("<" +
1752                                    WEBDAV_TAG_PAGER +
1753                                    ">" +
1754                                    pager +
1755                                    "</" +
1756                                    WEBDAV_TAG_PAGER +
1757                                    ">\n" );
1758        }
1759
1760        if (department != null) {
1761            department = StringTools.escapeXml(department);
1762            webDavContactMsg.append("<" +
1763                                    WEBDAV_TAG_DEPARTMENT +
1764                                    ">" +
1765                                    department +
1766                                    "</" +
1767                                    WEBDAV_TAG_DEPARTMENT +
1768                                    ">\n" );
1769        }
1770
1771        if (profession != null) {
1772            profession = StringTools.escapeXml(profession);
1773            webDavContactMsg.append("<" +
1774                                    WEBDAV_TAG_PROFESSION +
1775                                    ">" +
1776                                    profession +
1777                                    "</" +
1778                                    WEBDAV_TAG_PROFESSION +
1779                                    ">\n" );
1780        }
1781
1782        if (nickName != null) {
1783            nickName = StringTools.escapeXml(nickName);
1784            webDavContactMsg.append("<" +
1785                                    WEBDAV_TAG_NICKNAME +
1786                                    ">" +
1787                                    nickName +
1788                                    "</" +
1789                                    WEBDAV_TAG_NICKNAME +
1790                                    ">\n" );
1791        }
1792
1793        if (spouse != null) {
1794            spouse = StringTools.escapeXml(spouse);
1795            webDavContactMsg.append("<" +
1796                                    WEBDAV_TAG_SPOUSE +
1797                                    ">" +
1798                                    spouse +
1799                                    "</" +
1800                                    WEBDAV_TAG_SPOUSE +
1801                                    ">\n" );
1802        }
1803
1804        if (manager != null) {
1805            manager = StringTools.escapeXml(manager);
1806            webDavContactMsg.append("<" +
1807                                    WEBDAV_TAG_MANAGER +
1808                                    ">" +
1809                                    manager +
1810                                    "</" +
1811                                    WEBDAV_TAG_MANAGER +
1812                                    ">\n" );
1813        }
1814
1815        if (assistant != null) {
1816            assistant = StringTools.escapeXml(assistant);
1817            webDavContactMsg.append("<" +
1818                                    WEBDAV_TAG_ASSISTANT +
1819                                    ">" +
1820                                    assistant +
1821                                    "</" +
1822                                    WEBDAV_TAG_ASSISTANT +
1823                                    ">\n" );
1824        }
1825
1826        if (personalHomePage != null) {
1827            personalHomePage = StringTools.escapeXml(personalHomePage);
1828            webDavContactMsg.append("<" +
1829                                    WEBDAV_TAG_PERSONAL_HOME_PAGE +
1830                                    ">" +
1831                                    personalHomePage +
1832                                    "</" +
1833                                    WEBDAV_TAG_PERSONAL_HOME_PAGE +
1834                                    ">\n" );
1835        }
1836
1837        if (businessHomePage != null) {
1838            businessHomePage = StringTools.escapeXml(businessHomePage);
1839            webDavContactMsg.append("<" +
1840                                    WEBDAV_TAG_BUSINESS_HOME_PAGE +
1841                                    ">" +
1842                                    businessHomePage +
1843                                    "</" +
1844                                    WEBDAV_TAG_BUSINESS_HOME_PAGE +
1845                                    ">\n" );
1846        }
1847
1848        if (emailAddress1 != null) {
1849            emailAddress1 = StringTools.escapeXml(emailAddress1);
1850            webDavContactMsg.append("<" +
1851                                    WEBDAV_TAG_EMAIL1 +
1852                                    ">" +
1853                                    emailAddress1 +
1854                                    "</" +
1855                                    WEBDAV_TAG_EMAIL1 +
1856                                    ">\n" );
1857
1858            webDavContactMsg.append("<" +
1859                                    WEBDAV_TAG_EMAIL1_ADDRESS_TYPE +
1860                                    ">" +
1861                                    FIELD_TYPE_EMAIL1_ADDRESS +
1862                                    "</" +
1863                                    WEBDAV_TAG_EMAIL1_ADDRESS_TYPE +
1864                                    ">\n" );
1865        }
1866
1867        if (emailAddress2 != null) {
1868            emailAddress2 = StringTools.escapeXml(emailAddress2);
1869            webDavContactMsg.append("<" +
1870                                    WEBDAV_TAG_EMAIL2 +
1871                                    ">" +
1872                                    emailAddress2 +
1873                                    "</" +
1874                                    WEBDAV_TAG_EMAIL2 +
1875                                    ">\n" );
1876
1877            webDavContactMsg.append("<" +
1878                                    WEBDAV_TAG_EMAIL2_ADDRESS_TYPE +
1879                                    ">" +
1880                                    FIELD_TYPE_EMAIL2_ADDRESS +
1881                                    "</" +
1882                                    WEBDAV_TAG_EMAIL2_ADDRESS_TYPE +
1883                                    ">\n" );
1884
1885        }
1886
1887        if (emailAddress3 != null) {
1888            emailAddress3 = StringTools.escapeXml(emailAddress3);
1889            webDavContactMsg.append("<" +
1890                                    WEBDAV_TAG_EMAIL3 +
1891                                    ">" +
1892                                    emailAddress3 +
1893                                    "</" +
1894                                    WEBDAV_TAG_EMAIL3 +
1895                                    ">\n" );
1896
1897            webDavContactMsg.append("<" +
1898                                    WEBDAV_TAG_EMAIL3_ADDRESS_TYPE +
1899                                    ">" +
1900                                    FIELD_TYPE_EMAIL3_ADDRESS +
1901                                    "</" +
1902                                    WEBDAV_TAG_EMAIL3_ADDRESS_TYPE +
1903                                    ">\n" );
1904        }
1905
1906        webDavContactMsg.append("</D:prop>\n" +
1907                                "</D:set>\n" +
1908                                "</D:propertyupdate>" ); ;
1909
1910
1911        webDavHeaderMsg
1912            = MessageFormat.format(ItemDAO.WEBDAV_HEADER_PROPPATCH,
1913                new Object JavaDoc[] {
1914                        "/" +
1915                        server +
1916                        "/" +
1917                        username +
1918                        "/" +
1919                        resource ,
1920                        c.getHref()
1921              }
1922        );
1923
1924
1925        try {
1926             response = this.webDavHttp.sendRequest(webDavHeaderMsg ,
1927                                                    credentials ,
1928                                                    webDavContactMsg.toString() ,
1929                                                    FILE_ENCODING );
1930        } catch (IOException JavaDoc e) {
1931             throw new DataAccessException("Error getting Exchange server response",
1932                                            e);
1933        }
1934
1935        try {
1936            int s = getStatusFromResponse(response);
1937            checkResponseStatus(s);
1938        } catch (Exception JavaDoc e) {
1939
1940            throw new DataAccessException("USER " +
1941                                          username +
1942                                          " URI " +
1943                                          exchangeFolder +
1944                                          " setting exchange contact" ,
1945                                          e) ;
1946
1947        }
1948
1949        try {
1950            id = XmlParser.getRuidFromResponse(response);
1951        } catch (XmlParseException e) {
1952            throw new DataAccessException("Error getting resource id", e);
1953        }
1954
1955        c.setId(id);
1956
1957        return c;
1958
1959    }
1960
1961    /**
1962     * Delete a <i>Contact</i> from Exchange server.
1963     *
1964     * @param contact
1965     * @param username
1966     * @param credentials
1967     * @param exchangeFolder
1968     *
1969     * @throws sync4j.exchange.util.DataAccessException
1970     *
1971     */

1972    public void removeContact(Contact contact ,
1973                              String JavaDoc username ,
1974                              String JavaDoc credentials ,
1975                              String JavaDoc exchangeFolder)
1976    throws DataAccessException {
1977
1978        String JavaDoc webDavContactMsg = null ;
1979
1980        String JavaDoc webDavHeaderMsg = null ;
1981        String JavaDoc response = null ;
1982
1983        String JavaDoc server = null ;
1984        String JavaDoc resource = null ;
1985
1986        server = getServerFromExchangeFolder (exchangeFolder );
1987        resource = getResourceFromExchangeFolder (exchangeFolder );
1988
1989        webDavContactMsg = "" ;
1990
1991        webDavHeaderMsg =
1992            MessageFormat.format(ItemDAO.WEBDAV_HEADER_REMOVE,
1993            new Object JavaDoc[] {
1994                        "/" +
1995                            server +
1996                            "/" +
1997                            username +
1998                            "/" +
1999                            resource ,
2000                        contact.getHref()
2001            }
2002        );
2003
2004        try {
2005            response = this.webDavHttp.sendRequest(webDavHeaderMsg, credentials, webDavContactMsg, FILE_ENCODING);
2006        } catch (IOException JavaDoc e) {
2007            throw new DataAccessException("Error getting Exchange server response",
2008                                          e);
2009        }
2010
2011        try {
2012            int s = getStatusFromResponse(response);
2013            checkResponseStatus(s);
2014        } catch (Exception JavaDoc e) {
2015
2016            throw new DataAccessException("USER " +
2017                                          username +
2018                                          " URI " +
2019                                          exchangeFolder +
2020                                          " removing exchange contact" ,
2021                                          e) ;
2022
2023        }
2024    }
2025
2026    /**
2027     * get contacts from Exchange Server
2028     *
2029     * @param username
2030     * @param credentials
2031     * @param ids
2032     * @param exchangeFolder
2033     * @return array of find contacts
2034     *
2035     * @throws sync4j.exchange.util.DataAccessException
2036     **/

2037    public Contact[] getContacts (String JavaDoc username ,
2038                                  String JavaDoc credentials ,
2039                                  String JavaDoc[] ids ,
2040                                  String JavaDoc exchangeFolder)
2041        throws DataAccessException {
2042
2043        String JavaDoc clause = null ;
2044
2045        clause = getClause(ids);
2046
2047        return getContacts(username, credentials, clause, exchangeFolder);
2048
2049        }
2050
2051    /**
2052     * get contacts from Exchange Server
2053     *
2054     * @param username
2055     * @param credentials
2056     * @param fields
2057     * @param values
2058     * @param exchangeFolder
2059     * @return array of find contacts
2060     *
2061     * @throws sync4j.exchange.util.DataAccessException
2062     **/

2063    public Contact[] getContacts (String JavaDoc username ,
2064                                  String JavaDoc credentials ,
2065                                  String JavaDoc fields[] ,
2066                                  Object JavaDoc values[] ,
2067                                  String JavaDoc exchangeFolder)
2068    throws DataAccessException {
2069
2070        String JavaDoc clause = null;
2071
2072        clause = getClause(fields, values);
2073
2074        return getContacts(username, credentials, clause, exchangeFolder);
2075    }
2076
2077     //------------------------------------------------------------- Private methods
2078

2079    /**
2080     * Create a <i>Contact</i> array object from WebDav msg.
2081     *
2082     * @param id
2083     * @param webDavMsg
2084     *
2085     * @return a newly create <i>Calendar</i> object initialized with the
2086     * fields in the result set
2087     *
2088     */

2089    private Contact[] getContactsFromWebDavMsg(String JavaDoc webDavMsg)
2090    throws DataAccessException {
2091
2092        ArrayList JavaDoc contacts = null ;
2093        String JavaDoc [] resps = null ;
2094        String JavaDoc [] msg = null ;
2095
2096        String JavaDoc response = null ;
2097        String JavaDoc id = null ;
2098        String JavaDoc replUid = null ;
2099
2100        String JavaDoc isFolder = null ;
2101
2102        int count = 0 ;
2103
2104        msg = new String JavaDoc[] {webDavMsg};
2105
2106        contacts = new ArrayList JavaDoc();
2107
2108        try {
2109
2110            resps = XmlParser.getXMLTag(msg, TAG_RESPONSE);
2111
2112            for (int i = 0, l = resps.length; i < l; i++) {
2113
2114                response = resps[i] ;
2115                replUid = XmlParser.getXMLInitTagValue(response,
2116                                                        TAG_REPLUID) ;
2117
2118                id = getIdFromReplUid(replUid) ;
2119
2120                isFolder = XmlParser.getXMLInitTagValue(response,
2121                                                            TAG_IS_FOLDER) ;
2122
2123                if(PROP_NO_FOLDER.equals(isFolder)) {
2124                    contacts.add(getContactFromResponseTag(id, response));
2125                    count ++;
2126                }
2127
2128            }
2129
2130        } catch (XmlParseException e) {
2131            throw new DataAccessException("Error parsing contact", e);
2132        }
2133
2134        return (Contact[])contacts.toArray(new Contact[count]);
2135
2136    }
2137
2138    /**
2139     * Create a <i>Contact</i> object from response tag.
2140     *
2141     * @param id
2142     * @param msgResponse
2143     *
2144     * @return a newly create <i>Contact</i> object initialized with the
2145     * fields in the result set
2146     *
2147     */

2148    private Contact getContactFromResponseTag(String JavaDoc id, String JavaDoc msgResponse)
2149    throws DataAccessException {
2150
2151        Contact c = null ;
2152        String JavaDoc lastUpdate = null ;
2153
2154        String JavaDoc value = null ;
2155
2156        PersonalDetail personalDetail = null ;
2157        BusinessDetail businessDetail = null ;
2158        Address homeAddressBook = null ;
2159        Address workAddressBook = null ;
2160        Address otherAddressBook = null ;
2161
2162        Name name = null ;
2163        Title title = null ;
2164        Phone phone = null ;
2165        Email email = null ;
2166        WebPage webPage = null ;
2167
2168        List JavaDoc webPages = null ;
2169        List JavaDoc emails = null ;
2170        List JavaDoc webPagesBusiness = null ;
2171        List JavaDoc emailsBusiness = null ;
2172        List JavaDoc phonesPersonal = null ;
2173        List JavaDoc phonesBusiness = null ;
2174
2175        String JavaDoc response = null ;
2176
2177        StringBuffer JavaDoc webDavContactMsg = null ;
2178        String JavaDoc webDavHeaderMsg = null ;
2179
2180        String JavaDoc anniversary = null ;
2181        String JavaDoc birthday = null ;
2182        String JavaDoc categories = null ;
2183        String JavaDoc children = null ;
2184        String JavaDoc displayName = null ;
2185        String JavaDoc firstName = null ;
2186        String JavaDoc hobby = null ;
2187        String JavaDoc importance = null ;
2188        String JavaDoc initials = null ;
2189        String JavaDoc lastName = null ;
2190        String JavaDoc language = null ;
2191        String JavaDoc middleName = null ;
2192        String JavaDoc mileage = null ;
2193        String JavaDoc nickName = null ;
2194        String JavaDoc sensitivity = null ;
2195        String JavaDoc spouse = null ;
2196        String JavaDoc suffix = null ;
2197        String JavaDoc salutation = null ;
2198
2199        String JavaDoc yomiCompany = null ;
2200        String JavaDoc yomiFirstName = null ;
2201        String JavaDoc yomiLastName = null ;
2202
2203        String JavaDoc homeStreet = null ;
2204        String JavaDoc homeCity = null ;
2205        String JavaDoc homeState = null ;
2206        String JavaDoc homePostOfficeBox = null ;
2207        String JavaDoc homePostalCode = null ;
2208        String JavaDoc homeCountry = null ;
2209
2210        String JavaDoc officeStreet = null ;
2211        String JavaDoc officeCity = null ;
2212        String JavaDoc officeState = null ;
2213        String JavaDoc officeCountry = null ;
2214        String JavaDoc officePostalCode = null ;
2215        String JavaDoc officePostOfficeBox = null ;
2216
2217        String JavaDoc otherStreet = null ;
2218        String JavaDoc otherCity = null ;
2219        String JavaDoc otherState = null ;
2220        String JavaDoc otherPostalCode = null ;
2221        String JavaDoc otherPostOfficeBox = null ;
2222        String JavaDoc otherCountry = null ;
2223
2224        String JavaDoc assistantPhone = null ;
2225        String JavaDoc callBackPhone = null ;
2226        String JavaDoc homeFax = null ;
2227        String JavaDoc homePhone = null ;
2228        String JavaDoc homeOtherPhone = null ;
2229        String JavaDoc mobileOtherPhone = null ;
2230        String JavaDoc mobilePhone = null ;
2231        String JavaDoc officeFax = null ;
2232        String JavaDoc officeOtherPhone = null ;
2233        String JavaDoc officePhone = null ;
2234        String JavaDoc organizationPhone = null ;
2235        String JavaDoc otherFax = null ;
2236        String JavaDoc otherPhone = null ;
2237        String JavaDoc pager = null ;
2238        String JavaDoc telexNumber = null ;
2239
2240        String JavaDoc assistant = null ;
2241        String JavaDoc department = null ;
2242        String JavaDoc jobTitle = null ;
2243        String JavaDoc manager = null ;
2244        String JavaDoc officeLocation = null ;
2245        String JavaDoc organization = null ;
2246        String JavaDoc organizationIDNumber = null ;
2247        String JavaDoc profession = null ;
2248
2249        String JavaDoc emailAddress1 = null ;
2250        String JavaDoc emailAddress2 = null ;
2251        String JavaDoc emailAddress3 = null ;
2252        String JavaDoc email1AddressType = null ;
2253        String JavaDoc email2AddressType = null ;
2254        String JavaDoc email3AddressType = null ;
2255        String JavaDoc computerNetworkName = null ;
2256        String JavaDoc businessHomePage = null ;
2257        String JavaDoc personalHomePage = null ;
2258
2259        try {
2260
2261            anniversary = XmlParser.getXMLInitTagValue (
2262                            msgResponse,
2263                            TAG_ANNIVERSARY
2264                          );
2265
2266            birthday = XmlParser.getXMLInitTagValue (
2267                            msgResponse,
2268                            TAG_BIRTHDAY
2269                        );
2270
2271            categories
2272                        = XmlParser.getXMLInitTagValue (
2273                            msgResponse,
2274                            TAG_CATEGORIES
2275                          );
2276
2277            children
2278                        = XmlParser.getXMLInitTagValue (
2279                            msgResponse,
2280                            TAG_CHILDREN
2281                          );
2282
2283            displayName = XmlParser.getXMLInitTagValue (
2284                            msgResponse,
2285                            TAG_FILEAS
2286                          );
2287
2288            firstName = XmlParser.getXMLInitTagValue (
2289                            msgResponse,
2290                            TAG_FIRSTNAME
2291                        );
2292            hobby = XmlParser.getXMLInitTagValue (
2293                        msgResponse,
2294                        TAG_HOBBY
2295                    );
2296
2297            importance = XmlParser.getXMLInitTagValue (
2298                          msgResponse,
2299                          TAG_IMPORTANCE
2300                         );
2301
2302            initials = XmlParser.getXMLInitTagValue (
2303                        msgResponse,
2304                        TAG_INITIALS
2305                       );
2306
2307            language = XmlParser.getXMLInitTagValue (
2308                           msgResponse,
2309                           TAG_LANGUAGE
2310                       );
2311
2312            lastName = XmlParser.getXMLInitTagValue (
2313                            msgResponse,
2314                            TAG_LASTNAME
2315                        );
2316
2317            middleName = XmlParser.getXMLInitTagValue (
2318                            msgResponse,
2319                            TAG_MIDDLENAME
2320                         );
2321
2322            mileage
2323                        = XmlParser.getXMLInitTagValue (
2324                            msgResponse,
2325                            TAG_MILEAGE
2326            );
2327
2328            nickName = XmlParser.getXMLInitTagValue (
2329                        msgResponse,
2330                        TAG_NICKNAME
2331                       );
2332
2333            sensitivity
2334                        = XmlParser.getXMLInitTagValue (
2335                            msgResponse,
2336                            TAG_SENSITIVITY
2337                        );
2338
2339            spouse = XmlParser.getXMLInitTagValue (
2340                        msgResponse,
2341                        TAG_SPOUSECN
2342                     );
2343
2344            suffix = XmlParser.getXMLInitTagValue (
2345                            msgResponse,
2346                            TAG_SUFFIX
2347            );
2348
2349            salutation = XmlParser.getXMLInitTagValue (
2350                            msgResponse,
2351                            TAG_TITLE
2352            );
2353
2354
2355            homeStreet = XmlParser.getXMLInitTagValue (
2356                            msgResponse,
2357                            TAG_HOME_STREET
2358                          );
2359
2360            homeCity = XmlParser.getXMLInitTagValue (
2361                            msgResponse,
2362                            TAG_HOME_CITY
2363                       );
2364
2365            homeState = XmlParser.getXMLInitTagValue (
2366                            msgResponse,
2367                            TAG_HOME_STATE
2368                        );
2369
2370            homePostalCode = XmlParser.getXMLInitTagValue (
2371                                msgResponse,
2372                                TAG_HOME_POSTAL_CODE
2373                             );
2374
2375            homePostOfficeBox
2376                        = XmlParser.getXMLInitTagValue (
2377                            msgResponse,
2378                            TAG_HOME_POST_OFFICE_BOX
2379            );
2380
2381            homeCountry = XmlParser.getXMLInitTagValue (
2382                            msgResponse,
2383                            TAG_HOME_COUNTRY
2384                          );
2385
2386
2387            officeStreet = XmlParser.getXMLInitTagValue (
2388                            msgResponse,
2389                            TAG_WORK_STREET
2390                           );
2391
2392            officeCity = XmlParser.getXMLInitTagValue (
2393                            msgResponse,
2394                            TAG_WORK_CITY
2395                         );
2396
2397            officeState = XmlParser.getXMLInitTagValue (
2398                            msgResponse,
2399                            TAG_WORK_STATE
2400                          );
2401
2402            officePostalCode = XmlParser.getXMLInitTagValue (
2403                                msgResponse,
2404                                TAG_WORK_POSTALCODE
2405                               );
2406
2407            officePostOfficeBox
2408                            = XmlParser.getXMLInitTagValue (
2409                                msgResponse,
2410                                TAG_WORK_POST_OFFICE_BOX
2411                              );
2412
2413            officeCountry = XmlParser.getXMLInitTagValue (
2414                                msgResponse,
2415                                TAG_WORK_COUNTRY
2416                            );
2417
2418
2419            otherStreet = XmlParser.getXMLInitTagValue (
2420                            msgResponse,
2421                            TAG_OTHER_STREET
2422                          );
2423
2424            otherCity = XmlParser.getXMLInitTagValue (
2425                            msgResponse,
2426                            TAG_OTHER_CITY
2427                        );
2428
2429            otherState = XmlParser.getXMLInitTagValue (
2430                            msgResponse,
2431                            TAG_OTHER_STATE
2432                         );
2433
2434            otherPostalCode = XmlParser.getXMLInitTagValue (
2435                                msgResponse,
2436                                TAG_OTHER_POSTALCODE
2437                              );
2438
2439            otherPostOfficeBox
2440                        = XmlParser.getXMLInitTagValue (
2441                            msgResponse,
2442                            TAG_OTHER_POST_OFFICE_BOX
2443            );
2444
2445            otherCountry = XmlParser.getXMLInitTagValue (
2446                            msgResponse,
2447                            TAG_OTHER_COUNTRY
2448                           );
2449
2450
2451            assistant = XmlParser.getXMLInitTagValue (
2452                              msgResponse,
2453                              TAG_SECRETARY
2454                          );
2455
2456            department = XmlParser.getXMLInitTagValue (
2457                            msgResponse,
2458                            TAG_DEPARTMENT
2459                         );
2460
2461            jobTitle = XmlParser.getXMLInitTagValue (
2462                           msgResponse,
2463                           TAG_JOBTITLE
2464                       );
2465
2466            manager = XmlParser.getXMLInitTagValue (
2467                         msgResponse,
2468                         TAG_MANAGER
2469                       );
2470
2471            officeLocation
2472                        = XmlParser.getXMLInitTagValue (
2473                            msgResponse,
2474                            TAG_OFFICE_LOCATION
2475            );
2476
2477            organization = XmlParser.getXMLInitTagValue (
2478                                msgResponse,
2479                                TAG_ORGANIZATION
2480                            );
2481
2482            organizationIDNumber
2483                        = XmlParser.getXMLInitTagValue (
2484                            msgResponse,
2485                            TAG_ORGANIZATION_ID_NUMBER
2486            );
2487
2488            profession = XmlParser.getXMLInitTagValue (
2489                            msgResponse,
2490                            TAG_PROFESSION
2491                         );
2492
2493
2494            assistantPhone = XmlParser.getXMLInitTagValue (
2495                                 msgResponse,
2496                                 TAG_SECRETARY_PHONE
2497                              );
2498
2499
2500            callBackPhone = XmlParser.getXMLInitTagValue (
2501                                 msgResponse,
2502                                 TAG_CALL_BACK_PHONE
2503                             );
2504
2505
2506            homeFax = XmlParser.getXMLInitTagValue (
2507                        msgResponse,
2508                        TAG_HOME_FAX
2509                      );
2510
2511            homeOtherPhone = XmlParser.getXMLInitTagValue (
2512                                 msgResponse,
2513                                 TAG_HOME_PHONE2
2514                             );
2515
2516
2517            homePhone = XmlParser.getXMLInitTagValue (
2518                            msgResponse,
2519                            TAG_HOME_PHONE
2520                         );
2521
2522            mobileOtherPhone = XmlParser.getXMLInitTagValue (
2523                                msgResponse,
2524                                TAG_OTHER_MOBILE
2525                               );
2526
2527
2528            mobilePhone = XmlParser.getXMLInitTagValue (
2529                            msgResponse,
2530                            TAG_MOBILE
2531                          );
2532
2533            officeFax = XmlParser.getXMLInitTagValue (
2534                            msgResponse,
2535                            TAG_FAC_SIMILE_TELEPHONE_NUMBER
2536                        );
2537
2538
2539            officePhone = XmlParser.getXMLInitTagValue (
2540                             msgResponse,
2541                             TAG_TELEPHONE_NUMBER
2542                           );
2543
2544            officeOtherPhone = XmlParser.getXMLInitTagValue (
2545                                msgResponse,
2546                                TAG_TELEPHONE_NUMBER2
2547                               );
2548
2549            organizationPhone = XmlParser.getXMLInitTagValue (
2550                                    msgResponse,
2551                                    TAG_ORGANIZATION_MAIN_PHONE
2552                                );
2553
2554
2555            otherFax = XmlParser.getXMLInitTagValue (
2556                        msgResponse,
2557                        TAG_OTHER_FAX
2558                       );
2559
2560            otherPhone = XmlParser.getXMLInitTagValue (
2561                            msgResponse,
2562                            TAG_OTHER_TELEPHONE
2563                         );
2564
2565
2566            pager = XmlParser.getXMLInitTagValue (
2567                        msgResponse,
2568                        TAG_PAGER
2569                    );
2570
2571            telexNumber
2572                        = XmlParser.getXMLInitTagValue (
2573                            msgResponse,
2574                            TAG_TELEX_NUMBER
2575            );
2576
2577            value =
2578                XmlParser.getXMLInitTagValue (
2579                    msgResponse,
2580                    TAG_EMAIL1
2581                );
2582
2583            if (value != null && value.trim().length() > 0) {
2584
2585                value = value.replaceAll("&lt;", "<");
2586                value = value.replaceAll("&gt;", ">");
2587
2588                if (value.indexOf("<") != -1 && value.indexOf(">") != -1) {
2589
2590                    emailAddress1 = value.substring(value.indexOf("<") + 1,
2591                                                    value.indexOf(">"));
2592                } else {
2593                    emailAddress1 = value;
2594                }
2595
2596            }
2597
2598            value =
2599                XmlParser.getXMLInitTagValue (
2600                    msgResponse,
2601                    TAG_EMAIL2
2602                );
2603
2604            if (value != null && value.trim().length() > 0) {
2605
2606                value = value.replaceAll("&lt;", "<");
2607                value = value.replaceAll("&gt;", ">");
2608
2609                if (value.indexOf("<") != -1 && value.indexOf(">") != -1) {
2610
2611                    emailAddress2 = value.substring(value.indexOf("<") + 1,
2612                                                        value.indexOf(">"));
2613                } else {
2614                    emailAddress2 = value;
2615
2616                }
2617            }
2618
2619            value =
2620                XmlParser.getXMLInitTagValue (
2621                    msgResponse,
2622                    TAG_EMAIL3
2623                );
2624
2625            if (value != null && value.trim().length() > 0) {
2626
2627                value = value.replaceAll("&lt;", "<");
2628                value = value.replaceAll("&gt;", ">");
2629
2630                if (value.indexOf("<") != -1 && value.indexOf(">") != -1) {
2631
2632                    emailAddress3 = value.substring(value.indexOf("<") + 1,
2633                                                        value.indexOf(">"));
2634                } else {
2635                    emailAddress3 = value;
2636
2637                }
2638            }
2639
2640            email1AddressType
2641                = XmlParser.getXMLInitTagValue (
2642                    msgResponse,
2643                    TAG_EMAIL1_ADDRESS_TYPE
2644                );
2645
2646            email2AddressType
2647                = XmlParser.getXMLInitTagValue (
2648                    msgResponse,
2649                    TAG_EMAIL2_ADDRESS_TYPE
2650                );
2651
2652            email3AddressType
2653                = XmlParser.getXMLInitTagValue (
2654                    msgResponse,
2655                    TAG_EMAIL3_ADDRESS_TYPE
2656                );
2657
2658            businessHomePage = XmlParser.getXMLInitTagValue (
2659                                msgResponse,
2660                                TAG_BUSINESS_HOME_PAGE
2661                             );
2662
2663            personalHomePage
2664                        = XmlParser.getXMLInitTagValue (
2665                            msgResponse,
2666                            TAG_PERSONAL_HOME_PAGE
2667            );
2668
2669            computerNetworkName
2670                        = XmlParser.getXMLInitTagValue (
2671                            msgResponse,
2672                            TAG_COMPUTER_NETWORK_NAME
2673            );
2674
2675            lastUpdate =
2676                XmlParser.getXMLInitTagValue(msgResponse,
2677                TAG_LAST_MODIFIED);
2678
2679            c = new Contact(id, XmlParser.webDavTagToDate(lastUpdate));
2680
2681            if (firstName != null) {
2682                c.getName().getFirstName().setPropertyValue(firstName);
2683            }
2684
2685            if (lastName != null) {
2686                c.getName().getLastName().setPropertyValue(lastName);
2687            }
2688
2689            if (middleName != null) {
2690                c.getName().getMiddleName().setPropertyValue(middleName);
2691            }
2692
2693            if (nickName != null) {
2694                c.getName().getNickname().setPropertyValue(nickName);
2695            }
2696
2697            if (displayName != null) {
2698                c.getName().getDisplayName().setPropertyValue(displayName);
2699            }
2700
2701            if (suffix != null) {
2702                c.getName().getSuffix().setPropertyValue(suffix);
2703            }
2704
2705            if (importance != null) {
2706                c.setImportance(new Short JavaDoc(importance));
2707            }
2708
2709            if (initials != null) {
2710                c.getName().getInitials().setPropertyValue(initials);
2711            }
2712
2713            if (categories != null) {
2714                c.setCategories(XmlParser.getFieldFromMultipleTag(categories));
2715            }
2716
2717            if (salutation != null) {
2718                c.getName().getSalutation().setPropertyValue(salutation);
2719            }
2720
2721            if (mileage != null) {
2722                c.setMileage(new Integer JavaDoc (mileage));
2723            }
2724
2725            if (sensitivity != null) {
2726                c.setSensitivity(new Short JavaDoc(sensitivity));
2727            }
2728
2729            if (jobTitle != null) {
2730                title = new Title();
2731                title.setTitleType(FIELD_TYPE_JOB_TITLE);
2732                title.setPropertyValue(jobTitle);
2733                c.getBusinessDetail().addTitle(title);
2734            }
2735
2736            if (organization != null) {
2737                c.getBusinessDetail().getCompany().setPropertyValue(organization);
2738            }
2739
2740            if (department != null) {
2741                c.getBusinessDetail().getDepartment().setPropertyValue(department);
2742            }
2743
2744            if (profession != null) {
2745                c.getBusinessDetail().getRole().setPropertyValue(profession);
2746            }
2747
2748            if (anniversary != null) {
2749                c.getPersonalDetail().
2750                    setAnniversary(XmlParser.
2751                        webDavToPDIAnniversary(anniversary));
2752            }
2753
2754            if (birthday != null) {
2755                c.getPersonalDetail().
2756                    setBirthday(XmlParser.
2757                        webDavToPDIAnniversary(birthday));
2758            }
2759
2760            if (children != null) {
2761                c.getPersonalDetail().
2762                    setChildren(XmlParser.
2763                        getFieldFromMultipleTag(children));
2764            }
2765
2766            if (hobby != null) {
2767                c.getPersonalDetail().setHobbies(hobby);
2768            }
2769
2770            if (language != null) {
2771                c.setLanguages(language);
2772            }
2773
2774            if (spouse != null) {
2775                c.getPersonalDetail().setSpouse(spouse);
2776            }
2777
2778            if (manager != null) {
2779                c.getBusinessDetail().setManager(manager);
2780            }
2781
2782            if (assistant != null) {
2783                c.getBusinessDetail().setAssistant(assistant);
2784            }
2785
2786            if (officeLocation != null) {
2787                c.getBusinessDetail().setOfficeLocation(officeLocation);
2788            }
2789
2790            if (officePhone != null) {
2791                phone = new Phone();
2792                phone.setPhoneType(FIELD_TYPE_BUSINESS_TELEPHONE_NUMBER);
2793                phone.setPropertyValue(officePhone);
2794                c.getBusinessDetail().addPhone(phone);
2795            }
2796
2797            if (homePhone != null) {
2798                phone = new Phone();
2799                phone.setPhoneType(FIELD_TYPE_HOME_TELEPHONE_NUMBER);
2800                phone.setPropertyValue(homePhone);
2801                c.getPersonalDetail().addPhone(phone);
2802            }
2803
2804            if (mobilePhone != null) {
2805                phone = new Phone();
2806                phone.setPhoneType(FIELD_TYPE_MOBILE_TELEPHONE_NUMBER);
2807                phone.setPropertyValue(mobilePhone);
2808                c.getPersonalDetail().addPhone(phone);
2809            }
2810
2811            if (assistantPhone != null) {
2812                phone = new Phone();
2813                phone.setPhoneType(FIELD_TYPE_ASSISTANT_NUMBER);
2814                phone.setPropertyValue(assistantPhone);
2815                c.getBusinessDetail().addPhone(phone);
2816            }
2817
2818            if (officeOtherPhone != null) {
2819                phone = new Phone();
2820                phone.setPhoneType(FIELD_TYPE_BUSINESS_OTHER_TELEPHONE_NUMBER);
2821                phone.setPropertyValue(officeOtherPhone);
2822                c.getBusinessDetail().addPhone(phone);
2823            }
2824
2825            if (officeFax != null) {
2826                phone = new Phone();
2827                phone.setPhoneType(FIELD_TYPE_BUSINESS_FAX_NUMBER);
2828                phone.setPropertyValue(officeFax);
2829                c.getBusinessDetail().addPhone(phone);
2830            }
2831
2832            if (callBackPhone != null) {
2833                phone = new Phone();
2834                phone.setPhoneType(FIELD_TYPE_CALLBACK_NUMBER);
2835                phone.setPropertyValue(callBackPhone);
2836                c.getBusinessDetail().addPhone(phone);
2837            }
2838
2839            if (mobileOtherPhone != null) {
2840                phone = new Phone();
2841                phone.setPhoneType(FIELD_TYPE_CAR_TELEPHONE_NUMBER);
2842                phone.setPropertyValue(mobileOtherPhone);
2843                c.getPersonalDetail().addPhone(phone);
2844            }
2845
2846            if (organizationPhone != null) {
2847                phone = new Phone();
2848                phone.setPhoneType(FIELD_TYPE_COMPANY_MAIN_TELEPHONE_NUMBER);
2849                phone.setPropertyValue(organizationPhone);
2850                c.getBusinessDetail().addPhone(phone);
2851            }
2852
2853            if (homeOtherPhone != null) {
2854                phone = new Phone();
2855                phone.setPhoneType(FIELD_TYPE_HOME_OTHER_TELEPHONE_NUMBER);
2856                phone.setPropertyValue(homeOtherPhone);
2857                c.getBusinessDetail().addPhone(phone);
2858            }
2859
2860            if (homeFax != null) {
2861                phone = new Phone();
2862                phone.setPhoneType(FIELD_TYPE_HOME_FAX_NUMBER);
2863                phone.setPropertyValue(homeFax);
2864                c.getBusinessDetail().addPhone(phone);
2865            }
2866
2867            if (otherPhone != null) {
2868                phone = new Phone();
2869                phone.setPhoneType(FIELD_TYPE_OTHER_TELEPHONE_NUMBER);
2870                phone.setPropertyValue(otherPhone);
2871                c.getBusinessDetail().addPhone(phone);
2872            }
2873
2874            if (otherFax != null) {
2875                phone = new Phone();
2876                phone.setPhoneType(FIELD_TYPE_OTHER_FAX_NUMBER);
2877                phone.setPropertyValue(otherFax);
2878                c.getBusinessDetail().addPhone(phone);
2879            }
2880
2881            if (pager != null) {
2882                phone = new Phone();
2883                phone.setPhoneType(FIELD_TYPE_PAGER_NUMBER);
2884                phone.setPropertyValue(pager);
2885                c.getBusinessDetail().addPhone(phone);
2886            }
2887
2888            if (businessHomePage != null) {
2889                webPage = new WebPage();
2890                webPage.setWebPageType(FIELD_TYPE_BUSINESS_HOME_PAGE);
2891                webPage.setPropertyValue(businessHomePage);
2892                c.getBusinessDetail().addWebPage(webPage);
2893            }
2894
2895            if (personalHomePage != null) {
2896                webPage = new WebPage();
2897                webPage.setWebPageType(FIELD_TYPE_PERSONAL_HOME_PAGE);
2898                webPage.setPropertyValue(personalHomePage);
2899                c.getPersonalDetail().addWebPage(webPage);
2900            }
2901
2902            if (emailAddress1 != null) {
2903                email = new Email();
2904                email.setEmailType(FIELD_TYPE_EMAIL1_ADDRESS);
2905                email.setPropertyValue(emailAddress1);
2906                c.getPersonalDetail().addEmail(email);
2907            }
2908
2909            if (emailAddress2 != null) {
2910                email = new Email();
2911                email.setEmailType(FIELD_TYPE_EMAIL2_ADDRESS);
2912                email.setPropertyValue(emailAddress2);
2913                c.getPersonalDetail().addEmail(email);
2914            }
2915
2916            if (emailAddress3 != null) {
2917                email = new Email();
2918                email.setEmailType(FIELD_TYPE_EMAIL3_ADDRESS);
2919                email.setPropertyValue(emailAddress3);
2920                c.getPersonalDetail().addEmail(email);
2921            }
2922
2923            if (homeStreet != null) {
2924                c.getPersonalDetail().getAddress().
2925                                        getStreet().
2926                                            setPropertyValue(homeStreet);
2927            }
2928
2929            if (homeCity != null) {
2930                c.getPersonalDetail().getAddress().
2931                                        getCity().
2932                                            setPropertyValue(homeCity);
2933            }
2934
2935            if (homeState != null) {
2936                c.getPersonalDetail().getAddress().
2937                                        getState().
2938                                            setPropertyValue(homeState);
2939            }
2940
2941            if (homePostalCode != null) {
2942                c.getPersonalDetail().getAddress().
2943                                        getPostalCode().
2944                                            setPropertyValue(homePostalCode);
2945            }
2946
2947            if (homePostOfficeBox != null) {
2948                c.getPersonalDetail().getAddress().
2949                                        getPostOfficeAddress().
2950                                            setPropertyValue(homePostOfficeBox);
2951            }
2952
2953            if (homeCountry != null) {
2954                c.getPersonalDetail().getAddress().
2955                                        getCountry().
2956                                            setPropertyValue(homeCountry);
2957            }
2958
2959
2960            if (otherStreet != null) {
2961                c.getPersonalDetail().getOtherAddress().
2962                                        getStreet().
2963                                            setPropertyValue(otherStreet);
2964            }
2965
2966            if (otherCity != null) {
2967                c.getPersonalDetail().getOtherAddress().
2968                                        getCity().
2969                                            setPropertyValue(otherCity);
2970            }
2971
2972            if (otherState != null) {
2973                c.getPersonalDetail().getOtherAddress().
2974                                        getState().
2975                                            setPropertyValue(otherState);
2976            }
2977
2978            if (otherPostalCode != null) {
2979                c.getPersonalDetail().getOtherAddress().
2980                                        getPostalCode().
2981                                            setPropertyValue(otherPostalCode);
2982            }
2983
2984            if (homePostOfficeBox != null) {
2985                c.getPersonalDetail().getOtherAddress().
2986                                        getPostOfficeAddress().
2987                                            setPropertyValue(homePostOfficeBox);
2988            }
2989
2990
2991            if (otherCountry != null) {
2992                c.getPersonalDetail().getOtherAddress().
2993                                        getCountry().
2994                                            setPropertyValue(otherCountry);
2995            }
2996
2997
2998            if (officeStreet != null) {
2999                c.getBusinessDetail().getAddress().
3000                                        getStreet().
3001                                            setPropertyValue(officeStreet);
3002            }
3003
3004            if (officeCity != null) {
3005                c.getBusinessDetail().getAddress().
3006                                        getCity().
3007                                            setPropertyValue(officeCity);
3008            }
3009
3010            if (officeState != null) {
3011                c.getBusinessDetail().getAddress().
3012                                        getState().
3013                                            setPropertyValue(officeState);
3014            }
3015
3016            if (officePostalCode != null) {
3017                c.getBusinessDetail().getAddress().
3018                                        getPostalCode().
3019                                            setPropertyValue(officePostalCode);
3020            }
3021
3022            if (officePostOfficeBox != null) {
3023                c.getBusinessDetail().getAddress().
3024                                        getPostOfficeAddress().
3025                                            setPropertyValue(officePostOfficeBox);
3026            }
3027
3028            if (officeCountry != null) {
3029                c.getBusinessDetail().getAddress().
3030                                        getCountry().
3031                                            setPropertyValue(officeCountry);
3032            }
3033
3034
3035
3036        } catch (Exception JavaDoc e) {
3037            throw new DataAccessException("Error parsing contact item", e);
3038        }
3039
3040        return c;
3041
3042    }
3043
3044
3045    /**
3046     * get contacts from Exchange Server with the given clause
3047     *
3048     * @param username
3049     * @param credentials
3050     * @param clause
3051     * @param exchangeFolder
3052     * @return array of find contacts
3053     *
3054     * @throws sync4j.exchange.util.DataAccessException
3055     **/

3056    private Contact[] getContacts (String JavaDoc username ,
3057                                   String JavaDoc credentials ,
3058                                   String JavaDoc clause ,
3059                                   String JavaDoc exchangeFolder)
3060            throws DataAccessException {
3061
3062        Contact[] exchangeContacts = null ;
3063
3064        String JavaDoc response = null ;
3065        String JavaDoc webDavContactMsg = null ;
3066        String JavaDoc webDavHeaderMsg = null ;
3067
3068        String JavaDoc server = null ;
3069        String JavaDoc resource = null ;
3070
3071        server = getServerFromExchangeFolder (exchangeFolder );
3072        resource = getResourceFromExchangeFolder (exchangeFolder );
3073
3074        webDavContactMsg =
3075            MessageFormat.format(WEBDAV_MSG_SELECT_CONTACTS,
3076            new Object JavaDoc[] {server, username, resource, clause});
3077
3078        webDavHeaderMsg =
3079            MessageFormat.format(ItemDAO.WEBDAV_HEADER_SELECT,
3080
3081            new Object JavaDoc[] {
3082                        "/" +
3083                            server +
3084                            "/" +
3085                            username +
3086                            "/" +
3087                        resource
3088
3089            }
3090        );
3091
3092
3093        try {
3094             response = this.webDavHttp.sendRequest(webDavHeaderMsg, credentials, webDavContactMsg, FILE_ENCODING);
3095        } catch (IOException JavaDoc e) {
3096             throw new DataAccessException("Error getting Exchange server response",
3097                                           e);
3098        }
3099
3100        try {
3101            int s = getStatusFromResponse(response);
3102            checkResponseStatus(s);
3103        } catch (Exception JavaDoc e) {
3104
3105            throw new DataAccessException("USER " +
3106                                          username +
3107                                          " URI " +
3108                                          exchangeFolder +
3109                                          " getting Exchange contact" ,
3110                                          e) ;
3111
3112        }
3113
3114        exchangeContacts = getContactsFromWebDavMsg(response);
3115
3116        return exchangeContacts;
3117
3118    }
3119
3120    /**
3121     * Build a clause
3122     * to webdav select request
3123     * between ids item array
3124     *
3125     * @param ids
3126     * @return webdav select clause
3127     **/

3128    private static String JavaDoc getClause (String JavaDoc[] fields, Object JavaDoc[] values) {
3129
3130        StringBuffer JavaDoc clause = new StringBuffer JavaDoc();
3131
3132        int l = fields.length;
3133
3134        if (l == 0) {
3135            return "";
3136        }
3137
3138        clause.append("where ");
3139
3140        StringBuffer JavaDoc tmp = null;
3141        String JavaDoc valueTmp = null;
3142
3143        for (int i = 0; i < l; i++) {
3144            tmp = new StringBuffer JavaDoc();
3145            valueTmp = String.valueOf(values[i]);
3146            valueTmp = valueTmp.replaceAll("'", "''");
3147            valueTmp = StringTools.escapeXml(valueTmp);
3148
3149            if (valueTmp == null || "null".equals(valueTmp)) {
3150                valueTmp = "";
3151            }
3152
3153            if (TAG_FIRSTNAME.equals(fields[i])) {
3154                tmp.append("\"").append(FIELD_PREFIX).append("givenName\"");
3155                if (!valueTmp.equals("")) {
3156                    tmp.append("='").append(valueTmp).append("'");
3157                } else {
3158                    tmp.append(" is null ");
3159                }
3160            }
3161
3162            if (TAG_LASTNAME.equals(fields[i])) {
3163                tmp.append("\"").append(FIELD_PREFIX).append("sn\"");
3164                if (!valueTmp.equals("")) {
3165                    tmp.append("='").append(valueTmp).append("'");
3166                } else {
3167                    tmp.append(" is null ");
3168                }
3169            }
3170
3171            if (TAG_MIDDLENAME.equals(fields[i])) {
3172                tmp.append("\"").append(FIELD_PREFIX).append("middlename\"");
3173                if (!valueTmp.equals("")) {
3174                    tmp.append("='").append(valueTmp).append("'");
3175                } else {
3176                    tmp.append(" is null ");
3177                }
3178            }
3179
3180            if (TAG_EMAIL1.equals(fields[i])) {
3181                tmp.append("\"").append(FIELD_PREFIX).append("email1\"");
3182                if (!valueTmp.equals("")) {
3183                    tmp.append("='").append(valueTmp).append("'");
3184                } else {
3185                    tmp.append(" is null ");
3186                }
3187            }
3188
3189            if (i != 0 && tmp.length() != 0) {
3190                clause.append(" and ").append(tmp);
3191            } else if (tmp.length() != 0) {
3192                clause.append(tmp);
3193            }
3194
3195        }
3196
3197        clause.append("\r\n");
3198
3199        return clause.toString();
3200
3201    }
3202
3203}
3204
Popular Tags