Search in sources :

Example 11 with FormField

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

the class DataFormProvider method parseField.

private FormField parseField(XmlPullParser parser) throws Exception {
    boolean done = false;
    FormField formField = new FormField(parser.getAttributeValue("", "var"));
    formField.setLabel(parser.getAttributeValue("", "label"));
    formField.setType(parser.getAttributeValue("", "type"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("desc")) {
                formField.setDescription(parser.nextText());
            } else if (parser.getName().equals("value")) {
                formField.addValue(parser.nextText());
            } else if (parser.getName().equals("required")) {
                formField.setRequired(true);
            } else if (parser.getName().equals("option")) {
                formField.addOption(parseOption(parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("field")) {
                done = true;
            }
        }
    }
    return formField;
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Example 12 with FormField

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

the class PubSubManager method createNode.

/**
 * Creates a node with specified configuration.
 *
 * Note: This is the only way to create a collection node.
 *
 * @param name 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
 * @exception XMPPException
 */
public Node createNode(String name, Form config) throws XMPPException {
    PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
    boolean isLeafNode = true;
    if (config != null) {
        request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
        FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
        if (nodeTypeField != null)
            isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString());
    }
    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);
    return newNode;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) FormField(org.jivesoftware.smackx.FormField)

Example 13 with FormField

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

the class SubscribeForm method addField.

private void addField(SubscribeOptionFields nodeField, String type) {
    String fieldName = nodeField.getFieldName();
    if (getField(fieldName) == null) {
        FormField field = new FormField(fieldName);
        field.setType(type);
        addField(field);
    }
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Example 14 with FormField

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

the class Workgroup method joinQueue.

/**
 * <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>
 * <p/>
 * <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>
 * <p/>
 * 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>
 * <p/>
 * Some servers may be configured to require certain meta-data in order to
 * join the queue.<p>
 * <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 <tt>null</tt> if a userID should not be used.
 * @throws XMPPException if an error occured joining the queue. An error may indicate
 *                       that a connection failure occured or that the server explicitly rejected the
 *                       request to join the queue.
 */
public void joinQueue(Map<String, Object> metadata, String userID) throws XMPPException {
    // If already in the queue ignore the join request.
    if (inQueue) {
        throw new IllegalStateException("Already in queue " + workgroupJID);
    }
    // Build dataform from metadata
    Form form = new Form(Form.TYPE_SUBMIT);
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        String value = metadata.get(name).toString();
        String escapedName = StringUtils.escapeForXML(name);
        String escapedValue = StringUtils.escapeForXML(value);
        FormField field = new FormField(escapedName);
        field.setType(FormField.TYPE_TEXT_SINGLE);
        form.addField(field);
        form.setAnswer(escapedName, escapedValue);
    }
    joinQueue(form, userID);
}
Also used : WorkgroupForm(org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm) DataForm(org.jivesoftware.smackx.packet.DataForm) Form(org.jivesoftware.smackx.Form) FormField(org.jivesoftware.smackx.FormField)

Example 15 with FormField

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

the class SimpleUserSearch method getItemsToSearch.

private String getItemsToSearch() {
    StringBuilder buf = new StringBuilder();
    if (form == null) {
        form = Form.getFormFrom(this);
    }
    if (form == null) {
        return "";
    }
    Iterator<FormField> fields = form.getFields();
    while (fields.hasNext()) {
        FormField field = fields.next();
        String name = field.getVariable();
        String value = getSingleValue(field);
        if (value.trim().length() > 0) {
            buf.append("<").append(name).append(">").append(value).append("</").append(name).append(">");
        }
    }
    return buf.toString();
}
Also used : 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