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