use of org.xmpp.forms.DataForm in project Openfire by igniterealtime.
the class SearchPlugin method replyDataFormResult.
/**
* Constructs a query that is returned as an IQ packet that contains the search results.
*
* @param users
* set of users that will be used to construct the search results
* @param packet
* the IQ packet sent by the client
* @return the iq packet that contains the search results
*/
private IQ replyDataFormResult(Collection<User> users, IQ packet) {
final DataForm searchResults = new DataForm(DataForm.Type.result);
searchResults.addField("FORM_TYPE", null, FormField.Type.hidden);
searchResults.addReportedField("jid", "JID", FormField.Type.jid_single);
for (final String fieldName : getFilteredSearchFields()) {
searchResults.addReportedField(fieldName, LocaleUtils.getLocalizedString("advance.user.search." + fieldName.toLowerCase(), "search"), FormField.Type.text_single);
}
for (final User user : users) {
final String username = JID.unescapeNode(user.getUsername());
final Map<String, Object> item = new HashMap<String, Object>();
item.put("jid", username + "@" + serverName);
item.put(LocaleUtils.getLocalizedString("advance.user.search.username", "search"), username);
item.put(LocaleUtils.getLocalizedString("advance.user.search.name", "search"), (user.isNameVisible() ? removeNull(user.getName()) : ""));
item.put(LocaleUtils.getLocalizedString("advance.user.search.email", "search"), (user.isEmailVisible() ? removeNull(user.getEmail()) : ""));
searchResults.addItemFields(item);
}
IQ replyPacket = IQ.createResultIQ(packet);
Element reply = replyPacket.setChildElement("query", NAMESPACE_JABBER_IQ_SEARCH);
reply.add(searchResults.getElement());
return replyPacket;
}
Aggregations