Search in sources :

Example 31 with FormField

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

the class LeafNode method addFormFields.

@Override
protected void addFormFields(DataForm form, boolean isEditing) {
    super.addFormFields(form, isEditing);
    FormField typeField = form.getField("pubsub#node_type");
    typeField.addValue("leaf");
    FormField formField = form.addField();
    formField.setVariable("pubsub#send_item_subscribe");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.send_item_subscribe"));
    }
    formField.addValue(sendItemSubscribe);
    formField = form.addField();
    formField.setVariable("pubsub#persist_items");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.persist_items"));
    }
    formField.addValue(persistPublishedItems);
    formField = form.addField();
    formField.setVariable("pubsub#max_items");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_items"));
    }
    formField.addValue(maxPublishedItems);
    formField = form.addField();
    formField.setVariable("pubsub#max_payload_size");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_payload_size"));
    }
    formField.addValue(maxPayloadSize);
}
Also used : FormField(org.xmpp.forms.FormField)

Example 32 with FormField

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

the class Node method configure.

/**
     * Changes the node configuration based on the completed data form. Only owners or
     * sysadmins are allowed to change the node configuration. The completed data form
     * cannot remove all node owners. An exception is going to be thrown if the new form
     * tries to leave the node without owners.
     *
     * @param completedForm the completed data form.
     * @throws NotAcceptableException if completed data form tries to leave the node without owners.
     */
public void configure(DataForm completedForm) throws NotAcceptableException {
    boolean wasPresenceBased = isPresenceBasedDelivery();
    if (DataForm.Type.cancel.equals(completedForm.getType())) {
    // Existing node configuration is applied (i.e. nothing is changed)
    } else if (DataForm.Type.submit.equals(completedForm.getType())) {
        List<String> values;
        String booleanValue;
        // Get the new list of owners
        FormField ownerField = completedForm.getField("pubsub#owner");
        boolean ownersSent = ownerField != null;
        List<JID> owners = new ArrayList<>();
        if (ownersSent) {
            for (String value : ownerField.getValues()) {
                try {
                    owners.add(new JID(value));
                } catch (Exception e) {
                // Do nothing
                }
            }
        }
        // Answer a not-acceptable error if all the current owners will be removed
        if (ownersSent && owners.isEmpty()) {
            throw new NotAcceptableException();
        }
        for (FormField field : completedForm.getFields()) {
            if ("FORM_TYPE".equals(field.getVariable())) {
            // Do nothing
            } else if ("pubsub#deliver_payloads".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                deliverPayloads = "1".equals(booleanValue);
            } else if ("pubsub#notify_config".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyConfigChanges = "1".equals(booleanValue);
            } else if ("pubsub#notify_delete".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyDelete = "1".equals(booleanValue);
            } else if ("pubsub#notify_retract".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyRetract = "1".equals(booleanValue);
            } else if ("pubsub#presence_based_delivery".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                presenceBasedDelivery = "1".equals(booleanValue);
            } else if ("pubsub#subscribe".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                subscriptionEnabled = "1".equals(booleanValue);
            } else if ("pubsub#subscription_required".equals(field.getVariable())) {
                // TODO Replace this variable for the one defined in the JEP (once one is defined)
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                subscriptionConfigurationRequired = "1".equals(booleanValue);
            } else if ("pubsub#type".equals(field.getVariable())) {
                values = field.getValues();
                payloadType = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#body_xslt".equals(field.getVariable())) {
                values = field.getValues();
                bodyXSLT = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#dataform_xslt".equals(field.getVariable())) {
                values = field.getValues();
                dataformXSLT = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#access_model".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    accessModel = AccessModel.valueOf(values.get(0));
                }
            } else if ("pubsub#publish_model".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    publisherModel = PublisherModel.valueOf(values.get(0));
                }
            } else if ("pubsub#roster_groups_allowed".equals(field.getVariable())) {
                // Get the new list of roster group(s) allowed to subscribe and retrieve items
                rosterGroupsAllowed = new ArrayList<>();
                for (String value : field.getValues()) {
                    addAllowedRosterGroup(value);
                }
            } else if ("pubsub#contact".equals(field.getVariable())) {
                // Get the new list of users that may be contacted with questions
                contacts = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addContact(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#description".equals(field.getVariable())) {
                values = field.getValues();
                description = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#language".equals(field.getVariable())) {
                values = field.getValues();
                language = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#title".equals(field.getVariable())) {
                values = field.getValues();
                name = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#itemreply".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    replyPolicy = ItemReplyPolicy.valueOf(values.get(0));
                }
            } else if ("pubsub#replyroom".equals(field.getVariable())) {
                // Get the new list of multi-user chat rooms to specify for replyroom
                replyRooms = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addReplyRoom(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#replyto".equals(field.getVariable())) {
                // Get the new list of JID(s) to specify for replyto
                replyTo = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addReplyTo(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#collection".equals(field.getVariable())) {
                // Set the parent collection node
                values = field.getValues();
                String newParent = values.size() > 0 ? values.get(0) : " ";
                Node newParentNode = service.getNode(newParent);
                if (!(newParentNode instanceof CollectionNode)) {
                    throw new NotAcceptableException("Specified node in field pubsub#collection [" + newParent + "] " + ((newParentNode == null) ? "does not exist" : "is not a collection node"));
                }
                changeParent((CollectionNode) newParentNode);
            } else {
                // Let subclasses be configured by specified fields
                configure(field);
            }
        }
        // Set new list of owners of the node
        if (ownersSent) {
            // Calculate owners to remove and remove them from the DB
            Collection<JID> oldOwners = getOwners();
            oldOwners.removeAll(owners);
            for (JID jid : oldOwners) {
                removeOwner(jid);
            }
            // Calculate new owners and add them to the DB
            owners.removeAll(getOwners());
            for (JID jid : owners) {
                addOwner(jid);
            }
        }
        // TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his subscriptions are not going to be deleted.
        // Set the new list of publishers
        FormField publisherField = completedForm.getField("pubsub#publisher");
        if (publisherField != null) {
            // New list of publishers was sent to update publishers of the node
            List<JID> publishers = new ArrayList<>();
            for (String value : publisherField.getValues()) {
                try {
                    publishers.add(new JID(value));
                } catch (Exception e) {
                // Do nothing
                }
            }
            // Calculate publishers to remove and remove them from the DB
            Collection<JID> oldPublishers = getPublishers();
            oldPublishers.removeAll(publishers);
            for (JID jid : oldPublishers) {
                removePublisher(jid);
            }
            // Calculate new publishers and add them to the DB
            publishers.removeAll(getPublishers());
            for (JID jid : publishers) {
                addPublisher(jid);
            }
        }
        // Let subclasses have a chance to finish node configuration based on
        // the completed form
        postConfigure(completedForm);
        // Update the modification date to reflect the last time when the node's configuration
        // was modified
        modificationDate = new Date();
        // Notify subscribers that the node configuration has changed
        nodeConfigurationChanged();
    }
    // Store the new or updated node in the backend store
    saveToDB();
    // Check if we need to subscribe or unsubscribe from affiliate presences
    if (wasPresenceBased != isPresenceBasedDelivery()) {
        if (isPresenceBasedDelivery()) {
            addPresenceSubscriptions();
        } else {
            cancelPresenceSubscriptions();
        }
    }
}
Also used : JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Date(java.util.Date) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FormField(org.xmpp.forms.FormField)

