Search in sources :

Example 1 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)

Example 2 with DataForm

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

the class IQDiscoInfoHandler method handleIQ.

@Override
public IQ handleIQ(IQ packet) {
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested info to the reply if any otherwise add 
    // a not found error
    IQ reply = IQ.createResultIQ(packet);
    // Look for a DiscoInfoProvider associated with the requested entity.
    // We consider the host of the recipient JID of the packet as the entity. It's the 
    // DiscoInfoProvider responsibility to provide information about the JID's name together 
    // with any possible requested node.  
    DiscoInfoProvider infoProvider = getProvider(packet.getTo() == null ? XMPPServer.getInstance().getServerInfo().getXMPPDomain() : packet.getTo().getDomain());
    if (infoProvider != null) {
        // Get the JID's name
        String name = packet.getTo() == null ? null : packet.getTo().getNode();
        if (name == null || name.trim().length() == 0) {
            name = null;
        }
        // Get the requested node
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");
        // Check if we have information about the requested name and node
        if (infoProvider.hasInfo(name, node, packet.getFrom())) {
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();
            // Add to the reply all the identities provided by the DiscoInfoProvider
            Element identity;
            Iterator<Element> identities = infoProvider.getIdentities(name, node, packet.getFrom());
            while (identities.hasNext()) {
                identity = identities.next();
                identity.setQName(new QName(identity.getName(), queryElement.getNamespace()));
                queryElement.add((Element) identity.clone());
            }
            // Add to the reply all the features provided by the DiscoInfoProvider
            Iterator<String> features = infoProvider.getFeatures(name, node, packet.getFrom());
            boolean hasDiscoInfoFeature = false;
            boolean hasDiscoItemsFeature = false;
            boolean hasResultSetManagementFeature = false;
            while (features.hasNext()) {
                final String feature = features.next();
                queryElement.addElement("feature").addAttribute("var", feature);
                if (feature.equals(NAMESPACE_DISCO_INFO)) {
                    hasDiscoInfoFeature = true;
                } else if (feature.equals("http://jabber.org/protocol/disco#items")) {
                    hasDiscoItemsFeature = true;
                } else if (feature.equals(ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)) {
                    hasResultSetManagementFeature = true;
                }
            }
            if (hasDiscoItemsFeature && !hasResultSetManagementFeature) {
                // IQDiscoItemsHandler provides result set management
                // support.
                queryElement.addElement("feature").addAttribute("var", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
            }
            if (!hasDiscoInfoFeature) {
                // XEP-0030 requires that every entity that supports service
                // discovery broadcasts the disco#info feature.
                queryElement.addElement("feature").addAttribute("var", NAMESPACE_DISCO_INFO);
            }
            // Add to the reply the extended info (XDataForm) provided by the DiscoInfoProvider
            DataForm dataForm = infoProvider.getExtendedInfo(name, node, packet.getFrom());
            if (dataForm != null) {
                queryElement.add(dataForm.getElement());
            }
        } else {
            // If the DiscoInfoProvider has no information for the requested name and node 
            // then answer a not found error
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.item_not_found);
        }
    } else {
        // If we didn't find a DiscoInfoProvider then answer a not found error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.item_not_found);
    }
    return reply;
}
Also used : QName(org.dom4j.QName) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm)

Example 3 with DataForm

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

the class GetListGroups method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Requesting List of Existing Groups");
    form.addInstruction("Fill out this form to request list of groups.");
    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.list_single);
    field.setLabel("Start from page number");
    field.setVariable("start");
    field.addValue("0");
    field.addOption("0", "0");
    field.addOption("25", "25");
    field.addOption("50", "50");
    field.addOption("75", "75");
    field.addOption("100", "100");
    field.addOption("150", "150");
    field.addOption("200", "200");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.list_single);
    field.setLabel("Maximum number of items to show");
    field.setVariable("max_items");
    field.addValue("25");
    field.addOption("25", "25");
    field.addOption("50", "50");
    field.addOption("75", "75");
    field.addOption("100", "100");
    field.addOption("150", "150");
    field.addOption("200", "200");
    field.addOption("None", "none");
    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 4 with DataForm

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

