001/**
002 *
003 * Copyright © 2014-2020 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.gcm.packet;
018
019import javax.xml.namespace.QName;
020
021import org.jivesoftware.smack.packet.Stanza;
022
023import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
024
025/**
026 * XMPP extension elements as used by Google's GCM Cloud Connection Server (XMPP).
027 * <p>
028 * This extension is semantically the same as {@link org.jivesoftware.smackx.json.packet.JsonPacketExtension}, but with
029 * a different element and namespace. It is used to exchange message stanzas with a JSON payload as extension element.
030 * </p>
031 *
032 * @see <a href="https://developer.android.com/google/gcm/ccs.html">GCM Cloud Connection Server (XMPP)</a>
033 */
034public class GcmPacketExtension extends AbstractJsonPacketExtension {
035
036    public static final String ELEMENT = "gcm";
037    public static final String NAMESPACE = "google:mobile:data";
038    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
039
040    public GcmPacketExtension(String json) {
041        super(json);
042    }
043
044    @Override
045    public String getNamespace() {
046        return NAMESPACE;
047    }
048
049    @Override
050    public String getElementName() {
051        return ELEMENT;
052    }
053
054    /**
055     * Retrieve the GCM stanza extension from the packet.
056     *
057     * @param packet TODO javadoc me please
058     * @return the GCM stanza extension or null.
059     */
060    public static GcmPacketExtension from(Stanza packet) {
061        return packet.getExtension(GcmPacketExtension.class);
062    }
063}