Search in sources :

Example 76 with DataForm

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

the class UserProperties 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");
    List<String> accounts = data.getData().get("accountjids");
    if (accounts != null && accounts.size() > 0) {
        populateResponseFields(form, accounts);
    }
    command.add(form.getElement());
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 77 with DataForm

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

the class GroupDeleting method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Dispatching a deleting group event.");
    form.addInstruction("Fill out this form to dispatch a deleting group event.");
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("The group name of the group that is being deleted");
    field.setVariable("groupName");
    field.setRequired(true);
    // Add the form to the command
    command.add(form.getElement());
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 78 with DataForm

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

the class GroupMemberAdded method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Dispatching a group member added event.");
    form.addInstruction("Fill out this form to dispatch a group member added event.");
    FormField field = form.addField();
    field.setType(FormField.Type.hidden);
    field.setVariable("FORM_TYPE");
    field.addValue("http://jabber.org/protocol/admin");
    field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("The group name of the group");
    field.setVariable("groupName");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Member");
    field.setVariable("member");
    field.setRequired(true);
    // Add the form to the command
    command.add(form.getElement());
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 79 with DataForm

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

the class IQMUCRegisterHandler method handleIQ.

public IQ handleIQ(IQ packet) {
    IQ reply = null;
    // Get the target room
    MUCRoom room = null;
    String name = packet.getTo().getNode();
    if (name != null) {
        room = mucService.getChatRoom(name);
    }
    if (room == null) {
        // The room doesn't exist so answer a NOT_FOUND error
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
        return reply;
    } else if (!room.isRegistrationEnabled() || (packet.getFrom() != null && MUCRole.Affiliation.outcast == room.getAffiliation(packet.getFrom().asBareJID()))) {
        // The room does not accept users to register or
        // the user is an outcast and is not allowed to register
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.not_allowed);
        return reply;
    }
    if (IQ.Type.get == packet.getType()) {
        reply = IQ.createResultIQ(packet);
        String nickname = room.getReservedNickname(packet.getFrom());
        Element currentRegistration = probeResult.createCopy();
        if (nickname != null) {
            // The user is already registered with the room so answer a completed form
            ElementUtil.setProperty(currentRegistration, "query.registered", null);
            currentRegistration.addElement("username").addText(nickname);
            Element form = currentRegistration.element(QName.get("x", "jabber:x:data"));
            currentRegistration.remove(form);
            //                @SuppressWarnings("unchecked")
            //				Iterator<Element> fields = form.elementIterator("field");
            //
            //                Element field;
            //                while (fields.hasNext()) {
            //                    field = fields.next();
            //                    if ("muc#register_roomnick".equals(field.attributeValue("var"))) {
            //                        field.addElement("value").addText(nickname);
            //                    }
            //                }
            reply.setChildElement(currentRegistration);
        } else {
            // The user is not registered with the room so answer an empty form
            reply.setChildElement(currentRegistration);
        }
    } else if (IQ.Type.set == packet.getType()) {
        try {
            // Keep a registry of the updated presences
            List<Presence> presences = new ArrayList<>();
            reply = IQ.createResultIQ(packet);
            Element iq = packet.getChildElement();
            if (ElementUtil.includesProperty(iq, "query.remove")) {
                // The user is deleting his registration
                presences.addAll(room.addNone(packet.getFrom(), room.getRole()));
            } else {
                // The user is trying to register with a room
                Element formElement = iq.element("x");
                // Check if a form was used to provide the registration info
                if (formElement != null) {
                    // Get the sent form
                    final DataForm registrationForm = new DataForm(formElement);
                    // Get the desired nickname sent in the form
                    List<String> values = registrationForm.getField("muc#register_roomnick").getValues();
                    String nickname = (!values.isEmpty() ? values.get(0) : null);
                    // TODO The rest of the fields of the form are ignored. If we have a
                    // requirement in the future where we need those fields we'll have to change
                    // MUCRoom.addMember in order to receive a RegistrationInfo (new class)
                    // Add the new member to the members list
                    presences.addAll(room.addMember(packet.getFrom(), nickname, room.getRole()));
                } else {
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(PacketError.Condition.bad_request);
                }
            }
            // Send the updated presences to the room occupants
            for (Presence presence : presences) {
                room.send(presence);
            }
        } catch (ForbiddenException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.forbidden);
        } catch (ConflictException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.conflict);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    return reply;
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ConflictException(org.jivesoftware.openfire.muc.ConflictException) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) Presence(org.xmpp.packet.Presence) ArrayList(java.util.ArrayList) List(java.util.List) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) ConflictException(org.jivesoftware.openfire.muc.ConflictException)

Example 80 with DataForm

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

the class IQMUCSearchHandler method getDataElement.

/**
	 * Utility method that returns a 'jabber:iq:search' child element filled
	 * with a blank dataform.
	 * 
	 * @return Element, named 'query', escaped by the 'jabber:iq:search'
	 *         namespace, filled with a blank dataform.
	 */
private static Element getDataElement() {
    final DataForm searchForm = new DataForm(DataForm.Type.form);
    searchForm.setTitle("Chat Rooms Search");
    searchForm.addInstruction("Instructions");
    final FormField typeFF = searchForm.addField();
    typeFF.setVariable("FORM_TYPE");
    typeFF.setType(FormField.Type.hidden);
    typeFF.addValue("jabber:iq:search");
    final FormField nameFF = searchForm.addField();
    nameFF.setVariable("name");
    nameFF.setType(FormField.Type.text_single);
    nameFF.setLabel("Name");
    nameFF.setRequired(false);
    final FormField matchFF = searchForm.addField();
    matchFF.setVariable("name_is_exact_match");
    matchFF.setType(FormField.Type.boolean_type);
    matchFF.setLabel("Name must match exactly");
    matchFF.setRequired(false);
    final FormField subjectFF = searchForm.addField();
    subjectFF.setVariable("subject");
    subjectFF.setType(FormField.Type.text_single);
    subjectFF.setLabel("Subject");
    subjectFF.setRequired(false);
    final FormField userAmountFF = searchForm.addField();
    userAmountFF.setVariable("num_users");
    userAmountFF.setType(FormField.Type.text_single);
    userAmountFF.setLabel("Number of users");
    userAmountFF.setRequired(false);
    final FormField maxUsersFF = searchForm.addField();
    maxUsersFF.setVariable("num_max_users");
    maxUsersFF.setType(FormField.Type.text_single);
    maxUsersFF.setLabel("Max number allowed of users");
    maxUsersFF.setRequired(false);
    final FormField includePasswordProtectedFF = searchForm.addField();
    includePasswordProtectedFF.setVariable("include_password_protected");
    includePasswordProtectedFF.setType(FormField.Type.boolean_type);
    includePasswordProtectedFF.setLabel("Include password protected rooms");
    includePasswordProtectedFF.setRequired(false);
    final Element probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:search"));
    probeResult.add(searchForm.getElement());
    return probeResult;
}
Also used : Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

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