mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-15 07:21:08 +01:00
Rework Smack Provider design
this is the first stop towards fixing "SMACK-65: parsing should look for depth", by providing the initial parsing depth to the provider. Some methods (.e.g parseMessage) now use the depth as abort condition, instead of a unclean String equals check. parseIQ() and parseExtension() where both renamed to parse. This also restricts the Exceptions thrown by the parse method, to just XmlPullParserException, IOException and SmackException (not really a big victory, but nevertheless a slight improvement). StreamFeatureProvider is now gone, we simply use PacketExtensionProvider for stream features.
This commit is contained in:
parent
d04517cd08
commit
6980c8e63d
137 changed files with 1101 additions and 841 deletions
|
|
@ -29,10 +29,10 @@ import org.jivesoftware.smackx.pubsub.Affiliation;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class AffiliationProvider extends EmbeddedExtensionProvider
|
||||
public class AffiliationProvider extends EmbeddedExtensionProvider<Affiliation>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected Affiliation createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new Affiliation(attributeMap.get("node"), Affiliation.Type.valueOf(attributeMap.get("affiliation")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.AffiliationsExtension;
|
|||
* as specified in the <a href="http://xmpp.org/extensions/xep-0060.html#schemas-pubsub">affiliation schema</a>.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*/public class AffiliationsProvider extends EmbeddedExtensionProvider
|
||||
*/public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension>
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new AffiliationsExtension((List<Affiliation>)content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class ConfigEventProvider extends EmbeddedExtensionProvider
|
||||
public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
|
||||
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
if (content.size() == 0)
|
||||
return new ConfigurationEvent(attMap.get("node"));
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ import org.jivesoftware.smackx.pubsub.NodeExtension;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class EventProvider extends EmbeddedExtensionProvider
|
||||
public class EventProvider extends EmbeddedExtensionProvider<EventElement>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
|
||||
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class FormNodeProvider extends EmbeddedExtensionProvider
|
||||
public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.pubsub.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
|
|
@ -25,6 +28,7 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
|
|||
import org.jivesoftware.smackx.pubsub.SimplePayload;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Parses an <b>item</b> element as is defined in both the {@link PubSubNamespace#BASIC} and
|
||||
|
|
@ -34,10 +38,11 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class ItemProvider implements PacketExtensionProvider
|
||||
public class ItemProvider extends PacketExtensionProvider<Item>
|
||||
{
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
@Override
|
||||
public Item parse(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
String id = parser.getAttributeValue(null, "id");
|
||||
String node = parser.getAttributeValue(null, "node");
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class ItemsProvider extends EmbeddedExtensionProvider
|
||||
public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension>
|
||||
{
|
||||
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.pubsub.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
|
|
@ -23,6 +26,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Parses the root pubsub packet extensions of the {@link IQ} packet and returns
|
||||
|
|
@ -30,10 +34,11 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class PubSubProvider implements IQProvider
|
||||
public class PubSubProvider extends IQProvider<PubSub>
|
||||
{
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception
|
||||
{
|
||||
@Override
|
||||
public PubSub parse(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
PubSub pubsub = new PubSub();
|
||||
String namespace = parser.getNamespace();
|
||||
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.RetractItem;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class RetractEventProvider extends EmbeddedExtensionProvider
|
||||
public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new RetractItem(attributeMap.get("id"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class SimpleNodeProvider extends EmbeddedExtensionProvider
|
||||
public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension>
|
||||
{
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.pubsub.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.pubsub.Subscription;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Parses the <b>subscription</b> element out of the pubsub IQ message from
|
||||
|
|
@ -27,10 +29,11 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class SubscriptionProvider implements PacketExtensionProvider
|
||||
public class SubscriptionProvider extends PacketExtensionProvider<Subscription>
|
||||
{
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
@Override
|
||||
public Subscription parse(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException {
|
||||
String jid = parser.getAttributeValue(null, "jid");
|
||||
String nodeId = parser.getAttributeValue(null, "node");
|
||||
String subId = parser.getAttributeValue(null, "subid");
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
|
|||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class SubscriptionsProvider extends EmbeddedExtensionProvider
|
||||
public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension>
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
|
||||
{
|
||||
return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue