use of org.jivesoftware.smack.packet.XmlElement 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());
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class Node method getAffiliations.
private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<XmlElement> additionalExtensions, Collection<XmlElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSubElementType pubSubElementType = affiliationsNamespace.type;
PubSub pubSub = createPubsubPacket(IQ.Type.get, new NodeExtension(pubSubElementType, getId()));
if (additionalExtensions != null) {
for (XmlElement pe : additionalExtensions) {
pubSub.addExtension(pe);
}
}
PubSub reply = sendPubsubPacket(pubSub);
if (returnedExtensions != null) {
returnedExtensions.addAll(reply.getExtensions());
}
AffiliationsExtension affilElem = reply.getExtension(pubSubElementType);
return affilElem.getAffiliations();
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class OpenPgpContentElement method getExtension.
/**
* Returns the first extension that matches the specified element name and
* namespace, or <code>null</code> if it doesn't exist. If the provided elementName is null,
* only the namespace is matched. Extensions are
* are arbitrary XML elements in standard XMPP stanzas.
*
* @param elementName the XML element name of the extension. (May be null)
* @param namespace the XML element namespace of the extension.
* @param <PE> type of the ExtensionElement.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
@SuppressWarnings("unchecked")
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
if (namespace == null) {
return null;
}
QName key = new QName(namespace, elementName);
XmlElement packetExtension;
synchronized (payload) {
packetExtension = payload.getFirst(key);
}
if (packetExtension == null) {
return null;
}
return (PE) packetExtension;
}
Aggregations