Search in sources :

Example 91 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.

the class AMPExtensionTest method isCorrectFromXmlErrorHandling.

@Test
public void isCorrectFromXmlErrorHandling() throws Exception {
    AMPExtensionProvider ampProvider = new AMPExtensionProvider();
    XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(INCORRECT_RECEIVING_STANZA_STREAM, "UTF-8");
    assertEquals(XmlPullParser.START_TAG, parser.next());
    assertEquals(AMPExtension.ELEMENT, parser.getName());
    ExtensionElement extension = ampProvider.parse(parser);
    assertTrue(extension instanceof AMPExtension);
    AMPExtension amp = (AMPExtension) extension;
    assertEquals(0, amp.getRulesCount());
    assertEquals(AMPExtension.Status.alert, amp.getStatus());
    assertEquals("bernardo@hamlet.lit/elsinore", amp.getFrom());
    assertEquals("francisco@hamlet.lit", amp.getTo());
}
Also used : AMPExtensionProvider(org.jivesoftware.smackx.amp.provider.AMPExtensionProvider) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) AMPExtension(org.jivesoftware.smackx.amp.packet.AMPExtension) Test(org.junit.Test)

Example 92 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.

the class AMPExtensionTest method isCorrectFromXmlDeserialization.

@Test
public void isCorrectFromXmlDeserialization() throws Exception {
    AMPExtensionProvider ampProvider = new AMPExtensionProvider();
    XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(CORRECT_SENDING_STANZA_STREAM, "UTF-8");
    assertEquals(XmlPullParser.START_TAG, parser.next());
    assertEquals(AMPExtension.ELEMENT, parser.getName());
    ExtensionElement extension = ampProvider.parse(parser);
    assertTrue(extension instanceof AMPExtension);
    AMPExtension amp = (AMPExtension) extension;
    assertEquals(9, amp.getRulesCount());
}
Also used : AMPExtensionProvider(org.jivesoftware.smackx.amp.provider.AMPExtensionProvider) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) AMPExtension(org.jivesoftware.smackx.amp.packet.AMPExtension) Test(org.junit.Test)

Example 93 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.

the class OpenIQProviderTest method getParser.

private static XmlPullParser getParser(String control) throws XmlPullParserException, IOException {
    XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
    parser.setInput(new StringReader(control));
    while (true) {
        if (parser.next() == XmlPullParser.START_TAG && parser.getName().equals("open")) {
            break;
        }
    }
    return parser;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader)

Example 94 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.

the class PacketParserUtils method getParserFor.

public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
    XmlPullParser parser = newXmppParser(reader);
    // Wind the parser forward to the first start tag
    int event = parser.getEventType();
    while (event != XmlPullParser.START_TAG) {
        if (event == XmlPullParser.END_DOCUMENT) {
            throw new IllegalArgumentException("Document contains no start tag");
        }
        event = parser.next();
    }
    return parser;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 95 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.

the class PacketParserUtils method newXmppParser.

/**
     * Creates a new XmlPullParser suitable for parsing XMPP. This means in particular that
     * FEATURE_PROCESS_NAMESPACES is enabled.
     * <p>
     * Note that not all XmlPullParser implementations will return a String on
     * <code>getText()</code> if the parser is on START_TAG or END_TAG. So you must not rely on this
     * behavior when using the parser.
     * </p>
     * 
     * @param reader
     * @return A suitable XmlPullParser for XMPP parsing
     * @throws XmlPullParserException
     */
public static XmlPullParser newXmppParser(Reader reader) throws XmlPullParserException {
    XmlPullParser parser = newXmppParser();
    parser.setInput(reader);
    return parser;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)673 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)623 IOException (java.io.IOException)377 FileInputStream (java.io.FileInputStream)185 FileNotFoundException (java.io.FileNotFoundException)185 File (java.io.File)107 ArrayList (java.util.ArrayList)77 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)45 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)30 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28