Java 类org.jivesoftware.smackx.xdata.packet.DataForm 实例源码

项目:mangosta-android    文件:XMPPSession.java   
public void createNodeToAllowComments(String blogPostId) {
    String nodeName = PublishCommentExtension.NODE + "/" + blogPostId;

    PubSubManager pubSubManager = PubSubManager.getInstance(XMPPSession.getInstance().getXMPPConnection());
    try {
        // create node
        ConfigureForm configureForm = new ConfigureForm(DataForm.Type.submit);
        configureForm.setPublishModel(PublishModel.open);
        configureForm.setAccessModel(AccessModel.open);
        Node node = pubSubManager.createNode(nodeName, configureForm);

        // subscribe to comments
        String myJIDString = getUser().toString();
        node.subscribe(myJIDString);
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
        e.printStackTrace();
    }
}
项目:Smack    文件:StreamNegotiator.java   
/**
 * Creates the initiation acceptance stanza(/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.
 */
protected static StreamInitiation createInitiationAccept(
        StreamInitiation streamInitiationOffer, String[] namespaces)
{
    StreamInitiation response = new StreamInitiation();
    response.setTo(streamInitiationOffer.getFrom());
    response.setFrom(streamInitiationOffer.getTo());
    response.setType(IQ.Type.result);
    response.setStanzaId(streamInitiationOffer.getStanzaId());

    DataForm form = new DataForm(DataForm.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;
}
项目:Smack    文件:DataFormProvider.java   
private DataForm.Item parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    List<FormField> fields = new ArrayList<FormField>();
    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "field":
                fields.add(parseField(parser));
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }
    return new DataForm.Item(fields);
}
项目:Smack    文件:DataFormProvider.java   
private DataForm.ReportedData parseReported(XmlPullParser parser) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    List<FormField> fields = new ArrayList<FormField>();
    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "field":
                fields.add(parseField(parser));
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }
    return new DataForm.ReportedData(fields);
}
项目:Smack    文件:EntityCapsManager.java   
/**
 * 
 * @param info
 * @return true if the stanza(/packet) extensions is ill-formed
 */
