Search in sources :

Example 41 with DataForm

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

the class PubSubEngine method configureSubscription.

private void configureSubscription(PubSubService service, IQ iq, Element optionsElement) {
    String nodeID = optionsElement.attributeValue("node");
    String subID = optionsElement.attributeValue("subid");
    Node node;
    if (nodeID == null) {
        if (service.isCollectionNodesSupported()) {
            // Entity submits new subscription options of root collection node
            node = service.getRootCollectionNode();
        } else {
            // Service does not have a root collection node so return a nodeid-required error
            Element pubsubError = DocumentHelper.createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
            sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
            return;
        }
    } else {
        // Look for the specified node
        node = service.getNode(nodeID);
        if (node == null) {
            // Node does not exist. Return item-not-found error
            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
            return;
        }
    }
    NodeSubscription subscription;
    if (node.isMultipleSubscriptionsEnabled()) {
        if (subID == null) {
            // No subid was specified and the node supports multiple subscriptions
            Element pubsubError = DocumentHelper.createElement(QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));
            sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
            return;
        } else {
            // Check if the specified subID belongs to an existing node subscription
            subscription = node.getSubscription(subID);
            if (subscription == null) {
                Element pubsubError = DocumentHelper.createElement(QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));
                sendErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);
                return;
            }
        }
    } else {
        // Check if the specified JID has a subscription with the node
        String jidAttribute = optionsElement.attributeValue("jid");
        if (jidAttribute == null) {
            // No JID was specified so return an error indicating that jid is required
            Element pubsubError = DocumentHelper.createElement(QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));
            sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
            return;
        }
        JID subscriberJID = new JID(jidAttribute);
        subscription = node.getSubscription(subscriberJID);
        if (subscription == null) {
            Element pubsubError = DocumentHelper.createElement(QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
            sendErrorPacket(iq, PacketError.Condition.unexpected_request, pubsubError);
            return;
        }
    }
    // new subscription options
    if (!subscription.canModify(iq.getFrom())) {
        // Requestor is prohibited from setting new subscription options
        sendErrorPacket(iq, PacketError.Condition.forbidden, null);
        return;
    }
    Element formElement = optionsElement.element(QName.get("x", "jabber:x:data"));
    if (formElement != null) {
        // Change the subscription configuration based on the completed form
        subscription.configure(iq, new DataForm(formElement));
    } else {
        // No data form was included so return bad request error
        sendErrorPacket(iq, PacketError.Condition.bad_request, null);
    }
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm)

Example 42 with DataForm

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

the class WorkgroupFormProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    FormManager formManager = FormManager.getInstance();
    DataForm dataForm = formManager.getDataForm(workgroup);
    if (dataForm == null) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element iq = packet.getChildElement();
    if (iq.elements().isEmpty()) {
        reply.setChildElement(iq.createCopy());
        // Send the data form to the requestor
        reply.addExtension(dataForm.createCopy());
        workgroup.send(reply);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) PacketError(org.xmpp.packet.PacketError)

Example 43 with DataForm

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

the class FormManager method saveDataForm.

