Search in sources :

Example 1 with FormField

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

the class ConfigureForm method addField.

private void addField(ConfigureNodeFields 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 2 with FormField

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

the class ConfigureForm method toString.

@Override
public String toString() {
    StringBuilder result = new StringBuilder(getClass().getName() + " Content [");
    Iterator<FormField> fields = getFields();
    while (fields.hasNext()) {
        FormField formField = fields.next();
        result.append('(');
        result.append(formField.getVariable());
        result.append(':');
        Iterator<String> values = formField.getValues();
        StringBuilder valuesBuilder = new StringBuilder();
        while (values.hasNext()) {
            if (valuesBuilder.length() > 0)
                result.append(',');
            String value = (String) values.next();
            valuesBuilder.append(value);
        }
        if (valuesBuilder.length() == 0)
            valuesBuilder.append("NOT SET");
        result.append(valuesBuilder);
        result.append(')');
    }
    result.append(']');
    return result.toString();
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Example 3 with FormField

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

the class DataForm method toXML.

public String toXML() {
    StringBuilder buf = new StringBuilder();
    buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\" type=\"" + getType() + "\">");
    if (getTitle() != null) {
        buf.append("<title>").append(getTitle()).append("</title>");
    }
    for (Iterator<String> it = getInstructions(); it.hasNext(); ) {
        buf.append("<instructions>").append(it.next()).append("</instructions>");
    }
    // Append the list of fields returned from a search
    if (getReportedData() != null) {
        buf.append(getReportedData().toXML());
    }
    // Loop through all the items returned from a search and append them to the string buffer
    for (Iterator<Item> i = getItems(); i.hasNext(); ) {
        Item item = i.next();
        buf.append(item.toXML());
    }
    // Loop through all the form fields and append them to the string buffer
    for (Iterator<FormField> i = getFields(); i.hasNext(); ) {
        FormField field = i.next();
        buf.append(field.toXML());
    }
    buf.append("</").append(getElementName()).append(">");
    return buf.toString();
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Example 4 with FormField

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

the class UserSearch method buildDataForm.

private static void buildDataForm(SimpleUserSearch search, String instructions, XmlPullParser parser) throws Exception {
    DataForm dataForm = new DataForm(Form.TYPE_FORM);
    boolean done = false;
    dataForm.setTitle("User Search");
    dataForm.addInstruction(instructions);
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG && !parser.getNamespace().equals("jabber:x:data")) {
            String name = parser.getName();
            FormField field = new FormField(name);
            // Handle hard coded values.
            if (name.equals("first")) {
                field.setLabel("First Name");
            } else if (name.equals("last")) {
                field.setLabel("Last Name");
            } else if (name.equals("email")) {
                field.setLabel("Email Address");
            } else if (name.equals("nick")) {
                field.setLabel("Nickname");
            }
            field.setType(FormField.TYPE_TEXT_SINGLE);
            dataForm.addField(field);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        } else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
            search.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
            done = true;
        }
    }
    if (search.getExtension("x", "jabber:x:data") == null) {
        search.addExtension(dataForm);
    }
}
Also used : DataForm(org.jivesoftware.smackx.packet.DataForm) FormField(org.jivesoftware.smackx.FormField)

Example 5 with FormField

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

the class EntityCapsManager method generateVerificationString.

/**
 * Generates a XEP-115 Verification String
 *
 * @see <a href="http://xmpp.org/extensions/xep-0115.html#ver">XEP-115
 *      Verification String</a>
 *
 * @param discoverInfo
 * @param hash
 *            the used hash function
 * @return The generated verification String or null if the hash is not
 *         supported
 */
protected static String generateVerificationString(DiscoverInfo discoverInfo, String hash) {
    MessageDigest md = SUPPORTED_HASHES.get(hash.toLowerCase());
    if (md == null)
        return null;
    DataForm extendedInfo = (DataForm) discoverInfo.getExtension(Form.ELEMENT, Form.NAMESPACE);
    // 1. Initialize an empty string S ('sb' in this method).
    // Use StringBuilder as we don't
    StringBuilder sb = new StringBuilder();
    // need thread-safe StringBuffer
    // 2. Sort the service discovery identities by category and then by
    // type and then by xml:lang
    // (if it exists), formatted as CATEGORY '/' [TYPE] '/' [LANG] '/'
    // [NAME]. Note that each slash is included even if the LANG or
    // NAME is not included (in accordance with XEP-0030, the category and
    // type MUST be included.
    SortedSet<DiscoverInfo.Identity> sortedIdentities = new TreeSet<DiscoverInfo.Identity>();
    for (Iterator<DiscoverInfo.Identity> it = discoverInfo.getIdentities(); it.hasNext(); ) sortedIdentities.add(it.next());
    // followed by the '<' character.
    for (Iterator<DiscoverInfo.Identity> it = sortedIdentities.iterator(); it.hasNext(); ) {
        DiscoverInfo.Identity identity = it.next();
        sb.append(identity.getCategory());
        sb.append("/");
        sb.append(identity.getType());
        sb.append("/");
        sb.append(identity.getLanguage() == null ? "" : identity.getLanguage());
        sb.append("/");
        sb.append(identity.getName() == null ? "" : identity.getName());
        sb.append("<");
    }
    // 4. Sort the supported service discovery features.
    SortedSet<String> features = new TreeSet<String>();
    for (Iterator<Feature> it = discoverInfo.getFeatures(); it.hasNext(); ) features.add(it.next().getVar());
    // character
    for (String f : features) {
        sb.append(f);
        sb.append("<");
    }
    // see XEP-0115 5.4 step 3.6
    if (extendedInfo != null && extendedInfo.hasHiddenFormTypeField()) {
        synchronized (extendedInfo) {
            // 6. If the service discovery information response includes
            // XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e.,
            // by the XML character data of the <value/> element).
            SortedSet<FormField> fs = new TreeSet<FormField>(new Comparator<FormField>() {

                public int compare(FormField f1, FormField f2) {
                    return f1.getVariable().compareTo(f2.getVariable());
                }
            });
            FormField ft = null;
            for (Iterator<FormField> i = extendedInfo.getFields(); i.hasNext(); ) {
                FormField f = i.next();
                if (!f.getVariable().equals("FORM_TYPE")) {
                    fs.add(f);
                } else {
                    ft = f;
                }
            }
            // Add FORM_TYPE values
            if (ft != null) {
                formFieldValuesToCaps(ft.getValues(), sb);
            }
            // followed by the '<' character.
            for (FormField f : fs) {
                sb.append(f.getVariable());
                sb.append("<");
                formFieldValuesToCaps(f.getValues(), sb);
            }
        }
    }
    // 8. Ensure that S is encoded according to the UTF-8 encoding (RFC
    // 3269).
    // 9. Compute the verification string by hashing S using the algorithm
    // specified in the 'hash' attribute (e.g., SHA-1 as defined in RFC
    // 3174).
    // The hashed data MUST be generated with binary output and
    // encoded using Base64 as specified in Section 4 of RFC 4648
    // (note: the Base64 output MUST NOT include whitespace and MUST set
    // padding bits to zero).
    byte[] digest = md.digest(sb.toString().getBytes());
    return Base64.encodeBytes(digest);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) Feature(org.jivesoftware.smackx.packet.DiscoverInfo.Feature) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity) TreeSet(java.util.TreeSet) DataForm(org.jivesoftware.smackx.packet.DataForm) MessageDigest(java.security.MessageDigest) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity) 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