protected static boolean verifyPacketExtensions(DiscoverInfo info) {
    List<FormField> foundFormTypes = new LinkedList<FormField>();
    for (ExtensionElement pe : info.getExtensions()) {
        if (pe.getNamespace().equals(DataForm.NAMESPACE)) {
            DataForm df = (DataForm) pe;
            for (FormField f : df.getFields()) {
                if (f.getVariable().equals("FORM_TYPE")) {
                    for (FormField fft : foundFormTypes) {
                        if (f.equals(fft))
                            return true;
                    }
                    foundFormTypes.add(f);
                }
            }
        }
    }
    return false;
}
项目:Smack    文件:RoomInfoTest.java   
@Test
public void validateRoomWithForm() {
    DataForm dataForm = new DataForm(DataForm.Type.result);

    FormField desc = new FormField("muc#roominfo_description");
    desc.addValue("The place for all good witches!");
    dataForm.addField(desc);

    FormField subject = new FormField("muc#roominfo_subject");
    subject.addValue("Spells");
    dataForm.addField(subject);

    FormField occupants = new FormField("muc#roominfo_occupants");
    occupants.addValue("3");
    dataForm.addField(occupants);

    DiscoverInfo discoInfo = new DiscoverInfo();
    discoInfo.addExtension(dataForm);
    RoomInfo roomInfo = new RoomInfo(discoInfo);
    assertEquals("The place for all good witches!", roomInfo.getDescription());
    assertEquals("Spells", roomInfo.getSubject());
    assertEquals(3, roomInfo.getOccupantsCount());
}
项目:androidclient    文件:PrivateKeyUploadListener.java   
@Override
public void processStanza(Stanza packet) {
    XMPPConnection conn = getConnection();
    conn.removeAsyncStanzaListener(this);

    IQ iq = (IQ) packet;
    if (iq.getType() != IQ.Type.result) {
        finish(XMPPError.Condition.internal_server_error);
        return;
    }

    DataForm response = iq.getExtension("x", "jabber:x:data");
    if (response == null) {
        finish(XMPPError.Condition.internal_server_error);
        return;
    }

    String token = null;
    FormField field = response.getField("token");
    if (field != null)
        token = field.getValues().get(0);

    EndpointServer from = Preferences.getEndpointServer(getContext());
    finish(token, from != null ? from.toString() : conn.getXMPPServiceDomain().toString());
}
项目:androidclient    文件:PrivateKeyUploadListener.java   
private Stanza prepareKeyPacket() {
    String privatekey = Base64.encodeToString(mPrivateKeyData, Base64.NO_WRAP);

    Registration iq = new Registration();
    iq.setType(IQ.Type.set);
    iq.setTo(getConnection().getServiceName());
    Form form = new Form(DataForm.Type.submit);

    // form type: register#privatekey
    FormField type = new FormField("FORM_TYPE");
    type.setType(FormField.Type.hidden);
    type.addValue("http://kontalk.org/protocol/register#privatekey");
    form.addField(type);

    // private key
    FormField fieldKey = new FormField("privatekey");
    fieldKey.setLabel("Private key");
    fieldKey.setType(FormField.Type.text_single);
    fieldKey.addValue(privatekey);
    form.addField(fieldKey);

    iq.addExtension(form.getDataFormToSend());
    return iq;
}
项目:androidclient    文件:NumberValidator.java   
private Stanza createValidationForm() throws IOException {
    Registration iq = new Registration();
    iq.setType(IQ.Type.set);
    iq.setTo(mConnector.getConnection().getServiceName());
    Form form = new Form(DataForm.Type.submit);

    FormField type = new FormField("FORM_TYPE");
    type.setType(FormField.Type.hidden);
    type.addValue("http://kontalk.org/protocol/register#code");
    form.addField(type);

    if (mValidationCode != null) {
        FormField code = new FormField("code");
        code.setLabel("Validation code");
        code.setType(FormField.Type.text_single);
        code.addValue(mValidationCode.toString());
        form.addField(code);
    }

    iq.addExtension(form.getDataFormToSend());
    return iq;
}
项目:Smack    文件:MultiUserChat.java   
/**
 * Sends a voice request to the MUC. The room moderators usually need to approve this request.
 *
 * @throws NotConnectedException
 * @see <a href="http://xmpp.org/extensions/xep-0045.html#requestvoice">XEP-45 § 7.13 Requesting
 *      Voice</a>
 * @since 4.1
 */
public void requestVoice() throws NotConnectedException {
    DataForm form = new DataForm(DataForm.Type.submit);
    FormField formTypeField = new FormField(FormField.FORM_TYPE);
    formTypeField.addValue(MUCInitialPresence.NAMESPACE + "#request");
    form.addField(formTypeField);
    FormField requestVoiceField = new FormField("muc#role");
    requestVoiceField.setType(FormField.Type.text_single);
    requestVoiceField.setLabel("Requested role");
    requestVoiceField.addValue("participant");
    form.addField(requestVoiceField);
    Message message = new Message(room);
    message.addExtension(form);
    connection.sendStanza(message);
}
项目:Smack    文件:ConfigEventProvider.java   
@Override
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
    if (content.size() == 0)
        return new ConfigurationEvent(attMap.get("node"));
    else
        return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next()));
}
项目:Smack    文件:ReportedData.java   
/**
 * Returns a new ReportedData if the stanza(/packet) is used for reporting data and includes an 
 * extension that matches the elementName and namespace "x","jabber:x:data".
 * 
 * @param packet the stanza(/packet) used for reporting data.
 */
