Search in sources :

Example 86 with FormField

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

the class CollectionNode method addFormFields.

@Override
protected void addFormFields(DataForm form, boolean isEditing) {
    super.addFormFields(form, isEditing);
    FormField typeField = form.getField("pubsub#node_type");
    typeField.addValue("collection");
    // TODO: remove this field during an upgrade to pubsub version since it is replaced by children_association_policy
    FormField formField = form.addField();
    formField.setVariable("pubsub#leaf_node_association_policy");
    if (isEditing) {
        formField.setType(FormField.Type.list_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy"));
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.all"), LeafNodeAssociationPolicy.all.name());
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.owners"), LeafNodeAssociationPolicy.owners.name());
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.whitelist"), LeafNodeAssociationPolicy.whitelist.name());
    }
    formField.addValue(associationPolicy.name());
    formField = form.addField();
    formField.setVariable("pubsub#children_association_policy");
    if (isEditing) {
        formField.setType(FormField.Type.list_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy"));
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.all"), LeafNodeAssociationPolicy.all.name());
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.owners"), LeafNodeAssociationPolicy.owners.name());
        formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.whitelist"), LeafNodeAssociationPolicy.whitelist.name());
    }
    formField.addValue(associationPolicy.name());
    // TODO: remove this field during an upgrade to pubsub version since it is replaced by children_association_whitelist
    formField = form.addField();
    formField.setVariable("pubsub#leaf_node_association_whitelist");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_whitelist"));
    }
    for (JID contact : associationTrusted) {
        formField.addValue(contact.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#children_association_whitelist");
    if (isEditing) {
        formField.setType(FormField.Type.jid_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_whitelist"));
    }
    for (JID contact : associationTrusted) {
        formField.addValue(contact.toString());
    }
    formField = form.addField();
    formField.setVariable("pubsub#leaf_nodes_max");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_max"));
    }
    formField.addValue(maxLeafNodes);
    formField = form.addField();
    formField.setVariable("pubsub#children_max");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_max"));
    }
    formField.addValue(maxLeafNodes);
    formField = form.addField();
    formField.setVariable("pubsub#children");
    if (isEditing) {
        formField.setType(FormField.Type.text_multi);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children"));
    }
    for (Node.UniqueIdentifier nodeId : nodes.keySet()) {
        formField.addValue(nodeId.getNodeId());
    }
}
Also used : JID(org.xmpp.packet.JID) FormField(org.xmpp.forms.FormField)

Example 87 with FormField

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

the class PubSubEngine method getSentConfigurationForm.

/**
 * Returns the data form included in the configure element sent by the node owner or
 * {@code null} if none was included or access model was defined. If the
 * owner just wants to set the access model to use for the node and optionally set the
 * list of roster groups (i.e. contacts present in the node owner roster in the
 * specified groups are allowed to access the node) allowed to access the node then
 * instead of including a data form the owner can just specify the "access" attribute
 * of the configure element and optionally include a list of group elements. In this case,
 * the method will create a data form including the specified data. This is a nice way
 * to accept both ways to configure a node but always returning a data form.
 *
 * @param configureElement the configure element sent by the owner.
 * @return the data form included in the configure element sent by the node owner or
 *         {@code null} if none was included or access model was defined.
 */
private static DataForm getSentConfigurationForm(Element configureElement) {
    DataForm completedForm = null;
    FormField formField;
    Element formElement = configureElement.element(QName.get("x", "jabber:x:data"));
    if (formElement != null) {
        completedForm = new DataForm(formElement);
    }
    String accessModel = configureElement.attributeValue("access");
    if (accessModel != null) {
        if (completedForm == null) {
            // Create a form (i.e. simulate that the user sent a form with roster groups)
            completedForm = new DataForm(DataForm.Type.submit);
            // Add the hidden field indicating that this is a node config form
            formField = completedForm.addField();
            formField.setVariable("FORM_TYPE");
            formField.setType(FormField.Type.hidden);
            formField.addValue("http://jabber.org/protocol/pubsub#node_config");
        }
        if (completedForm.getField("pubsub#access_model") == null) {
            // Add the field that will specify the access model of the node
            formField = completedForm.addField();
            formField.setType(FormField.Type.list_single);
            formField.setVariable("pubsub#access_model");
            formField.addValue(accessModel);
        } else {
            Log.debug("PubSubEngine: Owner sent access model in data form and as attribute: " + configureElement.asXML());
        }
        // Check if a list of groups was specified
        List groups = configureElement.elements("group");
        if (!groups.isEmpty()) {
            // Add the field that will contain the specified groups
            formField = completedForm.addField();
            formField.setType(FormField.Type.list_multi);
            formField.setVariable("pubsub#roster_groups_allowed");
            // Add each group as a value of the groups field
            for (Iterator it = groups.iterator(); it.hasNext(); ) {
                formField.addValue(((Element) it.next()).getTextTrim());
            }
        }
    }
    return completedForm;
}
Also used : Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 88 with FormField

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

the class PubSubEngine method getPublishOptions.

/**
 * Get the dataform that describes the publish options from the request, or null if no such form was included.
 *
 * @param iq The publish request (cannot be null).
 * @return A publish options data form (possibly null).
 */
public static DataForm getPublishOptions(IQ iq) {
    final Element publishOptionsElement = iq.getChildElement().element("publish-options");
    if (publishOptionsElement == null) {
        return null;
    }
    final Element x = publishOptionsElement.element(QName.get(DataForm.ELEMENT_NAME, DataForm.NAMESPACE));
    if (x == null) {
        return null;
    }
    final DataForm result = new DataForm(x);
    if (result.getType() != DataForm.Type.submit) {
        return null;
    }
    final FormField formType = result.getField("FORM_TYPE");
    if (formType == null || !"http://jabber.org/protocol/pubsub#publish-options".equals(formType.getFirstValue())) {
        return null;
    }
    return result;
}
Also used : Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 89 with FormField

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

the class Node method getAuthRequestForm.

/**
 * Returns the data form to be included in the authorization request to be sent to
 * node owners when a new subscription needs to be approved.
 *
 * @param subscription the new subscription that needs to be approved.
 * @return the data form to be included in the authorization request.
 */
DataForm getAuthRequestForm(NodeSubscription subscription) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.authorization.title"));
    form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.authorization.instruction"));
    FormField formField = form.addField();
    formField.setVariable("FORM_TYPE");
    formField.setType(FormField.Type.hidden);
    formField.addValue("http://jabber.org/protocol/pubsub#subscribe_authorization");
    formField = form.addField();
    formField.setVariable("pubsub#subid");
    formField.setType(FormField.Type.hidden);
    formField.addValue(subscription.getID());
    formField = form.addField();
    formField.setVariable("pubsub#node");
    formField.setType(FormField.Type.text_single);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.authorization.node"));
    formField.addValue(nodeID);
    formField = form.addField();
    formField.setVariable("pubsub#subscriber_jid");
    formField.setType(FormField.Type.jid_single);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.authorization.subscriber"));
    formField.addValue(subscription.getJID().toString());
    formField = form.addField();
    formField.setVariable("pubsub#allow");
    formField.setType(FormField.Type.boolean_type);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.authorization.allow"));
    formField.addValue(Boolean.FALSE);
    return form;
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 90 with FormField

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

the class AdHocCommandManager method saveCompletedForm.

/**
 * Stores in the SessionData the fields and their values as specified in the completed
 * data form by the user.
 *
 * @param iqCommand the command element containing the data form element.
 * @param session the SessionData for this command execution.
 */
private void saveCompletedForm(Element iqCommand, SessionData session) {
    Element formElement = iqCommand.element(QName.get("x", "jabber:x:data"));
    if (formElement != null) {
        // Generate a Map with the variable names and variables values
        Map<String, List<String>> data = new HashMap<>();
        DataForm dataForm = new DataForm(formElement);
        for (FormField field : dataForm.getFields()) {
            data.put(field.getVariable(), field.getValues());
        }
        // Store the variables and their values in the session data
        session.addStageForm(data);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) List(java.util.List) FormField(org.xmpp.forms.FormField)

Aggregations

FormField (org.xmpp.forms.FormField)92 DataForm (org.xmpp.forms.DataForm)80 Element (org.dom4j.Element)21 JID (org.xmpp.packet.JID)13 IQ (org.xmpp.packet.IQ)7 HashSet (java.util.HashSet)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 ArrayList (java.util.ArrayList)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 ParseException (java.text.ParseException)3 Date (java.util.Date)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 Group (org.jivesoftware.openfire.group.Group)3 Test (org.junit.Test)3 List (java.util.List)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