Search in sources :

Example 26 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MultiUserChat method sendConfigurationForm.

/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form.
 *
 * @param form the form with the new settings.
 * @throws XMPPErrorException if an error occurs setting the new rooms' configuration.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendConfigurationForm(FillableForm form) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final DataForm dataForm;
    if (form != null) {
        dataForm = form.getDataFormToSubmit();
    } else {
        // Instant room, cf. XEP-0045 ยง 10.1.2
        dataForm = DataForm.builder().build();
    }
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    iq.addExtension(dataForm);
    connection.sendIqRequestAndWaitForResponse(iq);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MUCOwner(org.jivesoftware.smackx.muc.packet.MUCOwner)

Example 27 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class PubSubManager method createNode.

/**
 * Creates a node with specified configuration.
 *
 * Note: This is the only way to create a collection node.
 *
 * @param nodeId The name of the node, which must be unique within the
 * pubsub service
 * @param config The configuration for the node
 * @return The node that was created
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public Node createNode(String nodeId, FillableConfigureForm config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub request = PubSub.createPubsubPacket(pubSubService, IQ.Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId));
    boolean isLeafNode = true;
    if (config != null) {
        DataForm submitForm = config.getDataFormToSubmit();
        request.addExtension(new FormNode(FormNodeType.CONFIGURE, submitForm));
        NodeType nodeType = config.getNodeType();
        // Note that some implementations do to have the pubsub#node_type field in their defauilt configuration,
        // which I believe to be a bug. However, since PubSub specifies the default node type to be 'leaf' we assume
        // leaf if the field does not exist.
        isLeafNode = nodeType == null || nodeType == NodeType.leaf;
    }
    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(request);
    Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
    nodeMap.put(newNode.getId(), newNode);
    return newNode;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 28 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class Node method subscribe.

/**
 * The user subscribes to the node using the supplied jid and subscription
 * options.  The bare jid portion of this one must match the jid for the
 * connection.
 *
 * Please note that the {@link Subscription.State} should be checked
 * on return since more actions may be required by the caller.
 * {@link Subscription.State#pending} - The owner must approve the subscription
 * request before messages will be received.
 * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
 * the caller must configure the subscription before messages will be received.  If it is false
 * the caller can configure it but is not required to do so.
 *
 * @param jid The jid to subscribe as.
 * @param subForm TODO javadoc me please
 *
 * @return The subscription
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public Subscription subscribe(Jid jid, FillableSubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DataForm submitForm = subForm.getDataFormToSubmit();
    PubSub request = createPubsubPacket(IQ.Type.set, new SubscribeExtension(jid, getId()));
    request.addExtension(new FormNode(FormNodeType.OPTIONS, submitForm));
    PubSub reply = sendPubsubPacket(request);
    return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 29 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class StreamInitiationProvider method parse.

@Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    // si
    String id = parser.getAttributeValue("", "id");
    String mimeType = parser.getAttributeValue("", "mime-type");
    StreamInitiation initiation = new StreamInitiation();
    // file
    String name = null;
    String size = null;
    String hash = null;
    String date = null;
    String desc = null;
    boolean isRanged = false;
    // feature
    DataForm form = null;
    DataFormProvider dataFormProvider = new DataFormProvider();
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            String elementName = parser.getName();
            String namespace = parser.getNamespace();
            if (elementName.equals("file")) {
                name = parser.getAttributeValue("", "name");
                size = parser.getAttributeValue("", "size");
                hash = parser.getAttributeValue("", "hash");
                date = parser.getAttributeValue("", "date");
            } else if (elementName.equals("desc")) {
                desc = parser.nextText();
            } else if (elementName.equals("range")) {
                isRanged = true;
            } else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
                form = dataFormProvider.parse(parser);
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            if (parser.getName().equals("file")) {
                long fileSize = 0;
                if (size != null && size.trim().length() != 0) {
                    try {
                        fileSize = Long.parseLong(size);
                    } catch (NumberFormatException e) {
                        LOGGER.log(Level.SEVERE, "Failed to parse file size from " + fileSize, e);
                    }
                }
                Date fileDate = new Date();
                if (date != null) {
                    try {
                        fileDate = XmppDateTime.parseDate(date);
                    } catch (ParseException e) {
                    // couldn't parse date, use current date-time
                    }
                }
                File file = new File(name, fileSize);
                file.setHash(hash);
                file.setDate(fileDate);
                file.setDesc(desc);
                file.setRanged(isRanged);
                initiation.setFile(file);
            }
        }
    }
    initiation.setSessionID(id);
    initiation.setMimeType(mimeType);
    initiation.setFeatureNegotiationForm(form);
    return initiation;
}
Also used : StreamInitiation(org.jivesoftware.smackx.si.packet.StreamInitiation) DataFormProvider(org.jivesoftware.smackx.xdata.provider.DataFormProvider) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ParseException(java.text.ParseException) File(org.jivesoftware.smackx.si.packet.StreamInitiation.File) Date(java.util.Date)

Example 30 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class SoftwareInfoManager method fromJid.

/**
 * Get Software Information from the provided XMPP address. Returns <code>null</code> in case the queried entity does not announce that information.
 *
 * @param jid jid to get software information from
 * @return {@link SoftwareInfoForm} Form containing software information or <code>null</code>.
 * @throws NoResponseException if there was no response from the remote entity
 * @throws XMPPErrorException if there was an XMPP error returned
 * @throws NotConnectedException if the XMPP connection is not connected
 * @throws InterruptedException if the calling thread was interrupted
 */
public SoftwareInfoForm fromJid(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(jid);
    DataForm dataForm = DataForm.from(discoverInfo, SoftwareInfoForm.FORM_TYPE);
    if (dataForm == null) {
        return null;
    }
    return SoftwareInfoForm.getBuilder().setDataForm(dataForm).build();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2