public static ReportedData getReportedDataFrom(Stanza packet) {
    // Check if the packet includes the DataForm extension
    DataForm dataForm = DataForm.from(packet);
    if (dataForm != null) {
        if (dataForm.getReportedData() != null)
            return new ReportedData(dataForm);
    }
    // Otherwise return null
    return null;
}
项目:Smack    文件:FileTransferNegotiator.java   
private FormField getStreamMethodField(DataForm form) {
    for (FormField field : form.getFields()) {
        if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) {
            return field;
        }
    }
    return null;
}
项目:Smack    文件:FileTransferNegotiator.java   
private DataForm createDefaultInitiationForm() {
    DataForm form = new DataForm(DataForm.Type.form);
    FormField field = new FormField(STREAM_DATA_FIELD_NAME);
    field.setType(FormField.Type.list_single);
    if (!IBB_ONLY) {
        field.addOption(new FormField.Option(Bytestream.NAMESPACE));
    }
    field.addOption(new FormField.Option(DataPacketExtension.NAMESPACE));
    form.addField(field);
    return form;
}
项目:Smack    文件:Form.java   
/**
 * Returns a new ReportedData if the stanza(/packet) is used for gathering data and includes an 
 * extension that matches the elementName and namespace "x","jabber:x:data".  
 * 
 * @param packet the stanza(/packet) used for gathering data.
 * @return the data form parsed from the stanza(/packet) or <tt>null</tt> if there was not
 *      a form in the packet.
 */
public static Form getFormFrom(Stanza packet) {
    // Check if the packet includes the DataForm extension
    DataForm dataForm = DataForm.from(packet);
    if (dataForm != null) {
        if (dataForm.getReportedData() == null)
            return new Form(dataForm);
    }
    // Otherwise return null
    return null;
}
项目:Smack    文件:Form.java   
/**
 * Returns a DataForm that serves to send this Form to the server. If the form is of type 
 * submit, it may contain fields with no value. These fields will be removed since they only 
 * exist to assist the user while editing/completing the form in a UI. 
 * 
 * @return the wrapped DataForm.
 */
public DataForm getDataFormToSend() {
    if (isSubmitType()) {
        // Create a new DataForm that contains only the answered fields 
        DataForm dataFormToSend = new DataForm(getType());
        for(FormField field : getFields()) {
            if (!field.getValues().isEmpty()) {
                dataFormToSend.addField(field);
            }
        }
        return dataFormToSend;
    }
    return dataForm;
}
项目:Smack    文件:Form.java   
/**
 * Returns a new Form to submit the completed values. The new Form will include all the fields
 * of the original form except for the fields of type FIXED. Only the HIDDEN fields will 
 * include the same value of the original form. The other fields of the new form MUST be 
 * completed. If a field remains with no answer when sending the completed form, then it won't 
 * be included as part of the completed form.<p>
 * 
 * The reason why the fields with variables are included in the new form is to provide a model 
 * for binding with any UI. This means that the UIs will use the original form (of type 
 * "form") to learn how to render the form, but the UIs will bind the fields to the form of
 * type submit.
 * 
 * @return a Form to submit the completed values.
 */
