aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java
blob: cf993462e4f45ef5ae4694585b9bbe2f7555268e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package de.thedevstack.conversationsplus.xmpp.avatar;

import de.thedevstack.conversationsplus.xmpp.pubsub.PubSubPacketParser;

import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;

/**
 * Parses the IQ Packets for handling Avatars
 * as defined in XEP-0084.
 * @see {@link http://xmpp.org/extensions/xep-0084.html}
 */
public class AvatarPacketParser {
    /**
     * Extracts the base64 encoded avatar data from an IqPacket.
     * @param packet the IqPacket to be parsed.
     * @return base64 encoded avatar data
     */
    public static String parseAvatarData(IqPacket packet) {
        Element items = PubSubPacketParser.findItems(packet);
        String base64Avatar = null;
        if (null != items) {
            Element item = items.findChild("item");
            if (null != item) {
                base64Avatar = item.findChildContent("data", AvatarPacketGenerator.NAMESPACE_AVATAR_DATA);
            }
        }
        return base64Avatar;
    }
}