use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class PacketParserUtils method addExtensionElement.
public static void addExtensionElement(Collection<XmlElement> collection, XmlPullParser parser, String elementName, String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
XmlElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
collection.add(packetExtension);
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class XmppElementUtil method getElementsFrom.
public static <E extends ExtensionElement> List<E> getElementsFrom(MultiMap<QName, XmlElement> elementMap, Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
List<XmlElement> extensionElements = elementMap.getAll(qname);
if (extensionElements.isEmpty()) {
return Collections.emptyList();
}
List<E> res = new ArrayList<>(extensionElements.size());
for (XmlElement extensionElement : extensionElements) {
E e = castOrThrow(extensionElement, extensionElementClass);
res.add(e);
}
return res;
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class Workgroup method handlePacket.
// PacketListener Implementation.
private void handlePacket(Stanza packet) {
if (packet instanceof Message) {
Message msg = (Message) packet;
// Check to see if the user left the queue.
XmlElement pe = msg.getExtensionElement("depart-queue", "http://jabber.org/protocol/workgroup");
XmlElement queueStatus = msg.getExtensionElement("queue-status", "http://jabber.org/protocol/workgroup");
if (pe != null) {
fireQueueDepartedEvent();
} else if (queueStatus != null) {
QueueUpdate queueUpdate = (QueueUpdate) queueStatus;
if (queueUpdate.getPosition() != -1) {
fireQueuePositionEvent(queueUpdate.getPosition());
}
if (queueUpdate.getRemaingTime() != -1) {
fireQueueTimeEvent(queueUpdate.getRemaingTime());
}
} else {
// Check if a room invitation was sent and if the sender is the workgroup
MUCUser mucUser = MUCUser.from(msg);
MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
if (invite != null && workgroupJID.equals(invite.getFrom())) {
String sessionID = null;
Map<String, List<String>> metaData = null;
pe = msg.getExtensionElement(SessionID.ELEMENT_NAME, SessionID.NAMESPACE);
if (pe != null) {
sessionID = ((SessionID) pe).getSessionID();
}
pe = msg.getExtensionElement(MetaData.ELEMENT_NAME, MetaData.NAMESPACE);
if (pe != null) {
metaData = ((MetaData) pe).getMetaData();
}
WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(), workgroupJID, sessionID, msg.getBody(), msg.getFrom(), metaData);
fireInvitationEvent(inv);
}
}
}
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class EligibleForChatMarkerFilter method accept.
/**
* From XEP-0333, Protocol Format: The Chat Marker MUST have an 'id' which is the 'id' of the
* message being marked.<br>
* In order to make Chat Markers works together with XEP-0085 as it said in
* 8.5 Interaction with Chat States, only messages with <code>active</code> chat
* state are accepted.
*
* @param message to be analyzed.
* @return true if the message contains a stanza Id.
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat Markers</a>
*/
@Override
public boolean accept(Stanza message) {
if (!message.hasStanzaIdSet()) {
return false;
}
if (super.accept(message)) {
XmlElement extension = message.getExtension(ChatStateManager.NAMESPACE);
String chatStateElementName = extension.getElementName();
ChatState state;
try {
state = ChatState.valueOf(chatStateElementName);
return state == ChatState.active;
} catch (Exception ex) {
return false;
}
}
return true;
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class RegistrationProvider method parse.
@Override
public Registration parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
String instruction = null;
Map<String, String> fields = new HashMap<>();
List<XmlElement> packetExtensions = new LinkedList<>();
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
// attempt to parse it if it's in the form <name>value</name>.
if (parser.getNamespace().equals(Registration.NAMESPACE)) {
String name = parser.getName();
String value = "";
if (parser.next() == XmlPullParser.Event.TEXT_CHARACTERS) {
value = parser.getText();
}
// Ignore instructions, but anything else should be added to the map.
if (!name.equals("instructions")) {
fields.put(name, value);
} else {
instruction = value;
}
} else // Otherwise, it must be a packet extension.
{
PacketParserUtils.addExtensionElement(packetExtensions, parser, xmlEnvironment);
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals(IQ.QUERY_ELEMENT)) {
break outerloop;
}
}
}
Registration registration = new Registration(instruction, fields);
registration.addExtensions(packetExtensions);
return registration;
}
Aggregations