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);
}
}
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());
}
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);
}
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());
}
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());
}
Aggregations