public Form createAnswerForm() {
    if (!isFormType()) {
        throw new IllegalStateException("Only forms of type \"form\" could be answered");
    }
    // Create a new Form
    Form form = new Form(DataForm.Type.submit);
    for (FormField field : getFields()) {
        // Add to the new form any type of field that includes a variable.
        // Note: The fields of type FIXED are the only ones that don't specify a variable
        if (field.getVariable() != null) {
            FormField newField = new FormField(field.getVariable());
            newField.setType(field.getType());
            form.addField(newField);
            // Set the answer ONLY to the hidden fields 
            if (field.getType() == FormField.Type.hidden) {
                // Since a hidden field could have many values we need to collect them 
                // in a list
                List<String> values = new ArrayList<String>();
                for (String value : field.getValues()) {
                    values.add(value);
                }
                form.setAnswer(field.getVariable(), values);
            }
        }
    }
    return form;
}
项目:Smack    文件:RoomInfoTest.java   
@Test
public void validateRoomWithEmptyForm() {
    DataForm dataForm = new DataForm(DataForm.Type.result);

    DiscoverInfo discoInfo = new DiscoverInfo();
    discoInfo.addExtension(dataForm);
    RoomInfo roomInfo = new RoomInfo(discoInfo);
    assertTrue(roomInfo.getDescription().isEmpty());
    assertTrue(roomInfo.getSubject().isEmpty());
    assertEquals(-1, roomInfo.getOccupantsCount());
}
项目:Smack    文件:ConfigureFormTest.java   
@Test
public void checkChildrenAssocPolicy()
{
    ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
    form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners);
    assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy());
}
项目:Smack    文件:DataLayoutTest.java   
@Test
public void testLayoutFromFile() throws XmlPullParserException, IOException, SmackException {
    DataFormProvider pr = new DataFormProvider();

    XmlPullParser parser = PacketParserUtils.newXmppParser();
    parser.setInput(new InputStreamReader(this.getClass().getResourceAsStream(TEST_INPUT_1), "UTF-8"));
    parser.next();

    DataForm form = pr.parse(parser);
    assertNotNull( form);
    assertEquals(1 , form.getExtensionElements().size());

    DataLayout layout = (DataLayout) form.getExtensionElements().get(0);

    assertEquals(5 , layout.getPageLayout().size());
    assertEquals("Label - & \u00E9 \u00E1 ", layout.getLabel());
    Section section = (Section) layout.getPageLayout().get(1);
    assertEquals("section Label - & \u00E9 \u00E1 ", section.getLabel());
    Text text = (Text)layout.getPageLayout().get(2);
    assertEquals("PageText - & \u00E9 \u00E1 ", text.getText());
    section = (Section) layout.getPageLayout().get(3);
    assertEquals("<html>Number of Persons by<br/> Nationality and Status</html>", section.getLabel());
    text = (Text) layout.getPageLayout().get(4);
    assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());


    assertNotNull( layout.toXML());
    String output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_SPECIAL, output);
}
项目:androidclient    文件:NumberValidator.java   
private String findField(DataForm form, String name) {
    FormField field = form.getField(name);
    if (field != null) {
        List<String> values = field.getValues();
        if (values != null && values.size() > 0) {
            String value = values.get(0);
            return value != null && value.trim().length() > 0 ?
                value : null;
        }
    }
    return null;
}
项目:desktopclient-java    文件:PrivateKeyReceiver.java   
@Override
public void processStanza(Stanza packet) {
    LOGGER.info("response: "+packet);

    mConn.removeSyncStanzaListener(this);
    mConn.disconnect();

    if (!(packet instanceof IQ)) {
        LOGGER.warning("response not an IQ packet");
        finish(null);
        return;
    }
    IQ iq = (IQ) packet;

    if (iq.getType() != IQ.Type.result) {
        LOGGER.warning("ignoring response with IQ type: "+iq.getType());
        this.finish(null);
        return;
    }

    DataForm response = iq.getExtension(DataForm.ELEMENT, DataForm.NAMESPACE);
    if (response == null) {
        this.finish(null);
        return;
    }

    String token = null;
    List<FormField> fields = response.getFields();
    for (FormField field : fields) {
        if ("token".equals(field.getVariable())) {
            token = field.getValues().get(0);
            break;
        }
    }

    this.finish(token);
}
项目:Smack    文件:Workgroup.java   
/**
 * <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.
 * @throws SmackException 
 */
