package de.thedevstack.conversationsplus.xmpp.pubsub;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
/**
* Parses the IQ Packets for handling pubsub
* as defined in XEP-0060.
* @see http://xmpp.org/extensions/xep-0060.html
*/
public final class PubSubPacketParser {
/**
* Finds the pubsub element within an IQ packet.
* @param packet the retrieved IQ packet
* @return the {@value PubSubPacket#ELEMENT_NAME} Element or null
if the IqPacket is null or the IQ packet does not contain an pubsub element.
*/
public static Element findPubSubPacket(IqPacket packet){
if (null == packet) {
return null;
}
return packet.findChild(PubSubPacket.ELEMENT_NAME, PubSubPacket.NAMESPACE);
}
/**
* Finds the "items" element within an pubSubPacket element.
* @param pubSubPacket the pubSubPacket element
* @return the items Element or null
if the pubSubPacket is null or the pubSubPacket does not contain an items element.
*/
public static Element findItemsFromPubSubElement(Element pubSubPacket) {
if (null == pubSubPacket) {
return null;
}
return pubSubPacket.findChild("items");
}
/**
* Finds the "items" element within an pubSubPacket element.
* @param packet the IqPacket element
* @return the items Element or null
if the IqPacket is null or the IQ packet does not contain an pubsub element with an items element.
*/
public static Element findItems(IqPacket packet) {
return PubSubPacketParser.findItemsFromPubSubElement(PubSubPacketParser.findPubSubPacket(packet));
}
/**
* Utility class - avoid instantiation
*/
private PubSubPacketParser() {
// Avoid instantiation
}
}