use of org.jivesoftware.smackx.ReportedData in project jitsi by jitsi.
the class OperationSetUserSearchJabberImpl method search.
/**
* Performs user search for the searched string and returns the JIDs of the
* found contacts.
*
* @param searchedString the text we want to query the server.
* @return the list of found JIDs
*/
public List<String> search(String searchedString) {
ReportedData data = null;
try {
data = searchManager.searchForString(searchedString);
} catch (XMPPException e) {
logger.error(e);
return null;
}
if (data == null) {
logger.error("No data have been received from server.");
return null;
}
Iterator<Column> columns = data.getColumns();
Iterator<Row> rows = data.getRows();
if (columns == null || rows == null) {
logger.error("The received data is corrupted.");
return null;
}
Column jidColumn = null;
while (columns.hasNext()) {
Column tmpCollumn = columns.next();
if (tmpCollumn.getType().equals(FormField.TYPE_JID_SINGLE)) {
jidColumn = tmpCollumn;
break;
}
}
if (jidColumn == null) {
logger.error("No jid collumn provided by the server.");
return null;
}
List<String> result = new ArrayList<String>();
while (rows.hasNext()) {
Row row = rows.next();
result.add((String) row.getValues(jidColumn.getVariable()).next());
}
return result;
}
use of org.jivesoftware.smackx.ReportedData in project ecf by eclipse.
the class SimpleUserSearch method parseItems.
protected void parseItems(XmlPullParser parser) throws Exception {
ReportedData data = new ReportedData();
data.addColumn(new ReportedData.Column("JID", "jid", "text-single"));
boolean done = false;
List<ReportedData.Field> fields = new ArrayList<ReportedData.Field>();
while (!done) {
if (parser.getAttributeCount() > 0) {
String jid = parser.getAttributeValue("", "jid");
List<String> valueList = new ArrayList<String>();
valueList.add(jid);
ReportedData.Field field = new ReportedData.Field("jid", valueList);
fields.add(field);
}
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("item")) {
fields = new ArrayList<ReportedData.Field>();
} else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("item")) {
ReportedData.Row row = new ReportedData.Row(fields);
data.addRow(row);
} else if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
String value = parser.nextText();
List<String> valueList = new ArrayList<String>();
valueList.add(value);
ReportedData.Field field = new ReportedData.Field(name, valueList);
fields.add(field);
boolean exists = false;
Iterator<ReportedData.Column> cols = data.getColumns();
while (cols.hasNext()) {
ReportedData.Column column = cols.next();
if (column.getVariable().equals(name)) {
exists = true;
}
}
// Column name should be the same
if (!exists) {
ReportedData.Column column = new ReportedData.Column(name, name, "text-single");
data.addColumn(column);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
this.data = data;
}
use of org.jivesoftware.smackx.ReportedData in project ecf by eclipse.
the class XMPPUserSearchManager method search.
/**
* Specific implementation for XMPP
*
* @see IUserSearchManager#search(ICriteria).
*/
public ISearch search(ICriteria criteria) throws UserSearchException {
ResultList resultList = new ResultList();
try {
// initialize the form by chance it is null
if (form == null)
form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
/*
* For XMPP criterion is considered. The XMPP server will deal with
* the search.
*/
List criterions = criteria.getCriterions();
// add the fields for the search dynamically
// consider just the fields used on the search
// fields checked by user
String[] fields = getUserPropertiesFields();
for (int i = 0; i < fields.length; i++) {
Iterator criterionsIterator = criterions.iterator();
// the partial result is added to the result list
while (criterionsIterator.hasNext()) {
ICriterion criterion = (ICriterion) criterionsIterator.next();
if (criterion.equals(fields[i])) {
Form answerForm = form.createAnswerForm();
answerForm.setAnswer(fields[i], true);
answerForm.setAnswer(SEARCH_ACTION, criterion.toExpression());
ReportedData data = manager.sendSearchForm(ecfConnection.getXMPPConnection(), answerForm, SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
// create a result list from ReportedData
IResultList partialResultList = createResultList(data);
resultList.addAll(partialResultList.getResults());
}
}
}
return new XMPPSearch(resultList);
} catch (final XMPPException e) {
String message = null;
if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
} else {
message = e.getLocalizedMessage();
}
throw new UserSearchException(message, e, criteria);
} catch (ECFException e) {
throw new UserSearchException(e, criteria);
}
}
use of org.jivesoftware.smackx.ReportedData in project jitsi by jitsi.
the class UserSearchProvider method parseItems.
/**
* Parses the items from the result packet.
* @param parser the parser.
* @return <tt>ReportedData</tt> instance with the search results.
* @throws Exception if parser error occurred.
*/
protected ReportedData parseItems(XmlPullParser parser) throws Exception {
ReportedData data = new ReportedData();
data.addColumn(new ReportedData.Column("JID", "jid", FormField.TYPE_JID_SINGLE));
boolean done = false;
List<ReportedData.Field> fields = new ArrayList<ReportedData.Field>();
while (!done) {
if (parser.getAttributeCount() > 0) {
String jid = parser.getAttributeValue("", "jid");
List<String> valueList = new ArrayList<String>();
valueList.add(jid);
ReportedData.Field field = new ReportedData.Field("jid", valueList);
fields.add(field);
}
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("item")) {
fields = new ArrayList<ReportedData.Field>();
} else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("item")) {
ReportedData.Row row = new ReportedData.Row(fields);
data.addRow(row);
} else if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
String value = parser.nextText();
List<String> valueList = new ArrayList<String>();
valueList.add(value);
ReportedData.Field field = new ReportedData.Field(name, valueList);
fields.add(field);
boolean exists = false;
Iterator<Column> cols = data.getColumns();
while (cols.hasNext()) {
ReportedData.Column column = cols.next();
if (column.getVariable().equals(name))
exists = true;
}
// Column name should be the same
if (!exists) {
ReportedData.Column column = new ReportedData.Column(name, name, "text-single");
data.addColumn(column);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query"))
done = true;
}
}
return data;
}
Aggregations