Search in sources :

Example 81 with FormField

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

the class Ping method execute.

@Override
public void execute(final SessionData data, final Element command) {
    final DataForm form = new DataForm(DataForm.Type.result);
    form.setTitle("Server ping result (pong!)");
    final FormField field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("Server Time");
    field.setVariable("timestamp");
    field.addValue(XMPPDateTimeFormat.format(new Date()));
    command.add(form.getElement());
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField) Date(java.util.Date)

Example 82 with FormField

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

the class VCardModified method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Dispatching a vCard updated event.");
    form.addInstruction("Fill out this form to dispatch a vCard updated 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 username of the user who's vCard was updated");
    field.setVariable("username");
    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 83 with FormField

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

the class PubSubEngine method canAutoCreate.

/**
 * Checks if a node is allowed to be auto-created, given the configuration of the service and the optional publish options.
 *
 * @param publishOptions publish options (can be null)
 * @return true if auto-creation of nodes on publish to a non-existent node is allowed, otherwise false.
 */
private boolean canAutoCreate(DataForm publishOptions) {
    // Since pep#auto-create is advertised in disco#info in hard-code, this is always allowed, unless the publish options explicitly forbid this.
    if (publishOptions == null) {
        return true;
    }
    final FormField field = publishOptions.getField("pubsub#auto-create");
    if (field == null) {
        return true;
    }
    final String firstValue = field.getFirstValue();
    return "1".equals(firstValue) || "true".equalsIgnoreCase(firstValue);
}
Also used : FormField(org.xmpp.forms.FormField)

Example 84 with FormField

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

the class PubSubEngine method nodeMeetsPreconditions.

/**
 * Checks of the configuration of the node meets the preconditions, as supplied in the dataform.
 *
 * This method returns true only if the configuration of the node at least contains each of the fields
 * defined in the preconditions (with matching values).
 *
 * @param node The node (cannot be null)
 * @param preconditions The preconditions (can be null, in which case 'true' is returned).
 * @return True if all preconditions are met, otherwise false.
 */
private boolean nodeMeetsPreconditions(Node node, DataForm preconditions) {
    if (preconditions == null) {
        return true;
    }
    final DataForm conditions = node.getConfigurationForm();
    for (final FormField precondition : preconditions.getFields()) {
        if (precondition.getVariable().equals("FORM_TYPE")) {
            continue;
        }
        final FormField condition = conditions.getField(precondition.getVariable());
        if (condition == null) {
            // Unknown condition. Reject.
            return false;
        }
        if (condition.getValues().size() > 1) {
            if (!condition.getValues().containsAll(precondition.getValues()) || !precondition.getValues().containsAll(condition.getValues())) {
                // The condition value list does contain different values than the precondtion value list.
                return false;
            }
        } else {
            final String a = condition.getFirstValue();
            final String b = precondition.getFirstValue();
            if (!a.equals(b) && !(a.equals("true") && b.equals("1")) && !(a.equals("1") && b.equals("true")) && !(a.equals("false") && b.equals("0")) && !(a.equals("0") && b.equals("false"))) {
                return false;
            }
        }
    }
    return true;
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 85 with FormField

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

the class PubSubServiceInfo method validateAdditions.

public void validateAdditions(DataForm form, HttpServletRequest request, Map<String, listType> listTypes, Map<String, String> errors) {
    for (FormField field : form.getFields()) {
        if (listTypes.containsKey(field.getVariable())) {
            switch(listTypes.get(field.getVariable())) {
                case group:
                    if (ParamUtils.getParameter(request, field.getVariable() + "-Add") != null) {
                        String groupName = ParamUtils.getParameter(request, field.getVariable() + "-Additional");
                        if (isValidGroup(groupName)) {
                            if (!field.getValues().contains(groupName)) {
                                field.addValue(groupName);
                            } else {
                                // Group already in list
                                errors.put(field.getVariable(), LocaleUtils.getLocalizedString("pubsub.form.already_in_list", Arrays.asList(LocaleUtils.getLocalizedString("pubsub.form.group"), groupName)));
                            }
                        } else {
                            // Not a valid group
                            errors.put(field.getVariable(), LocaleUtils.getLocalizedString("pubsub.form.not_valid", Arrays.asList(groupName, LocaleUtils.getLocalizedString("pubsub.form.group"))));
                        }
                    }
                    break;
                case user:
                    if (ParamUtils.getParameter(request, field.getVariable() + "-Add") != null) {
                        String username = ParamUtils.getParameter(request, field.getVariable() + "-Additional");
                        JID newUser = getValidJID(username);
                        if (newUser != null) {
                            if (!field.getValues().contains(newUser.toBareJID())) {
                                field.addValue(newUser.toBareJID());
                            } else {
                                // User already in list
                                errors.put(field.getVariable(), LocaleUtils.getLocalizedString("pubsub.form.already_in_list", Arrays.asList(LocaleUtils.getLocalizedString("pubsub.form.user"), username)));
                            }
                        } else {
                            // Not a valid username
                            errors.put(field.getVariable(), LocaleUtils.getLocalizedString("pubsub.form.not_valid", Arrays.asList(username, LocaleUtils.getLocalizedString("pubsub.form.user"))));
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : JID(org.xmpp.packet.JID) 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