2005-09-17 01:04:30 +02:00
|
|
|
/**
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
2007-09-27 01:14:51 +02:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2005-09-17 01:04:30 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2007-09-27 01:14:51 +02:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2005-09-17 01:04:30 +02:00
|
|
|
*
|
2007-09-27 01:14:51 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2005-09-17 01:04:30 +02:00
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.search;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-10 09:45:50 +01:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
|
|
|
import org.jivesoftware.smackx.xdata.Form;
|
2005-09-17 01:04:30 +02:00
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
2005-09-19 06:06:59 +02:00
|
|
|
|
|
|
|
/**
|
2014-06-14 11:45:38 +02:00
|
|
|
* The UserSearchManager is a facade built upon Jabber Search Services (XEP-055) to allow for searching
|
2005-09-19 06:06:59 +02:00
|
|
|
* repositories on a Jabber Server. This implementation allows for transparency of implementation of
|
|
|
|
* searching (DataForms or No DataForms), but allows the user to simply use the DataForm model for both
|
|
|
|
* types of support.
|
|
|
|
* <pre>
|
2014-04-09 12:16:44 +02:00
|
|
|
* XMPPConnection con = new XMPPTCPConnection("jabber.org");
|
2005-09-19 06:06:59 +02:00
|
|
|
* 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);
|
|
|
|
* // Use Returned Data
|
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @author Derek DeMoro
|
|
|
|
*/
|
2005-09-17 01:04:30 +02:00
|
|
|
public class UserSearchManager {
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private final XMPPConnection con;
|
|
|
|
private final UserSearch userSearch;
|
2005-09-17 01:04:30 +02:00
|
|
|
|
2005-09-19 06:06:59 +02:00
|
|
|
/**
|
|
|
|
* Creates a new UserSearchManager.
|
|
|
|
*
|
2014-03-10 09:45:50 +01:00
|
|
|
* @param con the XMPPConnection to use.
|
2005-09-19 06:06:59 +02:00
|
|
|
*/
|
2014-03-10 09:45:50 +01:00
|
|
|
public UserSearchManager(XMPPConnection con) {
|
2005-09-17 01:04:30 +02:00
|
|
|
this.con = con;
|
|
|
|
userSearch = new UserSearch();
|
|
|
|
}
|
|
|
|
|
2005-09-19 06:06:59 +02:00
|
|
|
/**
|
|
|
|
* Returns the form to fill out to perform a search.
|
|
|
|
*
|
2005-09-20 23:02:30 +02:00
|
|
|
* @param searchService the search service to query.
|
2005-09-19 06:06:59 +02:00
|
|
|
* @return the form to fill out to perform a search.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2005-09-19 06:06:59 +02:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Form getSearchForm(DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2005-09-19 06:06:59 +02:00
|
|
|
return userSearch.getSearchForm(con, searchService);
|
2005-09-17 01:04:30 +02:00
|
|
|
}
|
|
|
|
|
2005-09-19 06:06:59 +02:00
|
|
|
/**
|
|
|
|
* Submits a search form to the server and returns the resulting information
|
2015-03-29 12:15:32 +02:00
|
|
|
* in the form of <code>ReportedData</code>.
|
2005-09-19 06:06:59 +02:00
|
|
|
*
|
2006-09-14 17:19:39 +02:00
|
|
|
* @param searchForm the <code>Form</code> to submit for searching.
|
2005-09-20 23:02:30 +02:00
|
|
|
* @param searchService the name of the search service to use.
|
2005-09-19 06:06:59 +02:00
|
|
|
* @return the ReportedData returned by the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2005-09-19 06:06:59 +02:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public ReportedData getSearchResults(Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2005-09-19 06:06:59 +02:00
|
|
|
return userSearch.sendSearchForm(con, searchForm, searchService);
|
|
|
|
}
|
2005-09-17 01:04:30 +02:00
|
|
|
|
2005-09-20 23:02:30 +02:00
|
|
|
|
2005-09-19 06:06:59 +02:00
|
|
|
/**
|
|
|
|
* Returns a collection of search services found on the server.
|
|
|
|
*
|
|
|
|
* @return a Collection of search services found on the server.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @throws InterruptedException
|
2005-09-19 06:06:59 +02:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public List<DomainBareJid> getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2005-09-19 06:06:59 +02:00
|
|
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
|
2014-07-25 20:49:11 +02:00
|
|
|
return discoManager.findServices(UserSearch.NAMESPACE, false, false);
|
2005-09-17 01:04:30 +02:00
|
|
|
}
|
|
|
|
}
|