private void saveDataForm(Workgroup workgroup) {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    WorkgroupForm form = getWebForm(workgroup);
    if (form.getTitle() != null) {
        dataForm.setTitle(form.getTitle());
    }
    if (form.getDescription() != null) {
        dataForm.addInstruction(form.getDescription());
    }
    List<FormElement> elems = new ArrayList<FormElement>();
    // Add normal elems
    int size = form.getFormElements().size();
    for (int j = 0; j < size; j++) {
        elems.add(form.getFormElementAt(j));
    }
    size = form.getHiddenVars().size();
    for (int k = 0; k < size; k++) {
        elems.add(form.getHiddenVars().get(k));
    }
    size = elems.size();
    for (int i = 0; i < size; i++) {
        FormElement elem = elems.get(i);
        FormField field = dataForm.addField();
        field.setLabel(elem.getLabel());
        field.setVariable(elem.getVariable());
        field.setRequired(elem.isRequired());
        if (elem.getDescription() != null) {
            field.setDescription(elem.getDescription());
        }
        if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
            field.setType(FormField.Type.text_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
            field.setType(FormField.Type.text_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
            field.setType(FormField.Type.boolean_type);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
            field.setType(FormField.Type.list_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
            field.setType(FormField.Type.list_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
            field.setType(FormField.Type.hidden);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
            field.setType(FormField.Type.text_private);
        }
        if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
            for (String item : elem.getAnswers()) {
                field.addOption(item, item);
            }
        } else if (elem.getAnswers().size() > 0) {
            // Add hidden element values.
            for (String item : elem.getAnswers()) {
                field.addValue(item);
            }
        }
    }
    XStream xstream = new XStream();
    String xmlToSave = xstream.toXML(dataForm);
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    try {
        props.deleteProperty(context);
        props.setProperty(context, xmlToSave);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) FormField(org.xmpp.forms.FormField)

Example 44 with DataForm

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

the class IQOwnerHandler method init.

private void init() {
    Element element = DocumentHelper.createElement(QName.get("query", "http://jabber.org/protocol/muc#owner"));
    configurationForm = new DataForm(DataForm.Type.form);
    configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title"));
    List<String> params = new ArrayList<>();
    params.add(room.getName());
    configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params));
    configurationForm.addField("FORM_TYPE", null, Type.hidden).addValue("http://jabber.org/protocol/muc#roomconfig");
    configurationForm.addField("muc#roomconfig_roomname", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"), Type.text_single);
    configurationForm.addField("muc#roomconfig_roomdesc", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"), Type.text_single);
    configurationForm.addField("muc#roomconfig_changesubject", LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"), Type.boolean_type);
    final FormField maxUsers = configurationForm.addField("muc#roomconfig_maxusers", LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"), Type.list_single);
    maxUsers.addOption("10", "10");
    maxUsers.addOption("20", "20");
    maxUsers.addOption("30", "30");
    maxUsers.addOption("40", "40");
    maxUsers.addOption("50", "50");
    maxUsers.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0");
    final FormField broadcast = configurationForm.addField("muc#roomconfig_presencebroadcast", LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"), Type.list_multi);
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator");
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant");
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor");
    configurationForm.addField("muc#roomconfig_publicroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_persistentroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_moderatedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_membersonly", LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed"));
    configurationForm.addField("muc#roomconfig_allowinvites", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_passwordprotectedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed"));
    configurationForm.addField("muc#roomconfig_roomsecret", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"), Type.text_private);
    final FormField whois = configurationForm.addField("muc#roomconfig_whois", LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"), Type.list_single);
    whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
    whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
    final FormField allowpm = configurationForm.addField("muc#roomconfig_allowpm", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowpm"), Type.list_single);
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participants");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "none");
    configurationForm.addField("muc#roomconfig_enablelogging", LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"), Type.boolean_type);
    configurationForm.addField("x-muc#roomconfig_reservednick", LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"), Type.boolean_type);
    configurationForm.addField("x-muc#roomconfig_canchangenick", LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
    configurationForm.addField("x-muc#roomconfig_registration", LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed"));
    configurationForm.addField("muc#roomconfig_roomadmins", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"), Type.jid_multi);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed"));
    configurationForm.addField("muc#roomconfig_roomowners", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"), Type.jid_multi);
    // Create the probeResult and add the basic info together with the configuration form
    probeResult = element;
    probeResult.add(configurationForm.getElement());
}
Also used : Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) FormField(org.xmpp.forms.FormField)

Example 45 with DataForm

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

the class ForwardTest method testForwarded.

@Test
public void testForwarded() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setBody("Tests");
    message.addExtension(new DataForm(DataForm.Type.submit));
    Forwarded forwarded = new Forwarded(message);
    Forwarded forwarded2 = new Forwarded(message);
    String xml1 = forwarded.getElement().asXML();
    String xml2 = forwarded2.getElement().asXML();
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
Also used : Message(org.xmpp.packet.Message) DataForm(org.xmpp.forms.DataForm) Test(org.junit.Test)

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