the class UpdateGroup method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    if (data.getStage() == 0) {
        form.setTitle("Update group configuration");
        form.addInstruction("Fill out this form to specify the group to update.");
        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("Group Name");
        field.setVariable("group");
        field.setRequired(true);
    } else {
        // Check if groups cannot be modified (backend is read-only)
        if (GroupManager.getInstance().isReadOnly()) {
            Element note = command.addElement("note");
            note.addAttribute("type", "error");
            note.setText("Groups are read only");
            return;
        }
        // Get requested group
        Group group;
        try {
            group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
        } catch (GroupNotFoundException e) {
            // Group not found
            Element note = command.addElement("note");
            note.addAttribute("type", "error");
            note.setText("Group not found");
            return;
        }
        form.setTitle("Update group configuration");
        form.addInstruction("Fill out this form with the new group configuration.");
        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_multi);
        field.setLabel("Description");
        field.setVariable("desc");
        if (group.getDescription() != null) {
            field.addValue(group.getDescription());
        }
        field = form.addField();
        field.setType(FormField.Type.list_single);
        field.setLabel("Shared group visibility");
        field.setVariable("showInRoster");
        field.addValue("nobody");
        field.addOption("Disable sharing group in rosters", "nobody");
        field.addOption("Show group in all users' rosters", "everybody");
        field.addOption("Show group in group members' rosters", "onlyGroup");
        field.addOption("Show group to members' rosters of these groups", "spefgroups");
        field.setRequired(true);
        String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
        if (showInRoster != null) {
            if ("onlyGroup".equals(showInRoster) && group.getProperties().get("sharedRoster.groupList").trim().length() > 0) {
                // Show shared group to other groups
                showInRoster = "spefgroups";
            }
            field.addValue(showInRoster);
        }
        field = form.addField();
        field.setType(FormField.Type.list_multi);
        field.setVariable("groupList");
        for (Group otherGroup : GroupManager.getInstance().getGroups()) {
            field.addOption(otherGroup.getName(), otherGroup.getName());
        }
        String groupList = group.getProperties().get("sharedRoster.groupList");
        if (groupList != null) {
            Collection<String> groups = new ArrayList<>();
            StringTokenizer tokenizer = new StringTokenizer(groupList, ",\t\n\r\f");
            while (tokenizer.hasMoreTokens()) {
                String tok = tokenizer.nextToken().trim();
                groups.add(tok.trim());
            }
            for (String othergroup : groups) {
                field.addValue(othergroup);
            }
        }
        field = form.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Group Display Name");
        field.setVariable("displayName");
        String displayName = group.getProperties().get("sharedRoster.displayName");
        if (displayName != null) {
            field.addValue(displayName);
        }
    }
    // Add the form to the command
    command.add(form.getElement());
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) FormField(org.xmpp.forms.FormField)

Example 5 with DataForm

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

the class CreateMUCRoom method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle("Create a multi-user chat room");
    form.addInstruction("Fill out this form to create a multi-user chat room.");
    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 name of the room");
    field.setVariable("roomname");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.text_single);
    field.setLabel("The service (hostname) to create the room on");
    field.setVariable("servicename");
    field.setRequired(true);
    field = form.addField();
    field.setType(FormField.Type.text_private);
    field.setLabel("The password for this account");
    field.setVariable("password");
    field = form.addField();
    field.setType(FormField.Type.text_private);
    field.setLabel("Retype password");
    field.setVariable("password-verify");
    field = form.addField();
    field.setType(FormField.Type.boolean_type);
    field.setLabel("Room is persistent");
    field.setVariable("persistent");
    field = form.addField();
    field.setType(FormField.Type.boolean_type);
    field.setLabel("Is the room public");
    field.setVariable("public");
    // Add the form to the command
    command.add(form.getElement());
}
Also used : 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