public void joinQueue(Map<String,Object> metadata, String userID) throws XMPPException, SmackException {
    // 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(DataForm.Type.submit);
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        String value = metadata.get(name).toString();

        FormField field = new FormField(name);
        field.setType(FormField.Type.text_single);
        form.addField(field);
        form.setAnswer(name, value);
    }
    joinQueue(form, userID);
}
项目:Smack    文件:AdHocCommandDataProvider.java   
@Override
public AdHocCommandData parse(XmlPullParser parser, int initialDepth)
                throws XmlPullParserException, IOException, SmackException {
    boolean done = false;
    AdHocCommandData adHocCommandData = new AdHocCommandData();
    DataFormProvider dataFormProvider = new DataFormProvider();

    int eventType;
    String elementName;
    String namespace;
    adHocCommandData.setSessionID(parser.getAttributeValue("", "sessionid"));
    adHocCommandData.setNode(parser.getAttributeValue("", "node"));

    // Status
    String status = parser.getAttributeValue("", "status");
    if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.executing);
    }
    else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.completed);
    }
    else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
        adHocCommandData.setStatus(AdHocCommand.Status.canceled);
    }

    // Action
    String action = parser.getAttributeValue("", "action");
    if (action != null) {
        Action realAction = AdHocCommand.Action.valueOf(action);
        if (realAction == null || realAction.equals(Action.unknown)) {
            adHocCommandData.setAction(Action.unknown);
        }
        else {
            adHocCommandData.setAction(realAction);
        }
    }
    while (!done) {
        eventType = parser.next();
        elementName = parser.getName();
        namespace = parser.getNamespace();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("actions")) {
                String execute = parser.getAttributeValue("", "execute");
                if (execute != null) {
                    adHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(execute));
                }
            }
            else if (parser.getName().equals("next")) {
                adHocCommandData.addAction(AdHocCommand.Action.next);
            }
            else if (parser.getName().equals("complete")) {
                adHocCommandData.addAction(AdHocCommand.Action.complete);
            }
            else if (parser.getName().equals("prev")) {
                adHocCommandData.addAction(AdHocCommand.Action.prev);
            }
            else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
                adHocCommandData.setForm((DataForm) dataFormProvider.parse(parser));
            }
            else if (parser.getName().equals("note")) {
                AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
                        parser.getAttributeValue("", "type"));
                String value = parser.nextText();
                adHocCommandData.addNote(new AdHocCommandNote(type, value));
            }
            else if (parser.getName().equals("error")) {
                XMPPError error = PacketParserUtils.parseError(parser);
                adHocCommandData.setError(error);
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("command")) {
                done = true;
            }
        }
    }
    return adHocCommandData;
}
项目:Smack    文件:AdHocCommandData.java   
public void setForm(DataForm form) {
    this.form = form;
}
项目:Smack    文件:SubscribeForm.java   
public SubscribeForm(DataForm configDataForm)
{
    super(configDataForm);
}
项目:Smack    文件:SubscribeForm.java   
public SubscribeForm(DataForm.Type formType)
{
    super(formType);
}
项目:Smack    文件:FormNodeProvider.java   
@Override
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
       return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
}
项目:Smack    文件:UserSearch.java   
private static void buildDataForm(SimpleUserSearch search,
                String instructions, XmlPullParser parser)
                throws XmlPullParserException, IOException, SmackException {
    DataForm dataForm = new DataForm(DataForm.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")) {
            PacketParserUtils.addExtensionElement(search, parser);
            done = true;
        }
    }
    if (search.getExtension("x", "jabber:x:data") == null) {
        search.addExtension(dataForm);
    }
}
项目:Smack    文件:DataFormProvider.java   
@Override
public DataForm parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
                SmackException {
    DataForm.Type dataFormType = DataForm.Type.fromString(parser.getAttributeValue("", "type"));
    DataForm dataForm = new DataForm(dataFormType);
    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            String namespace = parser.getNamespace();
            switch (name) {
            case "instructions":
                dataForm.addInstruction(parser.nextText());
                break;
            case "title":
                dataForm.setTitle(parser.nextText());
                break;
            case "field":
                dataForm.addField(parseField(parser));
                break;
            case "item":
                dataForm.addItem(parseItem(parser));
                break;
            case "reported":
                dataForm.setReportedData(parseReported(parser));
                break;
            // See XEP-133 Example 32 for a corner case where the data form contains this extension.
            case RosterPacket.ELEMENT:
                if (namespace.equals(RosterPacket.NAMESPACE)) {
                    dataForm.addExtensionElement(RosterPacketProvider.INSTANCE.parse(parser));
                }
                break;
            // See XEP-141 Data Forms Layout
            case DataLayout.ELEMENT:
                if (namespace.equals(DataLayout.NAMESPACE)) {
                    dataForm.addExtensionElement(DataLayoutProvider.parse(parser));
                }
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }
    return dataForm;
}
项目:androidclient    文件:RegisterKeyPairListener.java   
private Stanza prepareKeyPacket() {
    if (mKeyRing != null) {
        try {
            String publicKey = Base64.encodeToString(mKeyRing.publicKey.getEncoded(), Base64.NO_WRAP);

            Registration iq = new Registration();
            iq.setType(IQ.Type.set);
            iq.setTo(getConnection().getServiceName());
            Form form = new Form(DataForm.Type.submit);

            // form type: register#key
            FormField type = new FormField("FORM_TYPE");
            type.setType(FormField.Type.hidden);
            type.addValue("http://kontalk.org/protocol/register#key");
            form.addField(type);

            // new (to-be-signed) public key
            FormField fieldKey = new FormField("publickey");
            fieldKey.setLabel("Public key");
            fieldKey.setType(FormField.Type.text_single);
            fieldKey.addValue(publicKey);
            form.addField(fieldKey);

            // old (revoked) public key
            if (mRevoked != null) {
                String revokedKey = Base64.encodeToString(mRevoked.getEncoded(), Base64.NO_WRAP);

                FormField fieldRevoked = new FormField("revoked");
                fieldRevoked.setLabel("Revoked public key");
                fieldRevoked.setType(FormField.Type.text_single);
                fieldRevoked.addValue(revokedKey);
                form.addField(fieldRevoked);
            }

            iq.addExtension(form.getDataFormToSend());
            return iq;
        }
        catch (IOException e) {
            Log.v(MessageCenterService.TAG, "error encoding key", e);
        }
    }

    return null;
}
项目:androidclient    文件:RegisterKeyPairListener.java   
@Override
public void processStanza(Stanza packet) {
    IQ iq = (IQ) packet;
    if (iq.getType() == IQ.Type.result) {
        DataForm response = iq.getExtension("x", "jabber:x:data");
        if (response != null) {
            String publicKey = null;

            // ok! message will be sent
            List<FormField> fields = response.getFields();
            for (FormField field : fields) {
                if ("publickey".equals(field.getVariable())) {
                    publicKey = field.getValues().get(0);
                    break;
                }
            }

            if (!TextUtils.isEmpty(publicKey)) {
                byte[] publicKeyData;
                byte[] privateKeyData;
                byte[] bridgeCertData;
                try {
                    publicKeyData = Base64.decode(publicKey, Base64.DEFAULT);
                    privateKeyData = mKeyRing.secretKey.getEncoded();

                    bridgeCertData = X509Bridge.createCertificate(publicKeyData,
                        mKeyRing.secretKey.getSecretKey(), mPassphrase).getEncoded();
                }
                catch (Exception e) {
                    Log.e(MessageCenterService.TAG, "error decoding key data", e);
                    publicKeyData = null;
                    privateKeyData = null;
                    bridgeCertData = null;
                }

                if (publicKeyData != null && privateKeyData != null && bridgeCertData != null) {

                    // store key data in AccountManager
                    Authenticator.setDefaultPersonalKey(getContext(),
                        publicKeyData, privateKeyData, bridgeCertData,
                        mPassphrase);
                    // invalidate cached personal key
                    getApplication().invalidatePersonalKey();

                    unconfigure();
                    finish();

                    // restart message center
                    MessageCenterService.restart(getApplication());
                }

                // TODO else?
            }
        }
    }
}
项目:androidclient    文件:NumberValidator.java   
private Stanza createRegistrationForm() {
    Registration iq = new Registration();
    iq.setType(IQ.Type.set);
    iq.setTo(mConnector.getConnection().getServiceName());
    Form form = new Form(DataForm.Type.submit);

    FormField type = new FormField("FORM_TYPE");
    type.setType(FormField.Type.hidden);
    type.addValue(Registration.NAMESPACE);
    form.addField(type);

    FormField phone = new FormField("phone");
    phone.setLabel("Phone number");
    phone.setType(FormField.Type.text_single);
    phone.addValue(mPhone);
    form.addField(phone);

    if (mForce) {
        FormField force = new FormField("force");
        force.setLabel("Force registration");
        force.setType(FormField.Type.bool);
        force.addValue(String.valueOf(mForce));
        form.addField(force);
    }

    if (mFallback) {
        FormField fallback = new FormField("fallback");
        fallback.setLabel("Fallback");
        fallback.setType(FormField.Type.bool);
        fallback.addValue(String.valueOf(mFallback));
        form.addField(fallback);
    }
    else {
        // not falling back, ask for our preferred challenge
        FormField challenge = new FormField("challenge");
        challenge.setLabel("Challenge type");
        challenge.setType(FormField.Type.text_single);
        challenge.addValue(DEFAULT_CHALLENGE);
        form.addField(challenge);
    }

    iq.addExtension(form.getDataFormToSend());
    return iq;
}
项目:Chatting-App-    文件:RegisterKeyPairListener.java   
@Override
public void processPacket(Packet packet) {
    IQ iq = (IQ) packet;
    if (iq.getType() == IQ.Type.RESULT) {
        DataForm response = (DataForm) iq.getExtension("x", "jabber:x:data");
        if (response != null) {
            String publicKey = null;

            // ok! message will be sent
            List<FormField> fields = response.getFields();
            for (FormField field : fields) {
                if ("publickey".equals(field.getVariable())) {
                    publicKey = field.getValues().get(0);
                    break;
                }
            }

            if (!TextUtils.isEmpty(publicKey)) {
                byte[] publicKeyData;
                byte[] privateKeyData;
                byte[] bridgeCertData;
                try {
                    publicKeyData = Base64.decode(publicKey, Base64.DEFAULT);
                    privateKeyData = mKeyRing.secretKey.getEncoded();

                    // TODO subjectAltName?
                    bridgeCertData = X509Bridge.createCertificate(publicKeyData,
                        mKeyRing.secretKey.getSecretKey(), mPassphrase, null).getEncoded();
                }
                catch (Exception e) {
                    Log.e(MessageCenterService.TAG, "error decoding key data", e);
                    publicKeyData = null;
                    privateKeyData = null;
                    bridgeCertData = null;
                }

                if (publicKeyData != null && privateKeyData != null && bridgeCertData != null) {

                    // store key data in AccountManager
                    Authenticator.setDefaultPersonalKey(getContext(),
                        publicKeyData, privateKeyData, bridgeCertData,
                        mPassphrase);
                    // invalidate cached personal key
                    getApplication().invalidatePersonalKey();

                    finish();

                    // restart message center
                    MessageCenterService.restart(getApplication());
                }

                // TODO else?
            }
        }
    }
}
项目:Smack    文件:ServiceDiscoveryManager.java   
/**
 * Registers extended discovery information of this XMPP entity. When this
 * client is queried for its information this data form will be returned as
 * specified by XEP-0128.
 * <p>
 *
 * Since no stanza(/packet) is actually sent to the server it is safe to perform this
 * operation before logging to the server. In fact, you may want to
 * configure the extended info before logging to the server so that the
 * information is already available if it is required upon login.
 *
 * @param info
 *            the data form that contains the extend service discovery
 *            information.
 */
