001/**
002 *
003 * Copyright © 2014 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 org.jivesoftware.smack.packet.Stanza;
020
021import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
022
023/**
024 * XMPP extension elements as used by Google's GCM Cloud Connection Server (XMPP).
025 * <p>
026 * This extension is semantically the same as {@link org.jivesoftware.smackx.json.packet.JsonPacketExtension}, but with
027 * a different element and namespace. It is used to exchange message stanzas with a JSON payload as extension element.
028 * </p>
029 *
030 * @see <a href="https://developer.android.com/google/gcm/ccs.html">GCM Cloud Connection Server (XMPP)</a>
031 */
032public class GcmPacketExtension extends AbstractJsonPacketExtension {
033
034    public static final String ELEMENT = "gcm";
035    public static final String NAMESPACE = "google:mobile:data";
036
037    public GcmPacketExtension(String json) {
038        super(json);
039    }
040
041    @Override
042    public String getNamespace() {
043        return NAMESPACE;
044    }
045
046    @Override
047    public String getElementName() {
048        return ELEMENT;
049    }
050
051    /**
052     * Retrieve the GCM stanza extension from the packet.
053     *
054     * @param packet
055     * @return the GCM stanza extension or null.
056     */
057    public static GcmPacketExtension from(Stanza packet) {
058        return packet.getExtension(ELEMENT, NAMESPACE);
059    }
060}