001/**
002 *
003 * Copyright 2003-2010 Jive Software.
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.attention.packet;
018
019import org.jivesoftware.smack.packet.ExtensionElement;
020import org.jivesoftware.smack.provider.ExtensionElementProvider;
021
022import org.xmlpull.v1.XmlPullParser;
023
024/**
025 * A PacketExtension that implements XEP-0224: Attention
026 *
027 * This extension is expected to be added to message stanzas of type 'headline.'
028 * Please refer to the XEP for more implementation guidelines.
029 *
030 * @author Guus der Kinderen, guus.der.kinderen@gmail.com
031 * @see <a
032 *      href="http://xmpp.org/extensions/xep-0224.html">XEP-0224:&nbsp;Attention</a>
033 */
034public class AttentionExtension implements ExtensionElement {
035
036    /**
037     * The XML element name of an 'attention' extension.
038     */
039    public static final String ELEMENT_NAME = "attention";
040
041    /**
042     * The namespace that qualifies the XML element of an 'attention' extension.
043     */
044    public static final String NAMESPACE = "urn:xmpp:attention:0";
045
046    /*
047     * (non-Javadoc)
048     *
049     * @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
050     */
051    @Override
052    public String getElementName() {
053        return ELEMENT_NAME;
054    }
055
056    /*
057     * (non-Javadoc)
058     *
059     * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
060     */
061    @Override
062    public String getNamespace() {
063        return NAMESPACE;
064    }
065
066    /*
067     * (non-Javadoc)
068     *
069     * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
070     */
071    @Override
072    public String toXML(String enclosingNamespace) {
073        final StringBuilder sb = new StringBuilder();
074        sb.append('<').append(getElementName()).append(" xmlns=\"").append(
075                getNamespace()).append("\"/>");
076        return sb.toString();
077    }
078
079    /**
080     * A {@link ExtensionElementProvider} for the {@link AttentionExtension}. As
081     * Attention elements have no state/information other than the element name
082     * and namespace, this implementation simply returns new instances of
083     * {@link AttentionExtension}.
084     *
085     * @author Guus der Kinderen, guus.der.kinderen@gmail.com
086s     */
087    public static class Provider extends ExtensionElementProvider<AttentionExtension> {
088
089        @Override
090        public AttentionExtension parse(XmlPullParser parser, int initialDepth) {
091            return new AttentionExtension();
092        }
093    }
094}