Java Code Examples for org.jivesoftware.smackx.xdata.FormField#builder()

The following examples show how to use org.jivesoftware.smackx.xdata.FormField#builder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoomInfoTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void validateRoomWithForm() {
    DataForm.Builder dataForm = DataForm.builder(DataForm.Type.result);

    TextSingleFormField.Builder desc = FormField.builder("muc#roominfo_description");
    desc.setValue("The place for all good witches!");
    dataForm.addField(desc.build());

    TextSingleFormField.Builder subject = FormField.builder("muc#roominfo_subject");
    subject.setValue("Spells");
    dataForm.addField(subject.build());

    TextSingleFormField.Builder occupants = FormField.builder("muc#roominfo_occupants");
    occupants.setValue("3");
    dataForm.addField(occupants.build());

    DiscoverInfo discoInfo = DiscoverInfo.builder("disco1")
            .addExtension(dataForm.build())
            .build();
    RoomInfo roomInfo = new RoomInfo(discoInfo);
    assertEquals("The place for all good witches!", roomInfo.getDescription());
    assertEquals("Spells", roomInfo.getSubject());
    assertEquals(3, roomInfo.getOccupantsCount());
}
 
Example 2
Source File: EnablePushNotificationsIQ.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
    xml.attribute("jid", jid);
    xml.attribute("node", node);
    xml.rightAngleBracket();

    if (publishOptions != null) {
        DataForm.Builder dataForm = DataForm.builder();

        // TODO: Shouldn't this use some potentially existing PubSub API? Also FORM_TYPE fields are usually of type
        // 'hidden', but the examples in XEP-0357 do also not set the value to hidden and FORM_TYPE itself appears
        // to be more convention than specification.
        FormField formTypeField = FormField.buildHiddenFormType(PubSub.NAMESPACE + "#publish-options");
        dataForm.addField(formTypeField);

        Iterator<Map.Entry<String, String>> publishOptionsIterator = publishOptions.entrySet().iterator();
        while (publishOptionsIterator.hasNext()) {
            Map.Entry<String, String> pairVariableValue = publishOptionsIterator.next();
            TextSingleFormField.Builder field = FormField.builder(pairVariableValue.getKey());
            field.setValue(pairVariableValue.getValue());
            dataForm.addField(field.build());
        }

        xml.append(dataForm.build());
    }

    return xml;
}
 
Example 3
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Include Operating System's name as a {@link FormField}.
 * <br>
 * @param os Name of the OS
 * @return Builder
 */
public Builder setOS(String os) {
    TextSingleFormField.Builder builder = FormField.builder(OS);
    builder.setValue(os);
    dataFormBuilder.addField(builder.build());
    return this;
}
 
Example 4
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Include Operating System's version as a {@link FormField}.
 * <br>
 * @param os_version Version of OS
 * @return Builder
 */
public Builder setOSVersion(String os_version) {
    TextSingleFormField.Builder builder = FormField.builder(OS_VERSION);
    builder.setValue(os_version);
    dataFormBuilder.addField(builder.build());
    return this;
}
 
Example 5
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Include Software name as a {@link FormField}.
 * <br>
 * @param software Name of the software
 * @return Builder
 */
public Builder setSoftware(String software) {
    TextSingleFormField.Builder builder = FormField.builder(SOFTWARE);
    builder.setValue(software);
    dataFormBuilder.addField(builder.build());
    return this;
}
 
Example 6
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Include Software Version as a {@link FormField}.
 * <br>
 * @param softwareVersion Version of the Software in use
 * @return Builder
 */
public Builder setSoftwareVersion(String softwareVersion) {
    TextSingleFormField.Builder builder = FormField.builder(SOFTWARE_VERSION);
    builder.setValue(softwareVersion);
    dataFormBuilder.addField(builder.build());
    return this;
}
 
Example 7
Source File: DataFormTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidation() throws Exception {
    // Build a Form.
    DataForm.Builder df = DataForm.builder(DataForm.Type.form);
    String instruction = "InstructionTest1";
    df.addInstruction(instruction);
    FormField.Builder<?, ?> fieldBuilder = FormField.builder("testField1");

    ValidateElement dv = new RangeValidateElement("xs:integer", "1111", "9999");
    fieldBuilder.addFormFieldChildElement(dv);

    df.addField(fieldBuilder.build());

    DataForm dataForm = df.build();
    String output = dataForm.toXML().toString();
    assertEquals(TEST_OUTPUT_3, output);

    XmlPullParser parser = PacketParserUtils.getParserFor(output);

    dataForm = pr.parse(parser);

    assertNotNull(dataForm.getFields());
    assertEquals(1 , dataForm.getFields().size());
    Element element = ValidateElement.from(dataForm.getFields().get(0));
    assertNotNull(element);
    dv = (ValidateElement) element;

    assertEquals("xs:integer" , dv.getDatatype());

    output = dataForm.toXML().toString();
    assertEquals(TEST_OUTPUT_3, output);
}
 
Example 8
Source File: Workgroup.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Joins the workgroup queue to wait to be routed to an agent. After joining
 * the queue, queue status events will be sent to indicate the user's position and
 * estimated time left in the queue. Once joining the queue, there are three ways
 * the user can leave the queue: <ul>
 *
 * <li>The user is routed to an agent, which triggers a GroupChat invitation.
 * <li>The user asks to leave the queue by calling the {@link #departQueue} method.
 * <li>A server error occurs, or an administrator explicitly removes the user
 * from the queue.
 * </ul>
 *
 * A user cannot request to join the queue again if already in the queue. Therefore,
 * this method will throw an IllegalStateException if the user is already in the queue.<p>
 *
 * Some servers may be configured to require certain meta-data in order to
 * join the queue.<p>
 *
 * The server tracks the conversations that a user has with agents over time. By
 * default, that tracking is done using the user's JID. However, this is not always
 * possible. For example, when the user is logged in anonymously using a web client.
 * In that case the user ID might be a randomly generated value put into a persistent
 * cookie or a username obtained via the session. When specified, that userID will
 * be used instead of the user's JID to track conversations. The server will ignore a
 * manually specified userID if the user's connection to the server is not anonymous.
 *
 * @param metadata metadata to create a dataform from.
 * @param userID   String that represents the ID of the user when using anonymous sessions
 *                 or <code>null</code> if a userID should not be used.
 * @throws XMPPException if an error occurred joining the queue. An error may indicate
 *                       that a connection failure occurred or that the server explicitly rejected the
 *                       request to join the queue.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void joinQueue(Map<String, Object> metadata, Jid userID) throws XMPPException, SmackException, InterruptedException {
    // If already in the queue ignore the join request.
    if (inQueue) {
        throw new IllegalStateException("Already in queue " + workgroupJID);
    }

    // Build dataform from metadata
    DataForm.Builder form = DataForm.builder();
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        String value = metadata.get(name).toString();

        TextSingleFormField.Builder field = FormField.builder(name);
        field.setValue(value);
        form.addField(field.build());
    }
    joinQueue(form.build(), userID);
}
 
Example 9
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * This will allow to include {@link MediaElement} directly as a
 * {@link FormField}.
 * <br>
 * @param mediaElement MediaElement to be included
 * @return Builder
 */
public Builder setIcon(MediaElement mediaElement) {
    FormField.Builder<?, ?> builder = FormField.builder(ICON);
    builder.addFormFieldChildElement(mediaElement);
    dataFormBuilder.addField(builder.build());
    return this;
}