Search in sources :

Example 6 with FormField

use of org.jivesoftware.smackx.FormField in project ecf by eclipse.

the class FileTransferNegotiator method getStreamMethodField.

private FormField getStreamMethodField(DataForm form) {
    FormField field = null;
    for (Iterator<FormField> it = form.getFields(); it.hasNext(); ) {
        field = it.next();
        if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) {
            break;
        }
        field = null;
    }
    return field;
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Example 7 with FormField

use of org.jivesoftware.smackx.FormField in project ecf by eclipse.

the class StreamNegotiator method createInitiationAccept.

/**
 * Creates the initiation acceptance packet to forward to the stream
 * initiator.
 *
 * @param streamInitiationOffer The offer from the stream initiator to connect for a stream.
 * @param namespaces            The namespace that relates to the accepted means of transfer.
 * @return The response to be forwarded to the initiator.
 */
public StreamInitiation createInitiationAccept(StreamInitiation streamInitiationOffer, String[] namespaces) {
    StreamInitiation response = new StreamInitiation();
    response.setTo(streamInitiationOffer.getFrom());
    response.setFrom(streamInitiationOffer.getTo());
    response.setType(IQ.Type.RESULT);
    response.setPacketID(streamInitiationOffer.getPacketID());
    DataForm form = new DataForm(Form.TYPE_SUBMIT);
    FormField field = new FormField(FileTransferNegotiator.STREAM_DATA_FIELD_NAME);
    for (String namespace : namespaces) {
        field.addValue(namespace);
    }
    form.addField(field);
    response.setFeatureNegotiationForm(form);
    return response;
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) DataForm(org.jivesoftware.smackx.packet.DataForm) FormField(org.jivesoftware.smackx.FormField)

Example 8 with FormField

use of org.jivesoftware.smackx.FormField in project Smack by igniterealtime.

the class MultiUserChatCreationTest method testCreateReservedRoom.

/**
 * Tests creating a new "Reserved Room".
 */
public void testCreateReservedRoom() {
    MultiUserChat muc = new MultiUserChat(getConnection(0), room);
    try {
        // Create the room
        muc.create("testbot1");
        // Get the the room's configuration form
        Form form = muc.getConfigurationForm();
        assertNotNull("No room configuration form", form);
        // Create a new form to submit based on the original form
        Form submitForm = form.createAnswerForm();
        // Add default answers to the form to submit
        for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
            FormField field = fields.next();
            if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
                // Sets the default value as the answer
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }
        List<String> owners = new ArrayList<String>();
        owners.add(getBareJID(0));
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        // Update the new room's configuration
        muc.sendConfigurationForm(submitForm);
        // Destroy the new room
        muc.destroy("The room has almost no activity...", null);
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) ArrayList(java.util.ArrayList) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField)

Example 9 with FormField

use of org.jivesoftware.smackx.FormField in project ecf by eclipse.

the class FileTransferNegotiator method selectStreamNegotiator.

/**
 * Selects an appropriate stream negotiator after examining the incoming file transfer request.
 *
 * @param request The related file transfer request.
 * @return The file transfer object that handles the transfer
 * @throws XMPPException If there are either no stream methods contained in the packet, or
 *                       there is not an appropriate stream method.
 */
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws XMPPException {
    StreamInitiation si = request.getStreamInitiation();
    FormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
    if (streamMethodField == null) {
        String errorMessage = "No stream methods contained in packet.";
        XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
        IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
        iqPacket.setError(error);
        connection.sendPacket(iqPacket);
        throw new XMPPException(errorMessage, error);
    }
    // select the appropriate protocol
    StreamNegotiator selectedStreamNegotiator;
    try {
        selectedStreamNegotiator = getNegotiator(streamMethodField);
    } catch (XMPPException e) {
        IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
        iqPacket.setError(e.getXMPPError());
        connection.sendPacket(iqPacket);
        throw e;
    }
    return selectedStreamNegotiator;
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField)

Example 10 with FormField

use of org.jivesoftware.smackx.FormField in project ecf by eclipse.

the class FileTransferNegotiator method createDefaultInitiationForm.

private DataForm createDefaultInitiationForm() {
    DataForm form = new DataForm(Form.TYPE_FORM);
    FormField field = new FormField(STREAM_DATA_FIELD_NAME);
    field.setType(FormField.TYPE_LIST_SINGLE);
    if (!IBB_ONLY) {
        field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE));
    }
    field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE));
    form.addField(field);
    return form;
}
Also used : DataForm(org.jivesoftware.smackx.packet.DataForm) FormField(org.jivesoftware.smackx.FormField)

Aggregations

FormField (org.jivesoftware.smackx.FormField)19 XMPPException (org.jivesoftware.smack.XMPPException)5 DataForm (org.jivesoftware.smackx.packet.DataForm)5 Form (org.jivesoftware.smackx.Form)4 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IQ (org.jivesoftware.smack.packet.IQ)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)1 Feature (org.jivesoftware.smackx.packet.DiscoverInfo.Feature)1 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)1 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)1 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)1 WorkgroupForm (org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm)1