SearchToList.java
01 package com.bigllc.retsiq.examples;
02 
03 import java.net.MalformedURLException;
04 import java.util.Arrays;
05 import java.util.List;
06 
07 import com.bigllc.retsiq.simpleclient.RETSClientException;
08 import com.bigllc.retsiq.simpleclient.RETSConnection;
09 import com.bigllc.retsiq.simpleclient.RETSUserSession;
10 import com.bigllc.retsiq.simpleclient.RecordCollectionResponseHandler;
11 import com.bigllc.retsiq.simpleclient.SearchRecord;
12 
13 /**
14  * Example to demonstrate how to search for records and parse them in
15  * memory. The example will also limit the search to certain fields 
16  * and limited number of records. 
17  
18  @author Marc G. Smith
19  */
20 public class SearchToList 
21 {
22   public static void main(String[] argsthrows MalformedURLException 
23   {
24     String loginurl   = "http://rets.server.com/rets/login";
25     String username   = "username";
26     String password   = "password";
27     String path     = "/Agents/Agents";
28     String query     = "(UIDOFFICE=OFFICE1)";
29     int limit      = 10;
30     
31     // Create the connection class
32     RETSConnection connection = new RETSConnection(loginurl);
33     RETSUserSession session = null;
34     
35     try {
36       // Authenticate the user and get session
37       session = connection.getSession(username, password);
38       
39       // Create the output handler. This is a handler that
40       // creates a list of all the records.
41       RecordCollectionResponseHandler handler = 
42         new RecordCollectionResponseHandler();
43       
44       // Select only a few of the available fields
45       List<String> select = Arrays.asList(new String[] {
46         "UID""UIDOFFICE""FULLNAME"  
47       });
48       
49       // Execute the search
50       session.search(path, query, select, limit, 0, handler);
51       
52       // Print out the headers
53       for(String column: handler.getColumns()) {
54         System.out.print(column + "\t");
55       }
56       System.out.println();
57       
58       // Iterate through all the records and print out all 
59       // all the values.
60       for(SearchRecord record: handler.getRecords()) {
61         for(String field: record.getAllValues()) {
62           System.out.print(field + "\t");
63         }
64         System.out.println();
65       }
66     }
67     catch(RETSClientException e) {
68       System.err.println(e.getMessage());
69     }
70     finally {
71       if(session != null) { 
72         try {
73           session.logout()
74         
75         catch(RETSClientException e) {
76           System.err.println(e.getMessage());
77         }
78       }
79     }
80   }
81 }