Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebDAV for Exchange
>
Tutorial
> Search for contacts in public folder
This example shows you how to search for contacts, from a public folder.
import java.util.ArrayList; import java.util.List; import com.independentsoft.webdav.exchange.ContactPropertyName; import com.independentsoft.webdav.exchange.Condition; import com.independentsoft.webdav.exchange.ContentClassType; import com.independentsoft.webdav.exchange.From; import com.independentsoft.webdav.exchange.MultiStatus; import com.independentsoft.webdav.exchange.Operator; import com.independentsoft.webdav.exchange.Property; import com.independentsoft.webdav.exchange.PropertyName; import com.independentsoft.webdav.exchange.SearchResult; import com.independentsoft.webdav.exchange.SearchResultRecord; import com.independentsoft.webdav.exchange.Select; import com.independentsoft.webdav.exchange.SqlQuery; import com.independentsoft.webdav.exchange.WebdavClient; import com.independentsoft.webdav.exchange.WebdavException; import com.independentsoft.webdav.exchange.Where; public class Example { public static void main(final String[] args) { try { WebdavClient client = new WebdavClient("https://myserver/exchange/emailaddress", "username", "password"); String publicFolderUrl = "https://myserver/public/Test"; List
propertyNames = new ArrayList
(); propertyNames.add(ContactPropertyName.CONTENT_CLASS); propertyNames.add(ContactPropertyName.GIVEN_NAME); propertyNames.add(ContactPropertyName.EMAIL1); propertyNames.add(ContactPropertyName.ORGANIZATION); propertyNames.add(ContactPropertyName.DEPARTMENT); propertyNames.add(ContactPropertyName.TELEPHONE_NUMBER); Select select = new Select(propertyNames); From from = new From(publicFolderUrl); Where where = new Where(); Condition condition1 = new Condition(ContactPropertyName.CONTENT_CLASS, Operator.EQUALS, ContentClassType.PERSON); where.add(condition1); SqlQuery sqlQuery = new SqlQuery(select, from, where); MultiStatus multiStatus = client.search(publicFolderUrl, sqlQuery); SearchResult searchResult = new SearchResult(multiStatus, propertyNames); SearchResultRecord[] allRecords = searchResult.getRecords(); for (int i = 0; i < allRecords.length; i++) { System.out.println("Contact URL=" + allRecords[i].getUrl()); Property[] property = allRecords[i].getProperties(); System.out.println("ContentClass=" + property[0].getValue()); System.out.println("GivenName=" + property[1].getValue()); System.out.println("Email1=" + property[2].getValue()); System.out.println("Organization=" + property[3].getValue()); System.out.println("Department=" + property[4].getValue()); System.out.println("Phone=" + property[5].getValue()); } } catch (WebdavException e) { e.printStackTrace(); } } }