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