001/**
002 *
003 * Copyright © 2016 Fernando Ramirez
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.push_notifications.element;
018
019import org.jivesoftware.smack.packet.ExtensionElement;
020import org.jivesoftware.smack.packet.Message;
021import org.jivesoftware.smack.util.XmlStringBuilder;
022import org.jivesoftware.smackx.pubsub.packet.PubSub;
023import org.jxmpp.jid.Jid;
024
025/**
026 * Push Notifications elements.
027 * 
028 * @see <a href="http://xmpp.org/extensions/xep-0357.html">XEP-0357: Push
029 *      Notifications</a>
030 * @author Fernando Ramirez
031 * 
032 */
033public class PushNotificationsElements {
034
035    public static final String NAMESPACE = "urn:xmpp:push:0";
036
037    public static class RemoteDisablingExtension implements ExtensionElement {
038
039        public static final String NAMESPACE = PubSub.NAMESPACE;
040        public static final String ELEMENT = PubSub.ELEMENT;
041
042        private final String node;
043        private final Jid userJid;
044
045        public RemoteDisablingExtension(String node, Jid userJid) {
046            this.node = node;
047            this.userJid = userJid;
048        }
049
050        @Override
051        public String getElementName() {
052            return PubSub.ELEMENT;
053        }
054
055        @Override
056        public String getNamespace() {
057            return PubSub.NAMESPACE;
058        }
059
060        /**
061         * Get the node.
062         * 
063         * @return the node
064         */
065        public String getNode() {
066            return node;
067        }
068
069        /**
070         * Get the user JID.
071         * 
072         * @return the user JID
073         */
074        public Jid getUserJid() {
075            return userJid;
076        }
077
078        @Override
079        public CharSequence toXML() {
080            XmlStringBuilder xml = new XmlStringBuilder(this);
081
082            xml.attribute("node", node);
083            xml.rightAngleBracket();
084
085            xml.halfOpenElement("affiliation");
086            xml.attribute("jid", userJid);
087            xml.attribute("affiliation", "none");
088            xml.closeEmptyElement();
089
090            xml.closeElement(this);
091            return xml;
092        }
093
094        public static RemoteDisablingExtension from(Message message) {
095            return message.getExtension(ELEMENT, NAMESPACE);
096        }
097
098    }
099
100}