PushNotificationsElements.java

  1. /**
  2.  *
  3.  * Copyright © 2016 Fernando Ramirez
  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.push_notifications.element;

  18. import javax.xml.namespace.QName;

  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.packet.Message;
  21. import org.jivesoftware.smack.util.XmlStringBuilder;

  22. import org.jivesoftware.smackx.pubsub.packet.PubSub;

  23. import org.jxmpp.jid.Jid;

  24. /**
  25.  * Push Notifications elements.
  26.  *
  27.  * @see <a href="http://xmpp.org/extensions/xep-0357.html">XEP-0357: Push
  28.  *      Notifications</a>
  29.  * @author Fernando Ramirez
  30.  *
  31.  */
  32. public class PushNotificationsElements {

  33.     public static final String NAMESPACE = "urn:xmpp:push:0";

  34.     public static class RemoteDisablingExtension implements ExtensionElement {

  35.         public static final String NAMESPACE = PubSub.NAMESPACE;
  36.         public static final String ELEMENT = PubSub.ELEMENT;
  37.         public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

  38.         private final String node;
  39.         private final Jid userJid;

  40.         public RemoteDisablingExtension(String node, Jid userJid) {
  41.             this.node = node;
  42.             this.userJid = userJid;
  43.         }

  44.         @Override
  45.         public String getElementName() {
  46.             return PubSub.ELEMENT;
  47.         }

  48.         @Override
  49.         public String getNamespace() {
  50.             return PubSub.NAMESPACE;
  51.         }

  52.         /**
  53.          * Get the node.
  54.          *
  55.          * @return the node
  56.          */
  57.         public String getNode() {
  58.             return node;
  59.         }

  60.         /**
  61.          * Get the user JID.
  62.          *
  63.          * @return the user JID
  64.          */
  65.         public Jid getUserJid() {
  66.             return userJid;
  67.         }

  68.         @Override
  69.         public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  70.             XmlStringBuilder xml = new XmlStringBuilder(this);

  71.             xml.attribute("node", node);
  72.             xml.rightAngleBracket();

  73.             xml.halfOpenElement("affiliation");
  74.             xml.attribute("jid", userJid);
  75.             xml.attribute("affiliation", "none");
  76.             xml.closeEmptyElement();

  77.             xml.closeElement(this);
  78.             return xml;
  79.         }

  80.         public static RemoteDisablingExtension from(Message message) {
  81.             return message.getExtension(RemoteDisablingExtension.class);
  82.         }

  83.     }

  84. }