Search in sources :

Example 21 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class GetNumberActiveUsers method execute.

@Override
public void execute(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.result);
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setLabel(getLabel());
    field.setVariable("activeusersnum");
    // Make sure that we are only counting based on bareJIDs and not fullJIDs
    Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
    Set<String> users = new HashSet<>(sessions.size());
    for (ClientSession session : sessions) {
        if (session.getPresence().isAvailable()) {
            users.add(session.getAddress().toBareJID());
        }
    }
    field.addValue(users.size());
    command.add(form.getElement());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) HashSet(java.util.HashSet)

Example 22 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class GetNumberOnlineUsers method execute.

@Override
public void execute(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.result);
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setLabel(getLabel());
    field.setVariable("onlineusersnum");
    // Make sure that we are only counting based on bareJIDs and not fullJIDs
    Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
    Set<String> users = new HashSet<>(sessions.size());
    for (ClientSession session : sessions) {
        users.add(session.getAddress().toBareJID());
    }
    field.addValue(users.size());
    command.add(form.getElement());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) HashSet(java.util.HashSet)

Example 23 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class GetUsersPresence method execute.

@Override
public void execute(SessionData data, Element command) {
    String max_items = data.getData().get("max_items").get(0);
    int maxItems = -1;
    if (max_items != null && !"none".equals(max_items)) {
        try {
            maxItems = Integer.parseInt(max_items);
        } catch (NumberFormatException e) {
        // Do nothing. Assume that all users are being requested
        }
    }
    DataForm form = new DataForm(DataForm.Type.result);
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setLabel("The presences of active users");
    field.setVariable("activeuserpresences");
    // Get list of users (i.e. bareJIDs) that are connected to the server
    Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
    int index = 1;
    for (ClientSession session : sessions) {
        if (session.getPresence().isAvailable()) {
            field.addValue(session.getPresence().toXML());
        }
        if (maxItems > 0 && index >= maxItems) {
            break;
        }
    }
    command.add(form.getElement());
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 24 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class MultiUserChatServiceImpl method getExtendedInfo.

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
    if (name != null && node == null) {
        // Answer the extended info of a given room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            final DataForm dataForm = new DataForm(Type.result);
            final FormField fieldType = dataForm.addField();
            fieldType.setVariable("FORM_TYPE");
            fieldType.setType(FormField.Type.hidden);
            fieldType.addValue("http://jabber.org/protocol/muc#roominfo");
            final FormField fieldDescr = dataForm.addField();
            fieldDescr.setVariable("muc#roominfo_description");
            fieldDescr.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.desc"));
            fieldDescr.addValue(room.getDescription());
            final FormField fieldSubj = dataForm.addField();
            fieldSubj.setVariable("muc#roominfo_subject");
            fieldSubj.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.subject"));
            fieldSubj.addValue(room.getSubject());
            final FormField fieldOcc = dataForm.addField();
            fieldOcc.setVariable("muc#roominfo_occupants");
            fieldOcc.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.occupants"));
            fieldOcc.addValue(Integer.toString(room.getOccupantsCount()));
            /*field = new XFormFieldImpl("muc#roominfo_lang");
                field.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.language"));
                field.addValue(room.getLanguage());
                dataForm.addField(field);*/
            final FormField fieldDate = dataForm.addField();
            fieldDate.setVariable("x-muc#roominfo_creationdate");
            fieldDate.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.creationdate"));
            fieldDate.addValue(XMPPDateTimeFormat.format(room.getCreationDate()));
            return dataForm;
        }
    }
    return null;
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 25 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQChatSearchHandler method init.

private void init() {
    // Configure the search form that will be sent to the agents
    this.searchForm = new DataForm(DataForm.Type.form);
    this.searchForm.setTitle("Chat search");
    this.searchForm.addInstruction("Fill out this form to search for chats");
    // Add starting date
    FormField field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Starting Date");
    field.setVariable("date/start");
    // Add ending date
    field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Ending Date");
    field.setVariable("date/end");
    // Add workgroup JID
    field = this.searchForm.addField();
    field.setType(FormField.Type.jid_multi);
    field.setLabel("Workgroup");
    field.setVariable("workgroups");
    // Add agent JID
    field = this.searchForm.addField();
    field.setType(FormField.Type.jid_single);
    field.setLabel("Agent");
    field.setVariable("agent");
    // Add query string
    field = this.searchForm.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Search Terms");
    field.setVariable("queryString");
    field.setRequired(true);
    // Configure the form that will hold the search results
    this.resultForm = new DataForm(DataForm.Type.result);
    this.resultForm.addReportedField("workgroup", null, FormField.Type.jid_single);
    this.resultForm.addReportedField("sessionID", null, FormField.Type.text_single);
    this.resultForm.addReportedField("startDate", null, FormField.Type.text_single);
    this.resultForm.addReportedField("agentJIDs", null, FormField.Type.jid_multi);
    this.resultForm.addReportedField("relevance", null, FormField.Type.text_single);
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Aggregations

FormField (org.xmpp.forms.FormField)76 DataForm (org.xmpp.forms.DataForm)67 Element (org.dom4j.Element)16 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)9 IQ (org.xmpp.packet.IQ)7 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 Date (java.util.Date)4 List (java.util.List)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 Group (org.jivesoftware.openfire.group.Group)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 PacketException (org.jivesoftware.openfire.PacketException)2 GroupJID (org.jivesoftware.openfire.group.GroupJID)2 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2