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;
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 ExtensionElement {
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    @Override
051    public String getElementName() {
052        return ELEMENT_NAME;
053    }
054
055    /*
056     * (non-Javadoc)
057     * 
058     * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
059     */
060    @Override
061    public String getNamespace() {
062        return NAMESPACE;
063    }
064
065    /*
066     * (non-Javadoc)
067     * 
068     * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
069     */
070    @Override
071    public String toXML() {
072        final StringBuilder sb = new StringBuilder();
073        sb.append('<').append(getElementName()).append(" xmlns=\"").append(
074                getNamespace()).append("\"/>");
075        return sb.toString();
076    }
077
078    /**
079     * A {@link ExtensionElementProvider} for the {@link AttentionExtension}. As
080     * Attention elements have no state/information other than the element name
081     * and namespace, this implementation simply returns new instances of
082     * {@link AttentionExtension}.
083     * 
084     * @author Guus der Kinderen, guus.der.kinderen@gmail.com
085s     */
086    public static class Provider extends ExtensionElementProvider<AttentionExtension> {
087
088        @Override
089        public AttentionExtension parse(XmlPullParser parser, int initialDepth) {
090            return new AttentionExtension();
091        }
092    }
093}