Java 类org.jivesoftware.smackx.xdata.provider.DataFormProvider 实例源码

项目: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    文件:SmackInitializer.java   
/**
 * Initializes Smack for registration.
 */
public static void initializeRegistration() {
    disableSmackDefault();
    // not moving these into configuration since they are not loaded often
    ProviderManager.addIQProvider("query", "jabber:iq:register", new RegistrationProvider());
    ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
    ProviderManager.addExtensionProvider(Account.ELEMENT_NAME, Account.NAMESPACE, new Account.Provider());
}
项目: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;
}
项目:Chatting-App-    文件:NumberValidator.java   
private void configure() {
    ProviderManager.addIQProvider("query", "jabber:iq:register", new RegistrationFormProvider());
    ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
}