Search in sources :

Example 81 with DataForm

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;
}
Also used : User(org.jivesoftware.openfire.user.User) HashMap(java.util.HashMap) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) IQ(org.xmpp.packet.IQ)

Aggregations

DataForm (org.xmpp.forms.DataForm)81 FormField (org.xmpp.forms.FormField)67 Element (org.dom4j.Element)23 IQ (org.xmpp.packet.IQ)12 JID (org.xmpp.packet.JID)9 ArrayList (java.util.ArrayList)7 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 HashMap (java.util.HashMap)4 List (java.util.List)4 Group (org.jivesoftware.openfire.group.Group)4 Date (java.util.Date)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 XStream (com.thoughtworks.xstream.XStream)2 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 PacketException (org.jivesoftware.openfire.PacketException)2 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2