Home | History | Annotate | Download | only in packet
      1 /**
      2  * $RCSfile$
      3  * $Revision$
      4  * $Date$
      5  *
      6  * Copyright 2003-2010 Jive Software.
      7  *
      8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *     http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  */
     20 package org.jivesoftware.smackx.packet;
     21 
     22 import org.jivesoftware.smack.packet.PacketExtension;
     23 import org.jivesoftware.smack.provider.PacketExtensionProvider;
     24 import org.xmlpull.v1.XmlPullParser;
     25 
     26 /**
     27  * A PacketExtension that implements XEP-0224: Attention
     28  *
     29  * This extension is expected to be added to message stanzas of type 'headline.'
     30  * Please refer to the XEP for more implementation guidelines.
     31  *
     32  * @author Guus der Kinderen, guus.der.kinderen (at) gmail.com
     33  * @see <a
     34  *      href="http://xmpp.org/extensions/xep-0224.html">XEP-0224:&nbsp;Attention</a>
     35  */
     36 public class AttentionExtension implements PacketExtension {
     37 
     38     /**
     39      * The XML element name of an 'attention' extension.
     40      */
     41     public static final String ELEMENT_NAME = "attention";
     42 
     43     /**
     44      * The namespace that qualifies the XML element of an 'attention' extension.
     45      */
     46     public static final String NAMESPACE = "urn:xmpp:attention:0";
     47 
     48     /*
     49      * (non-Javadoc)
     50      *
     51      * @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
     52      */
     53     public String getElementName() {
     54         return ELEMENT_NAME;
     55     }
     56 
     57     /*
     58      * (non-Javadoc)
     59      *
     60      * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
     61      */
     62     public String getNamespace() {
     63         return NAMESPACE;
     64     }
     65 
     66     /*
     67      * (non-Javadoc)
     68      *
     69      * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
     70      */
     71     public String toXML() {
     72         final StringBuilder sb = new StringBuilder();
     73         sb.append("<").append(getElementName()).append(" xmlns=\"").append(
     74                 getNamespace()).append("\"/>");
     75         return sb.toString();
     76     }
     77 
     78     /**
     79      * A {@link PacketExtensionProvider} for the {@link AttentionExtension}. As
     80      * Attention elements have no state/information other than the element name
     81      * and namespace, this implementation simply returns new instances of
     82      * {@link AttentionExtension}.
     83      *
     84      * @author Guus der Kinderen, guus.der.kinderen (at) gmail.com
     85 s     */
     86     public static class Provider implements PacketExtensionProvider {
     87 
     88         /*
     89          * (non-Javadoc)
     90          *
     91          * @see
     92          * org.jivesoftware.smack.provider.PacketExtensionProvider#parseExtension
     93          * (org.xmlpull.v1.XmlPullParser)
     94          */
     95         public PacketExtension parseExtension(XmlPullParser arg0)
     96                 throws Exception {
     97             return new AttentionExtension();
     98         }
     99     }
    100 }
    101