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