AttentionExtension.java

  1. /**
  2.  *
  3.  * Copyright 2003-2010 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.attention.packet;

  18. import org.jivesoftware.smack.packet.ExtensionElement;
  19. import org.jivesoftware.smack.provider.ExtensionElementProvider;
  20. import org.xmlpull.v1.XmlPullParser;

  21. /**
  22.  * A PacketExtension that implements XEP-0224: Attention
  23.  *
  24.  * This extension is expected to be added to message stanzas of type 'headline.'
  25.  * Please refer to the XEP for more implementation guidelines.
  26.  *
  27.  * @author Guus der Kinderen, guus.der.kinderen@gmail.com
  28.  * @see <a
  29.  *      href="http://xmpp.org/extensions/xep-0224.html">XEP-0224:&nbsp;Attention</a>
  30.  */
  31. public class AttentionExtension implements ExtensionElement {

  32.     /**
  33.      * The XML element name of an 'attention' extension.
  34.      */
  35.     public static final String ELEMENT_NAME = "attention";

  36.     /**
  37.      * The namespace that qualifies the XML element of an 'attention' extension.
  38.      */
  39.     public static final String NAMESPACE = "urn:xmpp:attention:0";

  40.     /*
  41.      * (non-Javadoc)
  42.      *
  43.      * @see org.jivesoftware.smack.packet.PacketExtension#getElementName()
  44.      */
  45.     public String getElementName() {
  46.         return ELEMENT_NAME;
  47.     }

  48.     /*
  49.      * (non-Javadoc)
  50.      *
  51.      * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace()
  52.      */
  53.     public String getNamespace() {
  54.         return NAMESPACE;
  55.     }

  56.     /*
  57.      * (non-Javadoc)
  58.      *
  59.      * @see org.jivesoftware.smack.packet.PacketExtension#toXML()
  60.      */
  61.     public String toXML() {
  62.         final StringBuilder sb = new StringBuilder();
  63.         sb.append("<").append(getElementName()).append(" xmlns=\"").append(
  64.                 getNamespace()).append("\"/>");
  65.         return sb.toString();
  66.     }

  67.     /**
  68.      * A {@link ExtensionElementProvider} for the {@link AttentionExtension}. As
  69.      * Attention elements have no state/information other than the element name
  70.      * and namespace, this implementation simply returns new instances of
  71.      * {@link AttentionExtension}.
  72.      *
  73.      * @author Guus der Kinderen, guus.der.kinderen@gmail.com
  74. s     */
  75.     public static class Provider extends ExtensionElementProvider<AttentionExtension> {

  76.         @Override
  77.         public AttentionExtension parse(XmlPullParser parser, int initialDepth) {
  78.             return new AttentionExtension();
  79.         }
  80.     }
  81. }