001/**
002 *
003 * Copyright © 2014-2020 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.json.packet;
018
019import javax.xml.namespace.QName;
020
021import org.jivesoftware.smack.packet.Stanza;
022
023/**
024 * XMPP JSON Containers as defined in XEP-0335.
025 *
026 * @see <a href="http://xmpp.org/extensions/xep-0335.html">XEP-0335: JSON Containers</a>
027 */
028public class JsonPacketExtension extends AbstractJsonPacketExtension {
029
030    public static final String ELEMENT = "json";
031    public static final String NAMESPACE = "urn:xmpp:json:0";
032    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
033
034    public JsonPacketExtension(String json) {
035        super(json);
036    }
037
038    @Override
039    public String getNamespace() {
040        return NAMESPACE;
041    }
042
043    @Override
044    public String getElementName() {
045        return ELEMENT;
046    }
047
048    /**
049     * Retrieve the JSON stanza extension from the packet.
050     *
051     * @param packet TODO javadoc me please
052     * @return the JSON stanza extension or null.
053     */
054    public static JsonPacketExtension from(Stanza packet) {
055        return packet.getExtension(JsonPacketExtension.class);
056    }
057}