public synchronized void setExtendedInfo(DataForm info) {
  extendedInfo = info;
  // Notify others of a state change of SDM. In order to keep the state consistent, this
  // method is synchronized
  renewEntityCapsVersion();
}
项目:Smack    文件:AdHocCommandData.java   
/**
 * Returns the form of the command.
 *
 * @return the data form associated with the command.
 */
public DataForm getForm() {
    return form;
}
项目:Smack    文件:ConfigureForm.java   
/**
 * Create a decorator from an existing {@link DataForm} that has been
 * retrieved from parsing a node configuration request.
 * 
 * @param configDataForm
 */
public ConfigureForm(DataForm configDataForm)
{
    super(configDataForm);
}
项目:Smack    文件:ConfigureForm.java   
/**
 * Create a new form for configuring a node.  This would typically only be used 
 * when creating and configuring a node at the same time via {@link PubSubManager#createNode(String, Form)}, since 
 * configuration of an existing node is typically accomplished by calling {@link LeafNode#getNodeConfiguration()} and
 * using the resulting form to create a answer form.  See {@link #ConfigureForm(Form)}.
 * @param formType
 */
public ConfigureForm(DataForm.Type formType)
{
    super(formType);
}
项目:Smack    文件:Form.java   
/**
 * Creates a new Form that will wrap an existing DataForm. The wrapped DataForm must be
 * used for gathering data. 
 * 
 * @param dataForm the data form used for gathering data. 
 */
public Form(DataForm dataForm) {
    this.dataForm = dataForm;
}
项目:Smack    文件:Form.java   
/**
 * Creates a new Form of a given type from scratch.
 *
 * @param type the form's type (e.g. form, submit,cancel,result).
 */
public Form(DataForm.Type type) {
    this.dataForm = new DataForm(type);
}