GetObjectUrls.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.ObjectRecord;
08 import com.bigllc.retsiq.simpleclient.RETSClientException;
09 import com.bigllc.retsiq.simpleclient.RETSConnection;
10 import com.bigllc.retsiq.simpleclient.RETSUserSession;
11 import com.bigllc.retsiq.simpleclient.RecordCollectionResponseHandler;
12 import com.bigllc.retsiq.simpleclient.SearchRecord;
13 
14 /**
15  * Example to demonstrate how to get URL locations for objects. The
16  * example performs a search limited to 3 records and then fetches
17  * all the URLS for all the photos associated with those records. 
18  
19  @author Marc G. Smith
20  */
21 public class GetObjectUrls 
22 {
23   public static void main(String[] argsthrows MalformedURLException 
24   {
25     String loginurl   = "http://rets.server.com/rets/login";
26     String username   = "username";
27     String password   = "password";
28     String path     = "/Property/Residential";
29     String query     = "(LISTSTATUS=ACTIVE),(OFFICELIST=OFFICE1)";
30     String objectPath   = "/Property/Photo/";
31     int limit      = 3;
32 
33     // Create the connection class
34     RETSConnection connection = new RETSConnection(loginurl);
35     RETSUserSession session = null;
36     
37     try {
38       // Authenticate the user and get session
39       session = connection.getSession(username, password);
40       
41       // Create the output handler. This is a handler that
42       // creates a list of all the records.
43       RecordCollectionResponseHandler handler = 
44         new RecordCollectionResponseHandler();
45       
46       // Select only the UID for the listing.
47       List<String> select = Arrays.asList(new String[] {
48         "MLSNUM"  
49       });
50       
51       // Execute the search
52       session.search(path, query, select, limit, 0, handler);
53       
54       // Iterate through all the records.
55       for(SearchRecord record: handler.getRecords()) {
56         String uid = record.getValue("MLSNUM");
57         
58         // Create the object path for all the photo
59         // objects for the record
60         String objectFullPath = objectPath + uid + ":*";
61 
62         // Fetch the objects
63         List<ObjectRecord> objects = 
64           session.getObjectUrls(objectFullPath);
65         
66         
67         // Iterate through all the objects
68         System.out.println("Object URLS For MLSNUM " + uid);
69         System.out.println("----------------------------------");
70         for(ObjectRecord object: objects) {
71           System.out.println(object);
72         }
73         System.out.println();
74       }
75     }
76     catch(RETSClientException e) {
77       System.err.println(e.getMessage());
78     }
79     finally {
80       if(session != null) { 
81         try {
82           session.logout()
83         
84         catch(RETSClientException e) {
85           System.err.println(e.getMessage());
86         }
87       }
88     }
89   }
90 }