powered by Jive Software

Finding a user using his Email

Hi,

Is it possible to get the full JID of a user after proceding a search on his email, and how ?

Thx

I’'d like to know how to do this also.

The code sample in the UserSearchManager javadoc is obsolete, and no longer compiles:

XMPPConnection con = new XMPPConnection(“jabber.org”);

con.login(“john”, “doe”);

UserSearchManager search = new UserSearchManager(con, “users.jabber.org”);

Form searchForm = search.getSearchForm();

Form answerForm = searchForm.createAnswerForm();

answerForm.setAnswer(“last”, “DeMoro”);

ReportedData data = search.getSearchResults(answerForm);

Hi Guys,

Below is an simple example of how to use the search manager using Smack 3.0.x and Openfire with the latest version of the search plugin. You’‘ll notice I’‘ve hardcoded some of the variables (such as the search service url) and didn’'t put the results into any sort of table to keep the code somewhat reasonable in length.

Enjoy,

Ryan

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.ReportedData;
import org.jivesoftware.smackx.ReportedData.Column;
import org.jivesoftware.smackx.ReportedData.Row;
import org.jivesoftware.smackx.search.UserSearchManager; import java.util.Iterator; public class SearchSample {
   private static String DOMAIN = "example.org";
      public static void main(String[] args) {
      try {
         XMPPConnection con = new XMPPConnection(DOMAIN);
         con.connect();
         con.login("test", "test");
         UserSearchManager search = new UserSearchManager(con);
         Form searchForm = search.getSearchForm("search." + DOMAIN);
                  System.out.println("Available search fields:");
         Iterator<FormField> fields = searchForm.getFields();
         while (fields.hasNext()) {
            FormField field = fields.next();
            System.out.println(field.getVariable() + " : " + field.getType());
         }
                  Form answerForm = searchForm.createAnswerForm();
         answerForm.setAnswer("search", "ryan");
         answerForm.setAnswer("Email", true);
                  ReportedData data = search.getSearchResults(answerForm, "search." + DOMAIN);
                  System.out.println("\nColumns that are included as part of the search results:");
         Iterator<Column> columns = data.getColumns();
         while (columns.hasNext()) {
            System.out.println(columns.next().getVariable());
         }
                  System.out.println("\nThe jids from our each of our hits:");
         Iterator<Row> rows = data.getRows();
         while (rows.hasNext()) {
            Row row = rows.next();
                        Iterator<String> jids = row.getValues("jid");
            while (jids.hasNext()) {
               System.out.println(jids.next());
            }
         }
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}