GcmPacketExtension.java

  1. /**
  2.  *
  3.  * Copyright © 2014 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.gcm.packet;

  18. import org.jivesoftware.smack.packet.Stanza;
  19. import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;

  20. /**
  21.  * XMPP extension elements as used by Google's GCM Cloud Connection Server (XMPP).
  22.  * <p>
  23.  * This extension is semantically the same as {@link org.jivesoftware.smackx.json.packet.JsonPacketExtension}, but with
  24.  * a different element and namespace. It is used to exchange message stanzas with a JSON payload as extension element.
  25.  * </p>
  26.  *
  27.  * @see <a href="https://developer.android.com/google/gcm/ccs.html">GCM Cloud Connection Server (XMPP)</a>
  28.  */
  29. public class GcmPacketExtension extends AbstractJsonPacketExtension {

  30.     public static final String ELEMENT = "gcm";
  31.     public static final String NAMESPACE = "google:mobile:data";

  32.     public GcmPacketExtension(String json) {
  33.         super(json);
  34.     }

  35.     @Override
  36.     public String getNamespace() {
  37.         return NAMESPACE;
  38.     }

  39.     @Override
  40.     public String getElementName() {
  41.         return ELEMENT;
  42.     }

  43.     /**
  44.      * Retrieve the GCM packet extension from the packet.
  45.      *
  46.      * @param packet
  47.      * @return the GCM packet extension or null.
  48.      */
  49.     public static GcmPacketExtension from(Stanza packet) {
  50.         return packet.getExtension(ELEMENT, NAMESPACE);
  51.     }
  52. }