use of org.jivesoftware.smack.packet.NamedElement in project Smack by igniterealtime.
the class AbstractHttpOverXmppProvider method parseData.
/**
* Parses Data element if any.
*
* @param parser parser
* @return Data or null if no data
*
* @throws XmlPullParserException if an error in the XML parser occurred.
* @throws IOException if an I/O error occurred.
*/
protected AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
NamedElement child = null;
boolean done = false;
AbstractHttpOverXmpp.Data data = null;
/* We are either at start of data or end of req/res */
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
switch(parser.getName()) {
case ELEMENT_TEXT:
child = parseText(parser);
break;
case ELEMENT_BASE_64:
child = parseBase64(parser);
break;
case ELEMENT_CHUNKED_BASE_64:
child = parseChunkedBase64(parser);
break;
case ELEMENT_XML:
child = parseXml(parser);
break;
case ELEMENT_IBB:
child = parseIbb(parser);
break;
case ELEMENT_SIPUB:
// implemented yet
throw new UnsupportedOperationException("sipub is not supported yet");
case ELEMENT_JINGLE:
// implemented yet
throw new UnsupportedOperationException("jingle is not supported yet");
default:
// other elements are not allowed
throw new IllegalArgumentException("unsupported child tag: " + parser.getName());
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals(ELEMENT_DATA)) {
done = true;
}
}
}
data = new AbstractHttpOverXmpp.Data(child);
}
return data;
}
use of org.jivesoftware.smack.packet.NamedElement in project Smack by igniterealtime.
the class ItemValidationTest method parseSimplePayloadItem.
@Test
public void parseSimplePayloadItem() throws Exception {
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
EventElement event = (EventElement) eventExt;
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("foo", payload.getElementName());
assertEquals("smack:test", payload.getNamespace());
assertXmlSimilar(itemContent, payload.toXML().toString());
}
use of org.jivesoftware.smack.packet.NamedElement in project Smack by igniterealtime.
the class ItemValidationTest method parseComplexItem.
@Test
public void parseComplexItem() throws Exception {
String itemContent = "<entry xmlns='http://www.w3.org/2005/Atom'>" + "<title>Soliloquy</title>" + "<summary>" + "To be, or not to be: that is the question:" + "Whether 'tis nobler in the mind to suffer" + "The slings and arrows of outrageous fortune," + "Or to take arms against a sea of troubles," + "And by opposing end them?" + "</summary>" + "<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" + "<id>tag:denmark.lit,2003:entry-32397</id>" + "<published>2003-12-13T18:30:02Z</published>" + "<updated>2003-12-13T18:30:02Z</updated>" + "</entry>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
EventElement event = (EventElement) eventExt;
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("entry", payload.getElementName());
assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
assertXmlSimilar(itemContent, payload.toXML().toString());
}
use of org.jivesoftware.smack.packet.NamedElement in project Smack by igniterealtime.
the class ItemValidationTest method parseBasicItem.
@Test
public void parseBasicItem() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' />" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension) event.getExtensions().get(0)).items.size());
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof Item);
assertEquals("testid1", ((Item) itemExt).getId());
}
use of org.jivesoftware.smack.packet.NamedElement in project Smack by igniterealtime.
the class ItemValidationTest method parseEmptyTag.
@Test
public void parseEmptyTag() throws Exception {
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension) event.getExtensions().get(0)).items.size());
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
assertXmlSimilar(itemContent, item.getPayload().toXML().toString());
}
Aggregations