Search in sources :

Example 96 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project violations-plugin by jenkinsci.

the class ParseXML method parse.

/**
     * Parse an Input stream using a parser object.
     * @param in the stream to parse.
     * @param xmlParser the parser object.
     * @throws IOException if there is a problem.
     */
public static void parse(InputStream in, AbstractParser xmlParser) throws IOException {
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new XmlReader(in));
        xmlParser.setParser(parser);
        xmlParser.execute();
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new IOException2(ex);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 97 with XmlPullParser

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

the class DisplayedExtensionTest method checkDisplayedProvider.

@Test
public void checkDisplayedProvider() throws Exception {
    XmlPullParser parser = PacketParserUtils.getParserFor(displayedExtension);
    DisplayedExtension displayedExtension1 = new DisplayedProvider().parse(parser);
    Assert.assertEquals("message-1", displayedExtension1.getId());
    Message message = (Message) PacketParserUtils.parseStanza(displayedMessageStanza);
    DisplayedExtension displayedExtension2 = DisplayedExtension.from(message);
    Assert.assertEquals("message-1", displayedExtension2.getId());
}
Also used : Message(org.jivesoftware.smack.packet.Message) DisplayedExtension(org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension) XmlPullParser(org.xmlpull.v1.XmlPullParser) DisplayedProvider(org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider) Test(org.junit.Test)

Example 98 with XmlPullParser

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

the class AbstractHttpOverXmppProviderTest method areRespHeadersParsedCorrectly.

@Test
public void areRespHeadersParsedCorrectly() throws Exception {
    String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>" + "<headers xmlns='http://jabber.org/protocol/shim'>" + "<header name='Date'>Fri, 03 May 2013 13:52:10 GMT-4</header>" + "<header name='Allow'>OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE</header>" + "<header name='Content-Length'>0</header>" + "</headers>" + "</resp>";
    Map<String, String> expectedHeaders = new HashMap<String, String>();
    expectedHeaders.put("Date", "Fri, 03 May 2013 13:52:10 GMT-4");
    expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE");
    expectedHeaders.put("Content-Length", "0");
    HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppResp);
    HttpOverXmppResp body = ((HttpOverXmppResp) iq);
    checkHeaders(body.getHeaders(), expectedHeaders);
}
Also used : HttpOverXmppResp(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp) HashMap(java.util.HashMap) XmlPullParser(org.xmlpull.v1.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 99 with XmlPullParser

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

the class Base64BinaryChunkProviderTest method isNonLatsChunkParsedCorrectly.

@Test
public void isNonLatsChunkParsedCorrectly() throws Exception {
    String base64Text = "iVBORw0KGgoAAAANSUhEUgAAASwAAAGQCAYAA";
    String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' nr='0'>" + base64Text + "</chunk>";
    Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    ExtensionElement extension = provider.parse(parser);
    assertTrue(extension instanceof Base64BinaryChunk);
    Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
    assertEquals("Stream0001", chunk.getStreamId());
    assertFalse(chunk.isLast());
    assertEquals(base64Text, chunk.getText());
    assertEquals(0, chunk.getNr());
}
Also used : Base64BinaryChunk(org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Test(org.junit.Test)

Example 100 with XmlPullParser

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

the class CarbonTest method carbonReceivedTest.

@Test
public void carbonReceivedTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    control = XMLBuilder.create("received").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    assertEquals(CarbonExtension.Direction.received, cc.getDirection());
    // check end of tag
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("received", parser.getName());
}
Also used : CarbonManagerProvider(org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExperimentalInitializerTest(org.jivesoftware.smackx.ExperimentalInitializerTest) Test(org.junit.Test)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)665 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)614 IOException (java.io.IOException)376 FileNotFoundException (java.io.FileNotFoundException)185 FileInputStream (java.io.FileInputStream)184 File (java.io.File)107 ArrayList (java.util.ArrayList)75 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)42 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)29 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28