org.jivesoftware.smack.provider
Class EmbeddedExtensionProvider
java.lang.Object
org.jivesoftware.smack.provider.EmbeddedExtensionProvider
- All Implemented Interfaces:
- PacketExtensionProvider
public abstract class EmbeddedExtensionProvider
- extends Object
- implements PacketExtensionProvider
This class simplifies parsing of embedded elements by using the
Template Method Pattern.
After extracting the current element attributes and content of any child elements, the template method
(createReturnExtension(String, String, Map, List)
is called. Subclasses
then override this method to create the specific return type.
To use this class, you simply register your subclasses as extension providers in the
smack.properties file. Then they will be automatically picked up and used to parse
any child elements.
For example, given the following message
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo>
<event xmlns='http://jabber.org/protocol/pubsub#event>
<items node='princely_musings'>
<item id='asdjkwei3i34234n356'>
<entry xmlns='http://www.w3.org/2005/Atom'>
<title>Soliloquy</title>
<link rel='alternative' type='text/html'/>
<id>tag:denmark.lit,2003:entry-32397</id>
</entry>
</item>
</items>
</event>
</message>
I would have a classes
ItemsProvider
extends EmbeddedExtensionProvider
ItemProvider
extends EmbeddedExtensionProvider
and
AtomProvider extends PacketExtensionProvider
These classes are then registered in the meta-inf/smack.providers file
as follows.
<extensionProvider>
<elementName>items</elementName>
<namespace>http://jabber.org/protocol/pubsub#event</namespace>
<className>org.jivesoftware.smackx.provider.ItemsEventProvider</className>
</extensionProvider>
<extensionProvider>
<elementName>item</elementName>
<namespace>http://jabber.org/protocol/pubsub#event</namespace>
<className>org.jivesoftware.smackx.provider.ItemProvider</className>
</extensionProvider>
- Author:
- Robin Collier
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EmbeddedExtensionProvider
public EmbeddedExtensionProvider()
parseExtension
public final PacketExtension parseExtension(org.xmlpull.v1.XmlPullParser parser)
throws Exception
- Description copied from interface:
PacketExtensionProvider
- Parse an extension sub-packet and create a PacketExtension instance. At
the beginning of the method call, the xml parser will be positioned on the
opening element of the packet extension. At the end of the method call, the
parser must be positioned on the closing element of the packet extension.
- Specified by:
parseExtension
in interface PacketExtensionProvider
- Parameters:
parser
- an XML parser.
- Returns:
- a new IQ instance.
- Throws:
Exception
- if an error occurs parsing the XML.
createReturnExtension
protected abstract PacketExtension createReturnExtension(String currentElement,
String currentNamespace,
Map<String,String> attributeMap,
List<? extends PacketExtension> content)
Copyright © 2003-2007 Jive Software.