Example 33 with FormField

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

the class Node method getConfigurationChangeForm.

/**
     * Returns a data form with the node configuration. The returned data form is used for
     * notifying node subscribers that the node configuration has changed. The data form is
     * ony going to be included if node is configure to include payloads in event
     * notifications.
     *
     * @return a data form with the node configuration.
     */
private DataForm getConfigurationChangeForm() {
    DataForm form = new DataForm(DataForm.Type.result);
    FormField formField = form.addField();
    formField.setVariable("FORM_TYPE");
    formField.setType(FormField.Type.hidden);
    formField.addValue("http://jabber.org/protocol/pubsub#node_config");
    // Add the form fields and configure them for notification
    // (i.e. no label or options are included)
    addFormFields(form, false);
    return form;
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 34 with FormField

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

the class Node method getConfigurationForm.

/**
     * Returns a data form used by the owner to edit the node configuration.
     *
     * @return data form used by the owner to edit the node configuration.
     */
public DataForm getConfigurationForm() {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.conf.title"));
    List<String> params = new ArrayList<>();
    params.add(getNodeID());
    form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.conf.instruction", params));
    FormField formField = form.addField();
    formField.setVariable("FORM_TYPE");
    formField.setType(FormField.Type.hidden);
    formField.addValue("http://jabber.org/protocol/pubsub#node_config");
    // Add the form fields and configure them for edition
    addFormFields(form, true);
    return form;
}
Also used : DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FormField(org.xmpp.forms.FormField)

Example 35 with FormField

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

the class Node method addFormFields.

/**
     * Adds the required form fields to the specified form. When editing is true the field type
     * and a label is included in each fields. The form being completed will contain the current
     * node configuration. This information can be used for editing the node or for notifing that
     * the node configuration has changed.
     *
     * @param form the form containing the node configuration.
     * @param isEditing true when the form will be used to edit the node configuration.
     */
protected void addFormFields(DataForm form, boolean isEditing) {
    FormField formField = form.addField();
    formField.setVariable("pubsub#title");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.short_name"));
    }
    formField.addValue(name);
    formField = form.addField();
    formField.setVariable("pubsub#description");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.description"));
    }
    formField.addValue(description);
    formField = form.addField();
    formField.setVariable("pubsub#node_type");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.node_type"));
    }
    formField = form.addField();
    formField.setVariable("pubsub#collection");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.collection"));
    }
    if (parent != null && !parent.isRootCollectionNode()) {
        formField.addValue(parent.getNodeID());
    }
    formField = form.addField();
    formField.setVariable("pubsub#subscribe");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.subscribe"));
    }
    formField.addValue(subscriptionEnabled);
    formField = form.addField();
    formField.setVariable("pubsub#subscription_required");
    // TODO Replace this variable for the one defined in the JEP (once one is defined)
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.subscription_required"));
    }
    formField.addValue(subscriptionConfigurationRequired);
    formField = form.addField();
    formField.setVariable("pubsub#deliver_payloads");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.deliver_payloads"));
    }
    formField.addValue(deliverPayloads);
    formField = form.addField();
    formField.setVariable("pubsub#notify_config");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_config"));
    }
    formField.addValue(notifyConfigChanges);
    formField = form.addField();
    formField.setVariable("pubsub#notify_delete");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_delete"));
    }
    formField.addValue(notifyDelete);
    formField = form.addField();
    formField.setVariable("pubsub#notify_retract");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.notify_retract"));
    }
    formField.addValue(notifyRetract);
    formField = form.addField();
    formField.setVariable("pubsub#presence_based_delivery");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.presence_based"));
    }
    formField.addValue(presenceBasedDelivery);
    formField = form.addField();
    formField.setVariable("pubsub#type");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.type"));
    }
    formField.addValue(payloadType);
    formField = form.addField();
    formField.setVariable("pubsub#body_xslt");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.body_xslt"));
    }
    formField.addValue(bodyXSLT);
    formField = form.addField();
    formField.setVariable("pubsub#dataform_xslt");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.dataform_xslt"));
    }
    formField.addValue(dataformXSLT);
    formField = form.addField();
    formField.setVariable("pubsub#access_model");
    if (isEditing) {
        formField.setType(FormField.Type.list_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.access_model"));
        formField.addOption(null, AccessModel.authorize.getName());
        formField.addOption(null, AccessModel.open.getName());
        formField.addOption(null, AccessModel.presence.getName());
        formField.addOption(null, AccessModel.roster.getName());
        formField.addOption(null, AccessModel.whitelist.getName());
    }
    formField.addValue(accessModel.getName());
    formField = form.addField();
    formField.setVariable("pubsub#publish_model");
    if (isEditing) {
        formField.setType(FormField.Type.list_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.publish_model"));
        formField.addOption(null, PublisherModel.publishers.getName());
        formField.addOption(null, PublisherModel.subscribers.getName());
        formField.addOption(null, PublisherModel.open.getName());
    }
    formField.addValue(publisherModel.getName());
    formField = form.addField();
    formField.setVariable("pubsub#roster_groups_allowed");
    if (isEditing) {
        formField.setType(FormField.Type.list_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.roster_allowed"));
    }
    for (String group : rosterGroupsAllowed) {
        formField.addValue(group);
    }
    formField = form.addField();
    formField.setVariable("pubsub#contact");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.contact"));
    }
    for (JID contact : contacts) {
        formField.addValue(contact.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#language");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.language"));
    }
    formField.addValue(language);
    formField = form.addField();
    formField.setVariable("pubsub#owner");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.owner"));
    }
    for (JID owner : getOwners()) {
        formField.addValue(owner.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#publisher");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.publisher"));
    }
    for (JID owner : getPublishers()) {
        formField.addValue(owner.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#itemreply");
    if (isEditing) {
        formField.setType(FormField.Type.list_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.itemreply"));
    }
    if (replyPolicy != null) {
        formField.addValue(replyPolicy.name());
    }
    formField = form.addField();
    formField.setVariable("pubsub#replyroom");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.replyroom"));
    }
    for (JID owner : getReplyRooms()) {
        formField.addValue(owner.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#replyto");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.replyto"));
    }
    for (JID owner : getReplyTo()) {
        formField.addValue(owner.toString());
    }
}
Also used : JID(org.xmpp.packet.JID) 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