1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +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:
Florian Schmaus 2014-10-07 21:15:20 +02:00
parent d04517cd08
commit 6980c8e63d
137 changed files with 1101 additions and 841 deletions

View file

@ -65,7 +65,10 @@ introspection is used to try to automatically set properties of the IQ
instance using the values found in the IQ packet XML. For example, an XMPP instance using the values found in the IQ packet XML. For example, an XMPP
time packet resembles the following: time packet resembles the following:
### Introspection ### Introspection (DEPRECATED)
*Note*: This feature is deprecated, using introspection for parsing is not recommended.
Instead implement your own provider like shown in the next section.
_Time Packet_ _Time Packet_
@ -112,7 +115,65 @@ The introspection service will automatically try to convert the String value
from the XML into a boolean, int, long, float, double, or Class depending on from the XML into a boolean, int, long, float, double, or Class depending on
the type the IQ instance expects. the type the IQ instance expects.
_IQProvider Implementation_ ### Custom IQProvider example
Let's assume you want to write a provider for a new, unsupported IQ in Smack.
_Custom IQ_
```
<iq type='set' from='juliet@capulet.example/balcony' to='romeo@montage.example'>
<myiq xmlns='example:iq:foo' token='secret'>
<user age='42'>John Doe</user>
<location>New York</location>
</myiq>
</iq>
```
_Custom IQ Provider_
```java
public class MyIQProvider extends IQProvider<MyIQ> {
@Override
public MyIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
// Define the data we are trying to collect with sane defaults
int age = -1;
String user = null;
String location = null;
// Start parsing loop
outerloop: while(true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
switch (elementName) {
case "user":
age = ParserUtils.getIntegerAttribute(parser, "age");
user = parser.nextText();
break;
case "location"
location = parser.nextText();
break;
}
break;
case XmlPullParser.END_TAG:
// Abort condition: if the are on a end tag (closing element) of the same depth
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
// Construct the IQ instance at the end of parsing, when all data has been collected
return new MyIQ(user, age, location);
}
}
```
### DiscoItemsProvider
_Disco Items Packet_ _Disco Items Packet_
@ -136,37 +197,48 @@ _Disco Items IQProvider_
public class DiscoverItemsProvider implements IQProvider { public class DiscoverItemsProvider implements IQProvider<DiscoverItems> {
public IQ parseIQ(XmlPullParser parser) throws Exception { public DiscoverItems parseIQ(XmlPullParser parser, int initialDepth) throw XmlPullParserException, IOException {
DiscoverItems discoverItems = new DiscoverItems(); DiscoverItems discoverItems = new DiscoverItems();
boolean done = false;
DiscoverItems.Item item; DiscoverItems.Item item;
String jid = ""; String jid = "";
String name = ""; String name = "";
String action = ""; String action = "";
String node = ""; String node = "";
discoverItems.setNode(parser.getAttributeValue("", "node")); discoverItems.setNode(parser.getAttributeValue("", "node"));
while (!done) { outerloop: while (true) {
int eventType = parser.next(); int eventType = parser.next();
switch (eventType) {
if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) { case XmlPullParser.START_TAG:
// Initialize the variables from the parsed XML String elementName = parser.getName();
jid = parser.getAttributeValue("", "jid"); switch (elementName) {
name = parser.getAttributeValue("", "name"); case "item":
node = parser.getAttributeValue("", "node"); // Initialize the variables from the parsed XML
action = parser.getAttributeValue("", "action"); jid = parser.getAttributeValue("", "jid");
} name = parser.getAttributeValue("", "name");
else if (eventType == XmlPullParser.END_TAG && "item".equals(parser.getName())) { node = parser.getAttributeValue("", "node");
// Create a new Item and add it to DiscoverItems. action = parser.getAttributeValue("", "action");
item = new DiscoverItems.Item(jid); break;
item.setName(name); }
item.setNode(node); break;
item.setAction(action); case XmlPullParser.END_TAG:
discoverItems.addItem(item); String elementName = parser.getName();
} switch (elementName) {
else if (eventType == XmlPullParser.END_TAG && "query".equals(parser.getName())) { case "item":
done = true; // Create a new Item and add it to DiscoverItems.
item = new DiscoverItems.Item(jid);
item.setName(name);
item.setNode(node);
item.setAction(action);
discoverItems.addItem(item);
break;
case "query":
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
} }
} }
return discoverItems; return discoverItems;

View file

@ -125,7 +125,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser // Create the xml parser
XmlPullParser parser = getParserFromXML(xml); XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml // Create a packet from the xml
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser); Privacy packet = (Privacy) (new PrivacyProvider()).parse(parser);
// check if it exist // check if it exist
assertNotNull(packet); assertNotNull(packet);
@ -317,7 +317,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser // Create the xml parser
XmlPullParser parser = getParserFromXML(xml); XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml // Create a packet from the xml
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser); Privacy packet = (Privacy) (new PrivacyProvider()).parse(parser);
assertNotNull(packet); assertNotNull(packet);
assertNotNull(packet.getChildElementXML()); assertNotNull(packet.getChildElementXML());
@ -356,7 +356,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser // Create the xml parser
XmlPullParser parser = getParserFromXML(xml); XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml // Create a packet from the xml
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser); Privacy packet = (Privacy) (new PrivacyProvider()).parse(parser);
assertNotNull(packet); assertNotNull(packet);

View file

@ -58,8 +58,8 @@ import org.jivesoftware.smack.packet.RosterVer;
import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls; import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.PlainStreamElement; import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smack.rosterstore.RosterStore; import org.jivesoftware.smack.rosterstore.RosterStore;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jxmpp.util.XmppStringUtils; import org.jxmpp.util.XmppStringUtils;
@ -1052,9 +1052,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeature = PacketParserUtils.parseCompressionFeature(parser); streamFeature = PacketParserUtils.parseCompressionFeature(parser);
break; break;
default: default:
StreamFeatureProvider provider = ProviderManager.getStreamFeatureProvider(name, namespace); PacketExtensionProvider<PacketExtension> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (provider != null) { if (provider != null) {
streamFeature = provider.parseStreamFeature(parser); streamFeature = provider.parse(parser);
} }
break; break;
} }

View file

@ -16,14 +16,17 @@
*/ */
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* *
@ -78,11 +81,12 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Robin Collier * @author Robin Collier
*/ */
abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider abstract public class EmbeddedExtensionProvider<PE extends PacketExtension> extends PacketExtensionProvider<PE>
{ {
final public PacketExtension parseExtension(XmlPullParser parser) throws Exception @Override
{ final public PE parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String namespace = parser.getNamespace(); String namespace = parser.getNamespace();
String name = parser.getName(); String name = parser.getName();
Map<String, String> attMap = new HashMap<String, String>(); Map<String, String> attMap = new HashMap<String, String>();
@ -93,16 +97,17 @@ abstract public class EmbeddedExtensionProvider implements PacketExtensionProvid
} }
List<PacketExtension> extensions = new ArrayList<PacketExtension>(); List<PacketExtension> extensions = new ArrayList<PacketExtension>();
int tag;
do do
{ {
int tag = parser.next(); tag = parser.next();
if (tag == XmlPullParser.START_TAG) if (tag == XmlPullParser.START_TAG)
extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser)); extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
} while (!name.equals(parser.getName())); } while (!(tag == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
return createReturnExtension(name, namespace, attMap, extensions); return createReturnExtension(name, namespace, attMap, extensions);
} }
abstract protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content); abstract protected PE createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content);
} }

View file

@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension;
/** /**
* Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the * Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the
* {@link ProviderLoader}. * {@link ProviderLoader}.
@ -32,7 +34,7 @@ public final class ExtensionProviderInfo extends AbstractProviderInfo {
* @param namespace Namespace that provider parses. * @param namespace Namespace that provider parses.
* @param extProvider The provider implementation. * @param extProvider The provider implementation.
*/ */
public ExtensionProviderInfo(String elementName, String namespace, PacketExtensionProvider extProvider) { public ExtensionProviderInfo(String elementName, String namespace, PacketExtensionProvider<PacketExtension> extProvider) {
super(elementName, namespace, extProvider); super(elementName, namespace, extProvider);
} }

View file

@ -18,27 +18,14 @@
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.xmlpull.v1.XmlPullParser;
/** /**
* An interface for parsing custom IQ packets. Each IQProvider must be registered with * An abstract class for parsing custom IQ packets. Each IQProvider must be registered with
* the ProviderManager class for it to be used. Every implementation of this * the ProviderManager class for it to be used. Every implementation of this
* interface <b>must</b> have a public, no-argument constructor. * abstract class <b>must</b> have a public, no-argument constructor.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public interface IQProvider { public abstract class IQProvider<I extends IQ> extends Provider<I> {
/**
* Parse the IQ sub-document and create an IQ instance. Each IQ must have a
* single child element. At the beginning of the method call, the xml parser
* will be positioned at the opening tag of the IQ child element. At the end
* of the method call, the parser <b>must</b> be positioned on the closing tag
* of the child element.
*
* @param parser an XML parser.
* @return a new IQ instance.
* @throws Exception if an error occurs parsing the XML.
*/
public IQ parseIQ(XmlPullParser parser) throws Exception;
} }

View file

@ -34,7 +34,7 @@ public final class IQProviderInfo extends AbstractProviderInfo {
* @param namespace Namespace that provider parses. * @param namespace Namespace that provider parses.
* @param iqProvider The provider implementation. * @param iqProvider The provider implementation.
*/ */
public IQProviderInfo(String elementName, String namespace, IQProvider iqProvider) { public IQProviderInfo(String elementName, String namespace, IQProvider<IQ> iqProvider) {
super(elementName, namespace, iqProvider); super(elementName, namespace, iqProvider);
} }

View file

@ -17,27 +17,16 @@
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.xmlpull.v1.XmlPullParser;
/** /**
* An interface for parsing custom packets extensions. Each PacketExtensionProvider must * An abstract class for parsing custom packets extensions. Each PacketExtensionProvider must
* be registered with the ProviderManager class for it to be used. Every implementation * be registered with the ProviderManager class for it to be used. Every implementation
* of this interface <b>must</b> have a public, no-argument constructor. * of this abstract class <b>must</b> have a public, no-argument constructor.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public interface PacketExtensionProvider { public abstract class PacketExtensionProvider<PE extends PacketExtension> extends Provider<PE> {
/**
* 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 <b>must</b> be positioned on the closing element of the packet extension.
*
* @param parser an XML parser.
* @return a new IQ instance.
* @throws java.lang.Exception if an error occurs parsing the XML.
*/
public PacketExtension parseExtension(XmlPullParser parser) throws Exception;
} }

View file

@ -20,20 +20,24 @@ package org.jivesoftware.smack.provider;
import java.io.IOException; import java.io.IOException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
/** public abstract class Provider<E extends Element> {
*
*/
public interface StreamFeatureProvider {
/** public final E parse(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
* // XPP3 calling convention assert: Parser should be at start tag
* @param parser an XML parser. ParserUtils.assertAtStartTag(parser);
* @return a new PacketExtension instance.
* @throws XmlPullParserException if an error occurs parsing the XML. final int initialDepth = parser.getDepth();
*/ E e = parse(parser, initialDepth);
public PacketExtension parseStreamFeature(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException;
// XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
return e;
}
public abstract E parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException;;
} }

View file

@ -83,11 +83,16 @@ public class ProviderFileLoader implements ProviderLoader {
// reflection later to create instances of the class. // reflection later to create instances of the class.
// Add the provider to the map. // Add the provider to the map.
if (IQProvider.class.isAssignableFrom(provider)) { if (IQProvider.class.isAssignableFrom(provider)) {
iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider) provider.newInstance())); iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider<IQ>) provider.newInstance()));
} }
else if (IQ.class.isAssignableFrom(provider)) { else if (IQ.class.isAssignableFrom(provider)) {
iqProviders.add(new IQProviderInfo(elementName, namespace, (Class<? extends IQ>)provider)); iqProviders.add(new IQProviderInfo(elementName, namespace, (Class<? extends IQ>)provider));
} }
else {
exceptions.add(new IllegalArgumentException(
className
+ " is neither IQProvider or IQ class"));
}
break; break;
case "extensionProvider": case "extensionProvider":
// Attempt to load the provider class and then create // Attempt to load the provider class and then create
@ -96,16 +101,21 @@ public class ProviderFileLoader implements ProviderLoader {
// then we'll use reflection later to create instances // then we'll use reflection later to create instances
// of the class. // of the class.
if (PacketExtensionProvider.class.isAssignableFrom(provider)) { if (PacketExtensionProvider.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider) provider.newInstance())); extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider<PacketExtension>) provider.newInstance()));
} }
else if (PacketExtension.class.isAssignableFrom(provider)) { else if (PacketExtension.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, provider)); extProviders.add(new ExtensionProviderInfo(elementName, namespace, provider));
} }
else {
exceptions.add(new IllegalArgumentException(
className
+ " is neither PacketExtensionProvider or PacketExtension class"));
}
break; break;
case "streamFeatureProvider": case "streamFeatureProvider":
sfProviders.add(new StreamFeatureProviderInfo(elementName, sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace, namespace,
(StreamFeatureProvider) provider.newInstance())); (PacketExtensionProvider<PacketExtension>) provider.newInstance()));
break; break;
default: default:
LOGGER.warning("Unkown provider type: " + typeName); LOGGER.warning("Unkown provider type: " + typeName);

View file

@ -109,11 +109,11 @@ import org.jxmpp.util.XmppStringUtils;
*/ */
public final class ProviderManager { public final class ProviderManager {
private static final Map<String, PacketExtensionProvider> extensionProviders = new ConcurrentHashMap<String, PacketExtensionProvider>(); private static final Map<String, PacketExtensionProvider<PacketExtension>> extensionProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>();
private static final Map<String, IQProvider> iqProviders = new ConcurrentHashMap<String, IQProvider>(); private static final Map<String, IQProvider<IQ>> iqProviders = new ConcurrentHashMap<String, IQProvider<IQ>>();
private static final Map<String, Class<?>> extensionIntrospectionProviders = new ConcurrentHashMap<String, Class<?>>(); private static final Map<String, Class<?>> extensionIntrospectionProviders = new ConcurrentHashMap<String, Class<?>>();
private static final Map<String, Class<?>> iqIntrospectionProviders = new ConcurrentHashMap<String, Class<?>>(); private static final Map<String, Class<?>> iqIntrospectionProviders = new ConcurrentHashMap<String, Class<?>>();
private static final Map<String, StreamFeatureProvider> streamFeatureProviders = new ConcurrentHashMap<String, StreamFeatureProvider>(); private static final Map<String, PacketExtensionProvider<PacketExtension>> streamFeatureProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>();
static { static {
// Ensure that Smack is initialized by calling getVersion, so that user // Ensure that Smack is initialized by calling getVersion, so that user
@ -157,7 +157,7 @@ public final class ProviderManager {
* @param namespace the XML namespace. * @param namespace the XML namespace.
* @return the IQ provider. * @return the IQ provider.
*/ */
public static IQProvider getIQProvider(String elementName, String namespace) { public static IQProvider<IQ> getIQProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
return iqProviders.get(key); return iqProviders.get(key);
} }
@ -190,13 +190,14 @@ public final class ProviderManager {
* @param namespace the XML namespace. * @param namespace the XML namespace.
* @param provider the IQ provider. * @param provider the IQ provider.
*/ */
@SuppressWarnings("unchecked")
public static void addIQProvider(String elementName, String namespace, public static void addIQProvider(String elementName, String namespace,
Object provider) Object provider)
{ {
// First remove existing providers // First remove existing providers
String key = removeIQProvider(elementName, namespace); String key = removeIQProvider(elementName, namespace);
if (provider instanceof IQProvider) { if (provider instanceof IQProvider) {
iqProviders.put(key, (IQProvider) provider); iqProviders.put(key, (IQProvider<IQ>) provider);
} else if (provider instanceof Class && IQ.class.isAssignableFrom((Class<?>) provider)) { } else if (provider instanceof Class && IQ.class.isAssignableFrom((Class<?>) provider)) {
iqIntrospectionProviders.put(key, (Class<?>) provider); iqIntrospectionProviders.put(key, (Class<?>) provider);
} else { } else {
@ -240,7 +241,7 @@ public final class ProviderManager {
* @param namespace namespace associated with extension provider. * @param namespace namespace associated with extension provider.
* @return the extenion provider. * @return the extenion provider.
*/ */
public static PacketExtensionProvider getExtensionProvider(String elementName, String namespace) { public static PacketExtensionProvider<PacketExtension> getExtensionProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
return extensionProviders.get(key); return extensionProviders.get(key);
} }
@ -259,13 +260,14 @@ public final class ProviderManager {
* @param namespace the XML namespace. * @param namespace the XML namespace.
* @param provider the extension provider. * @param provider the extension provider.
*/ */
@SuppressWarnings("unchecked")
public static void addExtensionProvider(String elementName, String namespace, public static void addExtensionProvider(String elementName, String namespace,
Object provider) Object provider)
{ {
// First remove existing providers // First remove existing providers
String key = removeExtensionProvider(elementName, namespace); String key = removeExtensionProvider(elementName, namespace);
if (provider instanceof PacketExtensionProvider) { if (provider instanceof PacketExtensionProvider) {
extensionProviders.put(key, (PacketExtensionProvider) provider); extensionProviders.put(key, (PacketExtensionProvider<PacketExtension>) provider);
} else if (provider instanceof Class && PacketExtension.class.isAssignableFrom((Class<?>) provider)) { } else if (provider instanceof Class && PacketExtension.class.isAssignableFrom((Class<?>) provider)) {
extensionIntrospectionProviders.put(key, (Class<?>) provider); extensionIntrospectionProviders.put(key, (Class<?>) provider);
} else { } else {
@ -304,12 +306,12 @@ public final class ProviderManager {
return Collections.unmodifiableList(providers); return Collections.unmodifiableList(providers);
} }
public static StreamFeatureProvider getStreamFeatureProvider(String elementName, String namespace) { public static PacketExtensionProvider<PacketExtension> getStreamFeatureProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
return streamFeatureProviders.get(key); return streamFeatureProviders.get(key);
} }
public static void addStreamFeatureProvider(String elementName, String namespace, StreamFeatureProvider provider) { public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) {
String key = getKey(elementName, namespace); String key = getKey(elementName, namespace);
streamFeatureProviders.put(key, provider); streamFeatureProviders.put(key, provider);
} }

View file

@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smack.provider; package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension;
/** /**
* *
*/ */
@ -28,7 +30,8 @@ public final class StreamFeatureProviderInfo extends AbstractProviderInfo {
* @param namespace Namespace that provider parses. * @param namespace Namespace that provider parses.
* @param extProvider The provider implementation. * @param extProvider The provider implementation.
*/ */
public StreamFeatureProviderInfo(String elementName, String namespace, StreamFeatureProvider extProvider) { public StreamFeatureProviderInfo(String elementName, String namespace,
PacketExtensionProvider<PacketExtension> extProvider) {
super(elementName, namespace, extProvider); super(elementName, namespace, extProvider);
} }

View file

@ -22,13 +22,13 @@ import java.io.StringReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.compress.packet.Compress; import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.packet.Bind; import org.jivesoftware.smack.packet.Bind;
@ -121,7 +121,7 @@ public class PacketParserUtils {
case Message.ELEMENT: case Message.ELEMENT:
return parseMessage(parser); return parseMessage(parser);
case IQ.ELEMENT: case IQ.ELEMENT:
return parseIQ(parser, connection); return parse(parser, connection);
case Presence.ELEMENT: case Presence.ELEMENT:
return parsePresence(parser); return parsePresence(parser);
default: default:
@ -171,9 +171,16 @@ public class PacketParserUtils {
* *
* @param parser the XML parser, positioned at the start of a message packet. * @param parser the XML parser, positioned at the start of a message packet.
* @return a Message packet. * @return a Message packet.
* @throws Exception if an exception occurs while parsing the packet. * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
public static Message parseMessage(XmlPullParser parser) throws Exception { public static Message parseMessage(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
assert(parser.getName().equals(Message.ELEMENT));
final int initialDepth = parser.getDepth();
Message message = new Message(); Message message = new Message();
message.setPacketID(parser.getAttributeValue("", "id")); message.setPacketID(parser.getAttributeValue("", "id"));
message.setTo(parser.getAttributeValue("", "to")); message.setTo(parser.getAttributeValue("", "to"));
@ -197,26 +204,27 @@ public class PacketParserUtils {
// Parse sub-elements. We include extra logic to make sure the values // Parse sub-elements. We include extra logic to make sure the values
// are only read once. This is because it's possible for the names to appear // are only read once. This is because it's possible for the names to appear
// in arbitrary sub-elements. // in arbitrary sub-elements.
boolean done = false;
String thread = null; String thread = null;
while (!done) { outerloop: while (true) {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) { switch (eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName(); String elementName = parser.getName();
String namespace = parser.getNamespace(); String namespace = parser.getNamespace();
if (elementName.equals("subject")) { switch(elementName) {
String xmlLang = getLanguageAttribute(parser); case "subject":
if (xmlLang == null) { String xmlLangSubject = getLanguageAttribute(parser);
xmlLang = defaultLanguage; if (xmlLangSubject == null) {
xmlLangSubject = defaultLanguage;
} }
String subject = parseElementText(parser); String subject = parseElementText(parser);
if (message.getSubject(xmlLang) == null) { if (message.getSubject(xmlLangSubject) == null) {
message.addSubject(xmlLang, subject); message.addSubject(xmlLangSubject, subject);
} }
} break;
else if (elementName.equals(Message.BODY)) { case Message.BODY:
String xmlLang = getLanguageAttribute(parser); String xmlLang = getLanguageAttribute(parser);
if (xmlLang == null) { if (xmlLang == null) {
xmlLang = defaultLanguage; xmlLang = defaultLanguage;
@ -227,25 +235,26 @@ public class PacketParserUtils {
if (message.getBody(xmlLang) == null) { if (message.getBody(xmlLang) == null) {
message.addBody(xmlLang, body); message.addBody(xmlLang, body);
} }
} break;
else if (elementName.equals("thread")) { case "thread":
if (thread == null) { if (thread == null) {
thread = parser.nextText(); thread = parser.nextText();
} }
} break;
else if (elementName.equals("error")) { case "error":
message.setError(parseError(parser)); message.setError(parseError(parser));
} break;
// Otherwise, it must be a packet extension. default:
else {
message.addExtension( message.addExtension(
PacketParserUtils.parsePacketExtension(elementName, namespace, parser)); PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
break;
} }
} break;
else if (eventType == XmlPullParser.END_TAG) { case XmlPullParser.END_TAG:
if (parser.getName().equals("message")) { if (parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
break;
} }
} }
@ -434,9 +443,15 @@ public class PacketParserUtils {
* *
* @param parser the XML parser, positioned at the start of a presence packet. * @param parser the XML parser, positioned at the start of a presence packet.
* @return a Presence packet. * @return a Presence packet.
* @throws Exception if an exception occurs while parsing the packet. * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
public static Presence parsePresence(XmlPullParser parser) throws Exception { public static Presence parsePresence(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
Presence.Type type = Presence.Type.available; Presence.Type type = Presence.Type.available;
String typeString = parser.getAttributeValue("", "type"); String typeString = parser.getAttributeValue("", "type");
if (typeString != null && !typeString.equals("")) { if (typeString != null && !typeString.equals("")) {
@ -453,20 +468,21 @@ public class PacketParserUtils {
} }
// Parse sub-elements // Parse sub-elements
boolean done = false; outerloop: while (true) {
while (!done) {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) { switch (eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName(); String elementName = parser.getName();
String namespace = parser.getNamespace(); String namespace = parser.getNamespace();
if (elementName.equals("status")) { switch(elementName) {
case "status":
presence.setStatus(parser.nextText()); presence.setStatus(parser.nextText());
} break;
else if (elementName.equals("priority")) { case "priority":
int priority = Integer.parseInt(parser.nextText()); int priority = Integer.parseInt(parser.nextText());
presence.setPriority(priority); presence.setPriority(priority);
} break;
else if (elementName.equals("show")) { case "show":
String modeText = parser.nextText(); String modeText = parser.nextText();
if (StringUtils.isNotEmpty(modeText)) { if (StringUtils.isNotEmpty(modeText)) {
presence.setMode(Presence.Mode.fromString(modeText)); presence.setMode(Presence.Mode.fromString(modeText));
@ -480,12 +496,12 @@ public class PacketParserUtils {
+ presence.getPacketID() + presence.getPacketID()
+ "' which is invalid according to RFC6121 4.7.2.1"); + "' which is invalid according to RFC6121 4.7.2.1");
} }
} break;
else if (elementName.equals("error")) { case "error":
presence.setError(parseError(parser)); presence.setError(parseError(parser));
} break;
default:
// Otherwise, it must be a packet extension. // Otherwise, it must be a packet extension.
else {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of // Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information. // failing completely here. See SMACK-390 for more information.
try { try {
@ -496,12 +512,13 @@ public class PacketParserUtils {
"Failed to parse extension packet in Presence packet.", "Failed to parse extension packet in Presence packet.",
e); e);
} }
break;
} }
} case XmlPullParser.END_TAG:
else if (eventType == XmlPullParser.END_TAG) { if (parser.getDepth() == initialDepth) {
if (parser.getName().equals("presence")) { break outerloop;
done = true;
} }
break;
} }
} }
return presence; return presence;
@ -515,7 +532,7 @@ public class PacketParserUtils {
* @return an IQ object. * @return an IQ object.
* @throws Exception if an exception occurs while parsing the packet. * @throws Exception if an exception occurs while parsing the packet.
*/ */
public static IQ parseIQ(XmlPullParser parser, XMPPConnection connection) throws Exception { public static IQ parse(XmlPullParser parser, XMPPConnection connection) throws Exception {
IQ iqPacket = null; IQ iqPacket = null;
XMPPError error = null; XMPPError error = null;
@ -543,9 +560,9 @@ public class PacketParserUtils {
// Otherwise, see if there is a registered provider for // Otherwise, see if there is a registered provider for
// this element name and namespace. // this element name and namespace.
else { else {
IQProvider provider = ProviderManager.getIQProvider(elementName, namespace); IQProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
if (provider != null) { if (provider != null) {
iqPacket =provider.parseIQ(parser); iqPacket = provider.parse(parser);
} else { } else {
Class<?> introspectionProvider = ProviderManager.getIQIntrospectionProvider( Class<?> introspectionProvider = ProviderManager.getIQIntrospectionProvider(
elementName, namespace); elementName, namespace);
@ -611,7 +628,7 @@ public class PacketParserUtils {
return iqPacket; return iqPacket;
} }
public static RosterPacket parseRoster(XmlPullParser parser) throws Exception { public static RosterPacket parseRoster(XmlPullParser parser) throws XmlPullParserException, IOException {
RosterPacket roster = new RosterPacket(); RosterPacket roster = new RosterPacket();
boolean done = false; boolean done = false;
RosterPacket.Item item = null; RosterPacket.Item item = null;
@ -826,9 +843,12 @@ public class PacketParserUtils {
* *
* @param parser the XML parser. * @param parser the XML parser.
* @return an error sub-packet. * @return an error sub-packet.
* @throws Exception if an exception occurs while parsing the packet. * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
public static XMPPError parseError(XmlPullParser parser) throws Exception { public static XMPPError parseError(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
String type = null; String type = null;
String message = null; String message = null;
String condition = null; String condition = null;
@ -882,18 +902,26 @@ public class PacketParserUtils {
* @param namespace the XML namespace of the packet extension. * @param namespace the XML namespace of the packet extension.
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return a PacketExtension.
* @throws Exception
*/ */
public static PacketExtension parsePacketExtension(String elementName, String namespace, public static PacketExtension parsePacketExtension(String elementName, String namespace,
XmlPullParser parser) throws Exception { XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
// See if a provider is registered to handle the extension. // See if a provider is registered to handle the extension.
PacketExtensionProvider provider = ProviderManager.getExtensionProvider(elementName, namespace); PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace);
if (provider != null) { if (provider != null) {
return provider.parseExtension(parser); return provider.parse(parser);
} }
Class<?> introspectionProvider = ProviderManager.getExtensionIntrospectionProvider(elementName, namespace); Class<?> introspectionProvider = ProviderManager.getExtensionIntrospectionProvider(elementName, namespace);
if (introspectionProvider != null) { if (introspectionProvider != null) {
return (PacketExtension)parseWithIntrospection(elementName, introspectionProvider, parser); try {
return (PacketExtension)parseWithIntrospection(elementName, introspectionProvider, parser);
} catch (NoSuchMethodException | SecurityException
| InstantiationException | IllegalAccessException
| IllegalArgumentException
| InvocationTargetException
| ClassNotFoundException e) {
throw new SmackException(e);
}
} }
// No providers registered, so use a default extension. // No providers registered, so use a default extension.
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace); DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);

View file

@ -31,6 +31,14 @@ public class ParserUtils {
assert(parser.getEventType() == XmlPullParser.END_TAG); assert(parser.getEventType() == XmlPullParser.END_TAG);
} }
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
throws XmlPullParserException, IOException {
int event = parser.getEventType();
while (!(event == XmlPullParser.END_TAG && parser.getDepth() == depth)) {
event = parser.next();
}
}
/** /**
* Get the boolean value of an argument. * Get the boolean value of an argument.
* *

View file

@ -327,7 +327,7 @@ public class RosterTest {
.append("</query>") .append("</query>")
.append("</iq>"); .append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString()); final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser, connection); final IQ rosterPush = PacketParserUtils.parse(parser, connection);
initRoster(connection, roster); initRoster(connection, roster);
rosterListener.reset(); rosterListener.reset();
@ -460,7 +460,7 @@ public class RosterTest {
.append("</query>") .append("</query>")
.append("</iq>"); .append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString()); final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser, connection); final IQ rosterPush = PacketParserUtils.parse(parser, connection);
initRoster(connection, roster); initRoster(connection, roster);
rosterListener.reset(); rosterListener.reset();

View file

@ -72,12 +72,12 @@ public class ParsingExceptionTest {
assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content)); assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
} }
static class ThrowException implements PacketExtensionProvider { static class ThrowException extends PacketExtensionProvider<PacketExtension> {
public static final String ELEMENT = "exception"; public static final String ELEMENT = "exception";
public static final String NAMESPACE = "http://smack.jivesoftware.org/exception"; public static final String NAMESPACE = "http://smack.jivesoftware.org/exception";
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { public PacketExtension parse(XmlPullParser parser, int initialDepth) throws SmackException {
throw new SmackException("Test Exception"); throw new SmackException("Test Exception");
} }

View file

@ -59,10 +59,10 @@ public class ProviderConfigTest {
Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider")); Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider"));
} }
public static class TestIQProvider implements IQProvider { public static class TestIQProvider extends IQProvider<IQ> {
@Override @Override
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parse(XmlPullParser parser, int initialDepth) {
return null; return null;
} }

View file

@ -34,10 +34,10 @@ public class ProviderManagerTest {
assertTrue(SmackConfiguration.isSmackInitialized()); assertTrue(SmackConfiguration.isSmackInitialized());
} }
public static class TestIQProvider implements IQProvider { public static class TestIQProvider extends IQProvider<IQ> {
@Override @Override
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parse(XmlPullParser parser, int initialDepth) {
return null; return null;
} }

View file

@ -16,13 +16,16 @@
*/ */
package org.jivesoftware.smackx.carbons.provider; package org.jivesoftware.smackx.carbons.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension; import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction; import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
import org.jivesoftware.smackx.forward.Forwarded; import org.jivesoftware.smackx.forward.Forwarded;
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* This class implements the {@link PacketExtensionProvider} to parse * This class implements the {@link PacketExtensionProvider} to parse
@ -31,9 +34,13 @@ import org.xmlpull.v1.XmlPullParser;
* @author Georg Lukas * @author Georg Lukas
* *
*/ */
public class CarbonManagerProvider implements PacketExtensionProvider { public class CarbonManagerProvider extends PacketExtensionProvider<CarbonExtension> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { private static final ForwardedProvider FORWARDED_PROVIDER = new ForwardedProvider();
@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth)
throws SmackException, XmlPullParserException, IOException {
Direction dir = Direction.valueOf(parser.getName()); Direction dir = Direction.valueOf(parser.getName());
Forwarded fwd = null; Forwarded fwd = null;
@ -41,13 +48,13 @@ public class CarbonManagerProvider implements PacketExtensionProvider {
while (!done) { while (!done) {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) { if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) {
fwd = (Forwarded) PacketParserUtils.parsePacketExtension(Forwarded.ELEMENT, Forwarded.NAMESPACE, parser); fwd = FORWARDED_PROVIDER.parse(parser);
} }
else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName())) else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName()))
done = true; done = true;
} }
if (fwd == null) if (fwd == null)
throw new Exception("sent/received must contain exactly one <forwarded> tag"); throw new SmackException("sent/received must contain exactly one <forwarded> tag");
return new CarbonExtension(dir, fwd); return new CarbonExtension(dir, fwd);
} }
} }

View file

@ -19,16 +19,15 @@ package org.jivesoftware.smackx.csi.provider;
import java.io.IOException; import java.io.IOException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smackx.csi.packet.ClientStateIndication; import org.jivesoftware.smackx.csi.packet.ClientStateIndication;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
public class ClientStateIndicationFeatureProvider implements StreamFeatureProvider { public class ClientStateIndicationFeatureProvider extends PacketExtensionProvider<ClientStateIndication.Feature> {
@Override @Override
public PacketExtension parseStreamFeature(XmlPullParser parser) public ClientStateIndication.Feature parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException { throws XmlPullParserException, IOException, SmackException {
return ClientStateIndication.Feature.INSTANCE; return ClientStateIndication.Feature.INSTANCE;
} }

View file

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smackx.hoxt.provider; package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp; import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
@ -23,7 +24,9 @@ import org.jivesoftware.smackx.shim.packet.Header;
import org.jivesoftware.smackx.shim.packet.HeadersExtension; import org.jivesoftware.smackx.shim.packet.HeadersExtension;
import org.jivesoftware.smackx.shim.provider.HeaderProvider; import org.jivesoftware.smackx.shim.provider.HeaderProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -33,7 +36,7 @@ import java.util.Set;
* @author Andriy Tsykholyas * @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/ */
public abstract class AbstractHttpOverXmppProvider implements IQProvider { public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmpp> extends IQProvider<H> {
private static final String ELEMENT_HEADERS = "headers"; private static final String ELEMENT_HEADERS = "headers";
private static final String ELEMENT_HEADER = "header"; private static final String ELEMENT_HEADER = "header";
@ -56,9 +59,11 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
* @param parser parser * @param parser parser
* @param elementName name of concrete implementation of this element * @param elementName name of concrete implementation of this element
* @param body parent Body element * @param body parent Body element
* @throws Exception if anything goes wrong * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
protected void parseHeadersAndData(XmlPullParser parser, String elementName, AbstractHttpOverXmpp.AbstractBody body) throws Exception { protected void parseHeadersAndData(XmlPullParser parser, String elementName, AbstractHttpOverXmpp.AbstractBody body) throws XmlPullParserException, IOException, SmackException {
boolean done = false; boolean done = false;
while (!done) { while (!done) {
@ -82,7 +87,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
} }
} }
private HeadersExtension parseHeaders(XmlPullParser parser) throws Exception { private HeadersExtension parseHeaders(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
HeaderProvider provider = new HeaderProvider(); HeaderProvider provider = new HeaderProvider();
Set<Header> set = new HashSet<Header>(); Set<Header> set = new HashSet<Header>();
boolean done = false; boolean done = false;
@ -92,7 +97,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
if (eventType == XmlPullParser.START_TAG) { if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals(ELEMENT_HEADER)) { if (parser.getName().equals(ELEMENT_HEADER)) {
Header header = (Header) provider.parseExtension(parser); Header header = provider.parse(parser);
set.add(header); set.add(header);
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
@ -104,7 +109,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return new HeadersExtension(set); return new HeadersExtension(set);
} }
private AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
AbstractHttpOverXmpp.DataChild child = null; AbstractHttpOverXmpp.DataChild child = null;
boolean done = false; boolean done = false;
@ -143,7 +148,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return data; return data;
} }
private AbstractHttpOverXmpp.Text parseText(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.Text parseText(XmlPullParser parser) throws XmlPullParserException, IOException {
String text = null; String text = null;
boolean done = false; boolean done = false;
@ -166,7 +171,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return new AbstractHttpOverXmpp.Text(text); return new AbstractHttpOverXmpp.Text(text);
} }
private AbstractHttpOverXmpp.Xml parseXml(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.Xml parseXml(XmlPullParser parser) throws XmlPullParserException, IOException {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
boolean done = false; boolean done = false;
boolean startClosed = true; boolean startClosed = true;
@ -214,7 +219,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return new AbstractHttpOverXmpp.Xml(builder.toString()); return new AbstractHttpOverXmpp.Xml(builder.toString());
} }
private void appendXmlAttributes(XmlPullParser parser, StringBuilder builder) throws Exception { private void appendXmlAttributes(XmlPullParser parser, StringBuilder builder) {
// NOTE: for now we ignore namespaces // NOTE: for now we ignore namespaces
int count = parser.getAttributeCount(); int count = parser.getAttributeCount();
@ -230,7 +235,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
} }
} }
private AbstractHttpOverXmpp.Base64 parseBase64(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.Base64 parseBase64(XmlPullParser parser) throws XmlPullParserException, IOException {
String text = null; String text = null;
boolean done = false; boolean done = false;
@ -254,7 +259,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return new AbstractHttpOverXmpp.Base64(text); return new AbstractHttpOverXmpp.Base64(text);
} }
private AbstractHttpOverXmpp.ChunkedBase64 parseChunkedBase64(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.ChunkedBase64 parseChunkedBase64(XmlPullParser parser) throws XmlPullParserException, IOException {
String streamId = parser.getAttributeValue("", ATTRIBUTE_STREAM_ID); String streamId = parser.getAttributeValue("", ATTRIBUTE_STREAM_ID);
AbstractHttpOverXmpp.ChunkedBase64 child = new AbstractHttpOverXmpp.ChunkedBase64(streamId); AbstractHttpOverXmpp.ChunkedBase64 child = new AbstractHttpOverXmpp.ChunkedBase64(streamId);
boolean done = false; boolean done = false;
@ -275,7 +280,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return child; return child;
} }
private AbstractHttpOverXmpp.Ibb parseIbb(XmlPullParser parser) throws Exception { private AbstractHttpOverXmpp.Ibb parseIbb(XmlPullParser parser) throws XmlPullParserException, IOException {
String sid = parser.getAttributeValue("", ATTRIBUTE_SID); String sid = parser.getAttributeValue("", ATTRIBUTE_SID);
AbstractHttpOverXmpp.Ibb child = new AbstractHttpOverXmpp.Ibb(sid); AbstractHttpOverXmpp.Ibb child = new AbstractHttpOverXmpp.Ibb(sid);
boolean done = false; boolean done = false;

View file

@ -16,10 +16,12 @@
*/ */
package org.jivesoftware.smackx.hoxt.provider; package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk; import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Packet provider for base64 binary chunks. * Packet provider for base64 binary chunks.
@ -27,16 +29,10 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas * @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/ */
public class Base64BinaryChunkProvider implements PacketExtensionProvider { public class Base64BinaryChunkProvider extends PacketExtensionProvider<Base64BinaryChunk> {
/**
* Required no-argument constructor.
*/
public Base64BinaryChunkProvider() {
}
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { public Base64BinaryChunk parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String streamId = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_STREAM_ID); String streamId = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_STREAM_ID);
String nrString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_NR); String nrString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_NR);
String lastString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_LAST); String lastString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_LAST);

View file

@ -16,10 +16,13 @@
*/ */
package org.jivesoftware.smackx.hoxt.provider; package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.hoxt.packet.HttpMethod; import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq; import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Req packet provider. * Req packet provider.
@ -27,7 +30,7 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas * @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/ */
public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider { public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOverXmppReq> {
private static final String ELEMENT_REQ = "req"; private static final String ELEMENT_REQ = "req";
@ -42,7 +45,8 @@ public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider {
} }
@Override @Override
public IQ parseIQ(XmlPullParser parser) throws Exception { public HttpOverXmppReq parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String method = parser.getAttributeValue("", ATTRIBUTE_METHOD); String method = parser.getAttributeValue("", ATTRIBUTE_METHOD);
String resource = parser.getAttributeValue("", ATTRIBUTE_RESOURCE); String resource = parser.getAttributeValue("", ATTRIBUTE_RESOURCE);
String version = parser.getAttributeValue("", ATTRIBUTE_VERSION); String version = parser.getAttributeValue("", ATTRIBUTE_VERSION);

View file

@ -16,9 +16,12 @@
*/ */
package org.jivesoftware.smackx.hoxt.provider; package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp; import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Resp packet provider. * Resp packet provider.
@ -26,21 +29,16 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas * @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/ */
public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider { public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpOverXmppResp> {
private static final String ELEMENT_RESP = "resp"; private static final String ELEMENT_RESP = "resp";
private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage"; private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage";
private static final String ATTRIBUTE_STATUS_CODE = "statusCode"; private static final String ATTRIBUTE_STATUS_CODE = "statusCode";
/**
* Mandatory no argument constructor.
*/
public HttpOverXmppRespProvider() {
}
@Override @Override
public IQ parseIQ(XmlPullParser parser) throws Exception { public HttpOverXmppResp parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String version = parser.getAttributeValue("", ATTRIBUTE_VERSION); String version = parser.getAttributeValue("", ATTRIBUTE_VERSION);
String statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE); String statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE);
String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE); String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);

View file

@ -52,7 +52,7 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser); cc = (CarbonExtension) new CarbonManagerProvider().parse(parser);
fwd = cc.getForwarded(); fwd = cc.getForwarded();
// meta // meta
@ -83,7 +83,7 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser); cc = (CarbonExtension) new CarbonManagerProvider().parse(parser);
assertEquals(CarbonExtension.Direction.received, cc.getDirection()); assertEquals(CarbonExtension.Direction.received, cc.getDirection());
@ -102,6 +102,6 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
new CarbonManagerProvider().parseExtension(parser); new CarbonManagerProvider().parse(parser);
} }
} }

View file

@ -52,10 +52,10 @@ public class AbstractHttpOverXmppProviderTest {
expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE"); expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE");
expectedHeaders.put("Content-Length", "0"); expectedHeaders.put("Content-Length", "0");
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider(); HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp); assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp(); AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
@ -72,10 +72,10 @@ public class AbstractHttpOverXmppProviderTest {
Map<String, String> expectedHeaders = new HashMap<String, String>(); Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Host", "clayster.com"); expectedHeaders.put("Host", "clayster.com");
AbstractHttpOverXmppProvider provider = new HttpOverXmppReqProvider(); HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppReq); assertTrue(iq instanceof HttpOverXmppReq);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppReq) iq).getReq(); AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppReq) iq).getReq();
@ -181,10 +181,10 @@ public class AbstractHttpOverXmppProviderTest {
} }
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception { private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider(); HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string, tag); XmlPullParser parser = PacketParserUtils.getParserFor(string, tag);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp); assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp(); AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
return body; return body;

View file

@ -39,7 +39,7 @@ public class Base64BinaryChunkProviderTest {
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider(); Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
PacketExtension extension = provider.parseExtension(parser); PacketExtension extension = provider.parse(parser);
assertTrue(extension instanceof Base64BinaryChunk); assertTrue(extension instanceof Base64BinaryChunk);
Base64BinaryChunk chunk = (Base64BinaryChunk) extension; Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
@ -57,7 +57,7 @@ public class Base64BinaryChunkProviderTest {
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider(); Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
PacketExtension extension = provider.parseExtension(parser); PacketExtension extension = provider.parse(parser);
assertTrue(extension instanceof Base64BinaryChunk); assertTrue(extension instanceof Base64BinaryChunk);
Base64BinaryChunk chunk = (Base64BinaryChunk) extension; Base64BinaryChunk chunk = (Base64BinaryChunk) extension;

View file

@ -68,7 +68,7 @@ public class HttpOverXmppReqProviderTest {
private HttpOverXmppReq.Req parseReq(String string) throws Exception { private HttpOverXmppReq.Req parseReq(String string) throws Exception {
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider(); HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppReq); assertTrue(iq instanceof HttpOverXmppReq);
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq; HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
return castedIq.getReq(); return castedIq.getReq();

View file

@ -37,7 +37,7 @@ public class HttpOverXmppRespProviderTest {
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider(); HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp); assertTrue(iq instanceof HttpOverXmppResp);
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq; HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
HttpOverXmppResp.Resp resp = castedIq.getResp(); HttpOverXmppResp.Resp resp = castedIq.getResp();
@ -53,7 +53,7 @@ public class HttpOverXmppRespProviderTest {
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider(); HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string); XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser); IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp); assertTrue(iq instanceof HttpOverXmppResp);
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq; HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
HttpOverXmppResp.Resp resp = castedIq.getResp(); HttpOverXmppResp.Resp resp = castedIq.getResp();

View file

@ -25,10 +25,10 @@ import org.xmlpull.v1.XmlPullParser;
* @author Robin Collier * @author Robin Collier
* *
*/ */
public class CarExtensionProvider implements PacketExtensionProvider public class CarExtensionProvider extends PacketExtensionProvider
{ {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception public PacketExtension parse(XmlPullParser parser, int initialDepth) throws Exception
{ {
String color = null; String color = null;
int numTires = 0; int numTires = 0;

View file

@ -17,27 +17,24 @@
package org.jivesoftware.smackx.address.provider; package org.jivesoftware.smackx.address.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.address.packet.MultipleAddresses; import org.jivesoftware.smackx.address.packet.MultipleAddresses;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The MultipleAddressesProvider parses {@link MultipleAddresses} packets. * The MultipleAddressesProvider parses {@link MultipleAddresses} packets.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class MultipleAddressesProvider implements PacketExtensionProvider { public class MultipleAddressesProvider extends PacketExtensionProvider<MultipleAddresses> {
/** @Override
* Creates a new MultipleAddressesProvider. public MultipleAddresses parse(XmlPullParser parser,
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument int initialDepth) throws XmlPullParserException,
* constructor. IOException {
*/
public MultipleAddressesProvider() {
}
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
boolean done = false; boolean done = false;
MultipleAddresses multipleAddresses = new MultipleAddresses(); MultipleAddresses multipleAddresses = new MultipleAddresses();
while (!done) { while (!done) {

View file

@ -16,35 +16,32 @@
*/ */
package org.jivesoftware.smackx.amp.provider; package org.jivesoftware.smackx.amp.provider;
import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.amp.AMPDeliverCondition; import org.jivesoftware.smackx.amp.AMPDeliverCondition;
import org.jivesoftware.smackx.amp.AMPExpireAtCondition; import org.jivesoftware.smackx.amp.AMPExpireAtCondition;
import org.jivesoftware.smackx.amp.AMPMatchResourceCondition; import org.jivesoftware.smackx.amp.AMPMatchResourceCondition;
import org.jivesoftware.smackx.amp.packet.AMPExtension; import org.jivesoftware.smackx.amp.packet.AMPExtension;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class AMPExtensionProvider implements PacketExtensionProvider { public class AMPExtensionProvider extends PacketExtensionProvider<AMPExtension> {
private static final Logger LOGGER = Logger.getLogger(AMPExtensionProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(AMPExtensionProvider.class.getName());
/**
* Creates a new AMPExtensionProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public AMPExtensionProvider() {}
/** /**
* Parses a AMPExtension packet (extension sub-packet). * Parses a AMPExtension packet (extension sub-packet).
* *
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return a PacketExtension.
* @throws Exception if a parsing error occurs. * @throws IOException
* @throws XmlPullParserException
*/ */
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { public AMPExtension parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
final String from = parser.getAttributeValue(null, "from"); final String from = parser.getAttributeValue(null, "from");
final String to = parser.getAttributeValue(null, "to"); final String to = parser.getAttributeValue(null, "to");
final String statusString = parser.getAttributeValue(null, "status"); final String statusString = parser.getAttributeValue(null, "status");

View file

@ -80,17 +80,10 @@ public class AttentionExtension implements PacketExtension {
* *
* @author Guus der Kinderen, guus.der.kinderen@gmail.com * @author Guus der Kinderen, guus.der.kinderen@gmail.com
s */ s */
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<AttentionExtension> {
/* @Override
* (non-Javadoc) public AttentionExtension parse(XmlPullParser parser, int initialDepth) {
*
* @see
* org.jivesoftware.smack.provider.PacketExtensionProvider#parseExtension
* (org.xmlpull.v1.XmlPullParser)
*/
public PacketExtension parseExtension(XmlPullParser arg0)
throws Exception {
return new AttentionExtension(); return new AttentionExtension();
} }
} }

View file

@ -215,7 +215,7 @@ public class Bookmarks implements PrivateData {
super(); super();
} }
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception { public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
Bookmarks storage = new Bookmarks(); Bookmarks storage = new Bookmarks();
boolean done = false; boolean done = false;
@ -265,7 +265,7 @@ public class Bookmarks implements PrivateData {
return urlStore; return urlStore;
} }
private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws Exception { private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException {
String name = parser.getAttributeValue("", "name"); String name = parser.getAttributeValue("", "name");
String autojoin = parser.getAttributeValue("", "autojoin"); String autojoin = parser.getAttributeValue("", "autojoin");
String jid = parser.getAttributeValue("", "jid"); String jid = parser.getAttributeValue("", "jid");

View file

@ -16,7 +16,6 @@
*/ */
package org.jivesoftware.smackx.bytestreams.ibb.provider; package org.jivesoftware.smackx.bytestreams.ibb.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close; import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -26,9 +25,10 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Henning Staib * @author Henning Staib
*/ */
public class CloseIQProvider implements IQProvider { public class CloseIQProvider extends IQProvider<Close> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public Close parse(XmlPullParser parser, int initialDepth) {
String sid = parser.getAttributeValue("", "sid"); String sid = parser.getAttributeValue("", "sid");
return new Close(sid); return new Close(sid);
} }

View file

@ -16,13 +16,13 @@
*/ */
package org.jivesoftware.smackx.bytestreams.ibb.provider; package org.jivesoftware.smackx.bytestreams.ibb.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses an In-Band Bytestream data packet which can be a packet extension of * Parses an In-Band Bytestream data packet which can be a packet extension of
@ -30,19 +30,33 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Henning Staib * @author Henning Staib
*/ */
public class DataPacketProvider implements PacketExtensionProvider, IQProvider { public class DataPacketProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { public static class IQProvider extends org.jivesoftware.smack.provider.IQProvider<Data> {
String sessionID = parser.getAttributeValue("", "sid");
long seq = Long.parseLong(parser.getAttributeValue("", "seq")); private static final PacketExtensionProvider packetExtensionProvider = new PacketExtensionProvider();
String data = parser.nextText();
return new DataPacketExtension(sessionID, seq, data); @Override
public Data parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException,
SmackException {
DataPacketExtension data = packetExtensionProvider.parse(parser);
Data iq = new Data(data);
return iq;
}
} }
public IQ parseIQ(XmlPullParser parser) throws Exception { public static class PacketExtensionProvider extends org.jivesoftware.smack.provider.PacketExtensionProvider<DataPacketExtension> {
DataPacketExtension data = (DataPacketExtension) parseExtension(parser);
IQ iq = new Data(data);
return iq;
}
@Override
public DataPacketExtension parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
String sessionID = parser.getAttributeValue("", "sid");
long seq = Long.parseLong(parser.getAttributeValue("", "seq"));
String data = parser.nextText();
return new DataPacketExtension(sessionID, seq, data);
}
}
} }

View file

@ -16,22 +16,24 @@
*/ */
package org.jivesoftware.smackx.bytestreams.ibb.provider; package org.jivesoftware.smackx.bytestreams.ibb.provider;
import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType; import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses an In-Band Bytestream open packet. * Parses an In-Band Bytestream open packet.
* *
* @author Henning Staib * @author Henning Staib
*/ */
public class OpenIQProvider implements IQProvider { public class OpenIQProvider extends IQProvider<Open> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public Open parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String sessionID = parser.getAttributeValue("", "sid"); String sessionID = parser.getAttributeValue("", "sid");
int blockSize = Integer.parseInt(parser.getAttributeValue("", "block-size")); int blockSize = Integer.parseInt(parser.getAttributeValue("", "block-size"));
@ -44,6 +46,8 @@ public class OpenIQProvider implements IQProvider {
stanza = StanzaType.valueOf(stanzaValue.toUpperCase(Locale.US)); stanza = StanzaType.valueOf(stanzaValue.toUpperCase(Locale.US));
} }
parser.next();
return new Open(sessionID, blockSize, stanza); return new Open(sessionID, blockSize, stanza);
} }

View file

@ -16,19 +16,23 @@
*/ */
package org.jivesoftware.smackx.bytestreams.socks5.provider; package org.jivesoftware.smackx.bytestreams.socks5.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses a bytestream packet. * Parses a bytestream packet.
* *
* @author Alexander Wenckus * @author Alexander Wenckus
*/ */
public class BytestreamsProvider implements IQProvider { public class BytestreamsProvider extends IQProvider<Bytestream> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public Bytestream parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
Bytestream toReturn = new Bytestream(); Bytestream toReturn = new Bytestream();

View file

@ -19,17 +19,15 @@ package org.jivesoftware.smackx.caps.provider;
import java.io.IOException; import java.io.IOException;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smackx.caps.EntityCapsManager; import org.jivesoftware.smackx.caps.EntityCapsManager;
import org.jivesoftware.smackx.caps.packet.CapsExtension; import org.jivesoftware.smackx.caps.packet.CapsExtension;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
public class CapsExtensionProvider implements PacketExtensionProvider, StreamFeatureProvider { public class CapsExtensionProvider extends PacketExtensionProvider<CapsExtension> {
public PacketExtension parseExtension(XmlPullParser parser) throws XmlPullParserException, IOException, public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
SmackException { SmackException {
String hash = null; String hash = null;
String version = null; String version = null;
@ -57,9 +55,4 @@ public class CapsExtensionProvider implements PacketExtensionProvider, StreamFea
} }
} }
@Override
public PacketExtension parseStreamFeature(XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
return parseExtension(parser);
}
} }

View file

@ -66,9 +66,10 @@ public class ChatStateExtension implements PacketExtension {
return xml; return xml;
} }
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<ChatStateExtension> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public ChatStateExtension parse(XmlPullParser parser, int initialDepth) {
ChatState state; ChatState state;
try { try {
state = ChatState.valueOf(parser.getName()); state = ChatState.valueOf(parser.getName());

View file

@ -17,8 +17,9 @@
package org.jivesoftware.smackx.commands.provider; package org.jivesoftware.smackx.commands.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
@ -30,15 +31,18 @@ import org.jivesoftware.smackx.commands.AdHocCommandNote;
import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jivesoftware.smackx.xdata.provider.DataFormProvider; import org.jivesoftware.smackx.xdata.provider.DataFormProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The AdHocCommandDataProvider parses AdHocCommandData packets. * The AdHocCommandDataProvider parses AdHocCommandData packets.
* *
* @author Gabriel Guardincerri * @author Gabriel Guardincerri
*/ */
public class AdHocCommandDataProvider implements IQProvider { public class AdHocCommandDataProvider extends IQProvider<AdHocCommandData> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
boolean done = false; boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData(); AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider(); DataFormProvider dataFormProvider = new DataFormProvider();
@ -93,7 +97,7 @@ public class AdHocCommandDataProvider implements IQProvider {
adHocCommandData.addAction(AdHocCommand.Action.prev); adHocCommandData.addAction(AdHocCommand.Action.prev);
} }
else if (elementName.equals("x") && namespace.equals("jabber:x:data")) { else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
adHocCommandData.setForm((DataForm) dataFormProvider.parseExtension(parser)); adHocCommandData.setForm((DataForm) dataFormProvider.parse(parser));
} }
else if (parser.getName().equals("note")) { else if (parser.getName().equals("note")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf( AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
@ -115,38 +119,44 @@ public class AdHocCommandDataProvider implements IQProvider {
return adHocCommandData; return adHocCommandData;
} }
public static class BadActionError implements PacketExtensionProvider { public static class BadActionError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badAction); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badAction);
} }
} }
public static class MalformedActionError implements PacketExtensionProvider { public static class MalformedActionError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.malformedAction); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.malformedAction);
} }
} }
public static class BadLocaleError implements PacketExtensionProvider { public static class BadLocaleError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badLocale); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badLocale);
} }
} }
public static class BadPayloadError implements PacketExtensionProvider { public static class BadPayloadError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badPayload); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badPayload);
} }
} }
public static class BadSessionIDError implements PacketExtensionProvider { public static class BadSessionIDError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badSessionid); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badSessionid);
} }
} }
public static class SessionExpiredError implements PacketExtensionProvider { public static class SessionExpiredError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.sessionExpired); return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.sessionExpired);
} }
} }

View file

@ -16,17 +16,22 @@
*/ */
package org.jivesoftware.smackx.delay.provider; package org.jivesoftware.smackx.delay.provider;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.delay.packet.DelayInformation; import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public abstract class AbstractDelayInformationProvider implements PacketExtensionProvider { public abstract class AbstractDelayInformationProvider extends PacketExtensionProvider<DelayInformation> {
@Override @Override
public final PacketExtension parseExtension(XmlPullParser parser) throws Exception { public final DelayInformation parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException, SmackException {
String stampString = (parser.getAttributeValue("", "stamp")); String stampString = (parser.getAttributeValue("", "stamp"));
String from = parser.getAttributeValue("", "from"); String from = parser.getAttributeValue("", "from");
String reason = null; String reason = null;
@ -46,10 +51,14 @@ public abstract class AbstractDelayInformationProvider implements PacketExtensio
} else { } else {
parser.next(); parser.next();
} }
assert(parser.getEventType() == XmlPullParser.END_TAG); Date stamp;
Date stamp = parseDate(stampString); try {
stamp = parseDate(stampString);
} catch (ParseException e) {
throw new SmackException(e);
}
return new DelayInformation(stamp, from, reason); return new DelayInformation(stamp, from, reason);
} }
protected abstract Date parseDate(String string) throws Exception; protected abstract Date parseDate(String string) throws ParseException;
} }

View file

@ -17,20 +17,25 @@
package org.jivesoftware.smackx.disco.provider; package org.jivesoftware.smackx.disco.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The DiscoverInfoProvider parses Service Discovery information packets. * The DiscoverInfoProvider parses Service Discovery information packets.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DiscoverInfoProvider implements IQProvider { public class DiscoverInfoProvider extends IQProvider<DiscoverInfo> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public DiscoverInfo parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
DiscoverInfo discoverInfo = new DiscoverInfo(); DiscoverInfo discoverInfo = new DiscoverInfo();
boolean done = false; boolean done = false;
DiscoverInfo.Identity identity = null; DiscoverInfo.Identity identity = null;

View file

@ -17,19 +17,23 @@
package org.jivesoftware.smackx.disco.provider; package org.jivesoftware.smackx.disco.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The DiscoverInfoProvider parses Service Discovery items packets. * The DiscoverInfoProvider parses Service Discovery items packets.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DiscoverItemsProvider implements IQProvider { public class DiscoverItemsProvider extends IQProvider<DiscoverItems> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public DiscoverItems parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
DiscoverItems discoverItems = new DiscoverItems(); DiscoverItems discoverItems = new DiscoverItems();
boolean done = false; boolean done = false;
DiscoverItems.Item item; DiscoverItems.Item item;

View file

@ -16,13 +16,16 @@
*/ */
package org.jivesoftware.smackx.forward.provider; package org.jivesoftware.smackx.forward.provider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.delay.packet.DelayInformation; import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.jivesoftware.smackx.forward.Forwarded; import org.jivesoftware.smackx.forward.Forwarded;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* This class implements the {@link PacketExtensionProvider} to parse * This class implements the {@link PacketExtensionProvider} to parse
@ -30,8 +33,10 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Georg Lukas * @author Georg Lukas
*/ */
public class ForwardedProvider implements PacketExtensionProvider { public class ForwardedProvider extends PacketExtensionProvider<Forwarded> {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
DelayInformation di = null; DelayInformation di = null;
Packet packet = null; Packet packet = null;
@ -43,13 +48,13 @@ public class ForwardedProvider implements PacketExtensionProvider {
di = (DelayInformation)PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser); di = (DelayInformation)PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser);
else if (parser.getName().equals("message")) else if (parser.getName().equals("message"))
packet = PacketParserUtils.parseMessage(parser); packet = PacketParserUtils.parseMessage(parser);
else throw new Exception("Unsupported forwarded packet type: " + parser.getName()); else throw new SmackException("Unsupported forwarded packet type: " + parser.getName());
} }
else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(Forwarded.ELEMENT)) else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(Forwarded.ELEMENT))
done = true; done = true;
} }
if (packet == null) if (packet == null)
throw new Exception("forwarded extension must contain a packet"); throw new SmackException("forwarded extension must contain a packet");
return new Forwarded(di, packet); return new Forwarded(di, packet);
} }
} }

View file

@ -100,13 +100,10 @@ public class LastActivity extends IQ {
* *
* @author Derek DeMoro * @author Derek DeMoro
*/ */
public static class Provider implements IQProvider { public static class Provider extends IQProvider<LastActivity> {
public Provider() { @Override
super(); public LastActivity parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException {
}
public IQ parseIQ(XmlPullParser parser) throws SmackException, XmlPullParserException {
LastActivity lastActivity = new LastActivity(); LastActivity lastActivity = new LastActivity();
String seconds = parser.getAttributeValue("", "seconds"); String seconds = parser.getAttributeValue("", "seconds");
if (seconds != null) { if (seconds != null) {

View file

@ -18,6 +18,7 @@
package org.jivesoftware.smackx.iqprivate; package org.jivesoftware.smackx.iqprivate;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -28,7 +29,9 @@ import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
import org.jivesoftware.smackx.iqprivate.packet.PrivateData; import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
import org.jivesoftware.smackx.iqprivate.provider.PrivateDataProvider; import org.jivesoftware.smackx.iqprivate.provider.PrivateDataProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
@ -211,8 +214,11 @@ public class PrivateDataManager extends Manager {
/** /**
* An IQ provider to parse IQ results containing private data. * An IQ provider to parse IQ results containing private data.
*/ */
public static class PrivateDataIQProvider implements IQProvider { public static class PrivateDataIQProvider extends IQProvider<PrivateDataResult> {
public IQ parseIQ(XmlPullParser parser) throws Exception {
@Override
public PrivateDataResult parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
PrivateData privateData = null; PrivateData privateData = null;
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -17,7 +17,11 @@
package org.jivesoftware.smackx.iqprivate.provider; package org.jivesoftware.smackx.iqprivate.provider;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.iqprivate.packet.PrivateData; import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
/** /**
@ -37,7 +41,6 @@ public interface PrivateDataProvider {
* *
* @param parser an XML parser. * @param parser an XML parser.
* @return a new PrivateData instance. * @return a new PrivateData instance.
* @throws Exception if an error occurs parsing the XML.
*/ */
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception; public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException;
} }

View file

@ -16,22 +16,26 @@
*/ */
package org.jivesoftware.smackx.iqregister.provider; package org.jivesoftware.smackx.iqregister.provider;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.iqregister.packet.Registration; import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class RegistrationProvider implements IQProvider { public class RegistrationProvider extends IQProvider<Registration> {
@Override @Override
public IQ parseIQ(XmlPullParser parser) throws Exception { public Registration parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String instruction = null; String instruction = null;
Map<String, String> fields = new HashMap<String, String>(); Map<String, String> fields = new HashMap<String, String>();
List<PacketExtension> packetExtensions = new LinkedList<PacketExtension>(); List<PacketExtension> packetExtensions = new LinkedList<PacketExtension>();

View file

@ -16,15 +16,14 @@
*/ */
package org.jivesoftware.smackx.iqregister.provider; package org.jivesoftware.smackx.iqregister.provider;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smackx.iqregister.packet.Registration; import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
public class RegistrationStreamFeatureProvider implements StreamFeatureProvider { public class RegistrationStreamFeatureProvider extends PacketExtensionProvider<Registration.Feature> {
@Override @Override
public PacketExtension parseStreamFeature(XmlPullParser parser) { public Registration.Feature parse(XmlPullParser parser, int initialDepth) {
return Registration.Feature.INSTANCE; return Registration.Feature.INSTANCE;
} }

View file

@ -17,15 +17,18 @@
package org.jivesoftware.smackx.iqversion.provider; package org.jivesoftware.smackx.iqversion.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.iqversion.packet.Version; import org.jivesoftware.smackx.iqversion.packet.Version;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class VersionProvider implements IQProvider { public class VersionProvider extends IQProvider<Version> {
public IQ parseIQ(XmlPullParser parser) throws Exception {
assert (parser.getEventType() == XmlPullParser.START_TAG); @Override
final int initalDepth = parser.getDepth(); public Version parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String name = null, version = null, os = null; String name = null, version = null, os = null;
outerloop: while (true) { outerloop: while (true) {
@ -46,7 +49,7 @@ public class VersionProvider implements IQProvider {
} }
break; break;
case XmlPullParser.END_TAG: case XmlPullParser.END_TAG:
if (parser.getDepth() == initalDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) { if (parser.getDepth() == initialDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) {
break outerloop; break outerloop;
} }
} }

View file

@ -17,20 +17,21 @@
package org.jivesoftware.smackx.jiveproperties.provider; package org.jivesoftware.smackx.jiveproperties.provider;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager; import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension; import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class JivePropertiesExtensionProvider implements PacketExtensionProvider { public class JivePropertiesExtensionProvider extends PacketExtensionProvider<JivePropertiesExtension> {
private static final Logger LOGGER = Logger.getLogger(JivePropertiesExtensionProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(JivePropertiesExtensionProvider.class.getName());
@ -45,10 +46,13 @@ public class JivePropertiesExtensionProvider implements PacketExtensionProvider
* *
* @param parser the XML parser, positioned at the start of a properties sub-packet. * @param parser the XML parser, positioned at the start of a properties sub-packet.
* @return a map of the properties. * @return a map of the properties.
* @throws Exception if an error occurs while parsing the properties. * @throws IOException
* @throws XmlPullParserException
*/ */
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { public JivePropertiesExtension parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>();
while (true) { while (true) {
int eventType = parser.next(); int eventType = parser.next();

View file

@ -17,11 +17,14 @@
package org.jivesoftware.smackx.muc.packet; package org.jivesoftware.smackx.muc.packet;
import java.io.IOException;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* A group chat invitation packet extension, which is used to invite other * A group chat invitation packet extension, which is used to invite other
@ -125,8 +128,12 @@ public class GroupChatInvitation implements PacketExtension {
return packet.getExtension(ELEMENT, NAMESPACE); return packet.getExtension(ELEMENT, NAMESPACE);
} }
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<GroupChatInvitation> {
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
@Override
public GroupChatInvitation parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
String roomAddress = parser.getAttributeValue("", "jid"); String roomAddress = parser.getAttributeValue("", "jid");
// Advance to end of extension. // Advance to end of extension.
parser.next(); parser.next();

View file

@ -17,19 +17,23 @@
package org.jivesoftware.smackx.muc.provider; package org.jivesoftware.smackx.muc.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muc.packet.MUCAdmin; import org.jivesoftware.smackx.muc.packet.MUCAdmin;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin) * The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class MUCAdminProvider implements IQProvider { public class MUCAdminProvider extends IQProvider<MUCAdmin> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public MUCAdmin parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
MUCAdmin mucAdmin = new MUCAdmin(); MUCAdmin mucAdmin = new MUCAdmin();
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -17,20 +17,25 @@
package org.jivesoftware.smackx.muc.provider; package org.jivesoftware.smackx.muc.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muc.packet.MUCOwner; import org.jivesoftware.smackx.muc.packet.MUCOwner;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner) * The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class MUCOwnerProvider implements IQProvider { public class MUCOwnerProvider extends IQProvider<MUCOwner> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public MUCOwner parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
MUCOwner mucOwner = new MUCOwner(); MUCOwner mucOwner = new MUCOwner();
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -16,14 +16,17 @@
*/ */
package org.jivesoftware.smackx.muc.provider; package org.jivesoftware.smackx.muc.provider;
import java.io.IOException;
import org.jivesoftware.smackx.muc.MUCAffiliation; import org.jivesoftware.smackx.muc.MUCAffiliation;
import org.jivesoftware.smackx.muc.MUCRole; import org.jivesoftware.smackx.muc.MUCRole;
import org.jivesoftware.smackx.muc.packet.Destroy; import org.jivesoftware.smackx.muc.packet.Destroy;
import org.jivesoftware.smackx.muc.packet.MUCItem; import org.jivesoftware.smackx.muc.packet.MUCItem;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class MUCParserUtils { public class MUCParserUtils {
public static MUCItem parseItem(XmlPullParser parser) throws Exception { public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth(); int initialDepth = parser.getDepth();
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation")); MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
String nick = parser.getAttributeValue("", "nick"); String nick = parser.getAttributeValue("", "nick");
@ -54,7 +57,7 @@ public class MUCParserUtils {
return new MUCItem(affiliation, role, actor, reason, jid, nick); return new MUCItem(affiliation, role, actor, reason, jid, nick);
} }
public static Destroy parseDestroy(XmlPullParser parser) throws Exception { public static Destroy parseDestroy(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
Destroy destroy = new Destroy(); Destroy destroy = new Destroy();
destroy.setJid(parser.getAttributeValue("", "jid")); destroy.setJid(parser.getAttributeValue("", "jid"));

View file

@ -18,10 +18,12 @@
package org.jivesoftware.smackx.muc.provider; package org.jivesoftware.smackx.muc.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The MUCUserProvider parses packets with extended presence information about * The MUCUserProvider parses packets with extended presence information about
@ -29,17 +31,18 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class MUCUserProvider implements PacketExtensionProvider { public class MUCUserProvider extends PacketExtensionProvider<MUCUser> {
/** /**
* Parses a MUCUser packet (extension sub-packet). * Parses a MUCUser packet (extension sub-packet).
* *
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return a PacketExtension.
* @throws Exception if a parsing error occurs. * @throws IOException
* @throws XmlPullParserException
*/ */
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
final int initialDepth = parser.getDepth(); public MUCUser parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
MUCUser mucUser = new MUCUser(); MUCUser mucUser = new MUCUser();
outerloop: while (true) { outerloop: while (true) {
switch (parser.next()) { switch (parser.next()) {
@ -77,7 +80,7 @@ public class MUCUserProvider implements PacketExtensionProvider {
return mucUser; return mucUser;
} }
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws Exception { private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
MUCUser.Invite invite = new MUCUser.Invite(); MUCUser.Invite invite = new MUCUser.Invite();
invite.setFrom(parser.getAttributeValue("", "from")); invite.setFrom(parser.getAttributeValue("", "from"));
@ -98,7 +101,7 @@ public class MUCUserProvider implements PacketExtensionProvider {
return invite; return invite;
} }
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws Exception { private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
MUCUser.Decline decline = new MUCUser.Decline(); MUCUser.Decline decline = new MUCUser.Decline();
decline.setFrom(parser.getAttributeValue("", "from")); decline.setFrom(parser.getAttributeValue("", "from"));

View file

@ -16,9 +16,12 @@
*/ */
package org.jivesoftware.smackx.nick.packet; package org.jivesoftware.smackx.nick.packet;
import java.io.IOException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* A minimalistic implementation of a {@link PacketExtension} for nicknames. * A minimalistic implementation of a {@link PacketExtension} for nicknames.
@ -91,10 +94,11 @@ public class Nick implements PacketExtension {
return buf.toString(); return buf.toString();
} }
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<Nick> {
public PacketExtension parseExtension(XmlPullParser parser) @Override
throws Exception { public Nick parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
parser.next(); parser.next();
final String name = parser.getText(); final String name = parser.getText();

View file

@ -17,9 +17,12 @@
package org.jivesoftware.smackx.offline.packet; package org.jivesoftware.smackx.offline.packet;
import java.io.IOException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* OfflineMessageInfo is an extension included in the retrieved offline messages requested by * OfflineMessageInfo is an extension included in the retrieved offline messages requested by
@ -85,25 +88,20 @@ public class OfflineMessageInfo implements PacketExtension {
return buf.toString(); return buf.toString();
} }
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<OfflineMessageInfo> {
/**
* Creates a new Provider.
* ProviderManager requires that every PacketExtensionProvider has a public,
* no-argument constructor
*/
public Provider() {
}
/** /**
* Parses a OfflineMessageInfo packet (extension sub-packet). * Parses a OfflineMessageInfo packet (extension sub-packet).
* *
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return a PacketExtension.
* @throws Exception if a parsing error occurs. * @throws IOException
* @throws XmlPullParserException
*/ */
public PacketExtension parseExtension(XmlPullParser parser) @Override
throws Exception { public OfflineMessageInfo parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
OfflineMessageInfo info = new OfflineMessageInfo(); OfflineMessageInfo info = new OfflineMessageInfo();
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -20,7 +20,9 @@ package org.jivesoftware.smackx.offline.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -187,9 +189,12 @@ public class OfflineMessageRequest extends IQ {
} }
} }
public static class Provider implements IQProvider { public static class Provider extends IQProvider<OfflineMessageRequest> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public OfflineMessageRequest parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
OfflineMessageRequest request = new OfflineMessageRequest(); OfflineMessageRequest request = new OfflineMessageRequest();
boolean done = false; boolean done = false;
while (!done) { while (!done) {
@ -214,7 +219,8 @@ public class OfflineMessageRequest extends IQ {
return request; return request;
} }
private Item parseItem(XmlPullParser parser) throws Exception { private Item parseItem(XmlPullParser parser)
throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
Item item = new Item(parser.getAttributeValue("", "node")); Item item = new Item(parser.getAttributeValue("", "node"));
item.setAction(parser.getAttributeValue("", "action")); item.setAction(parser.getAttributeValue("", "action"));

View file

@ -17,12 +17,15 @@
package org.jivesoftware.smackx.pep.provider; package org.jivesoftware.smackx.pep.provider;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* *
@ -38,19 +41,11 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Jeff Williams * @author Jeff Williams
*/ */
public class PEPProvider implements PacketExtensionProvider { public class PEPProvider extends PacketExtensionProvider<PacketExtension> {
Map<String, PacketExtensionProvider> nodeParsers = new HashMap<String, PacketExtensionProvider>(); private static final Map<String, PacketExtensionProvider<?>> nodeParsers = new HashMap<String, PacketExtensionProvider<?>>();
PacketExtension pepItem;
/** public static void registerPEPParserExtension(String node, PacketExtensionProvider<?> pepItemParser) {
* Creates a new PEPProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public PEPProvider() {
}
public void registerPEPParserExtension(String node, PacketExtensionProvider pepItemParser) {
nodeParsers.put(node, pepItemParser); nodeParsers.put(node, pepItemParser);
} }
@ -60,10 +55,14 @@ public class PEPProvider implements PacketExtensionProvider {
* *
* @param parser the XML parser, positioned at the starting element of the extension. * @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension. * @return a PacketExtension.
* @throws Exception if a parsing error occurs. * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { @Override
public PacketExtension parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
PacketExtension pepItem = null;
boolean done = false; boolean done = false;
while (!done) { while (!done) {
int eventType = parser.next(); int eventType = parser.next();
@ -73,9 +72,9 @@ public class PEPProvider implements PacketExtensionProvider {
// Figure out the node for this event. // Figure out the node for this event.
String node = parser.getAttributeValue("", "node"); String node = parser.getAttributeValue("", "node");
// Get the parser for this kind of node, and if found then parse the node. // Get the parser for this kind of node, and if found then parse the node.
PacketExtensionProvider nodeParser = nodeParsers.get(node); PacketExtensionProvider<?> nodeParser = nodeParsers.get(node);
if (nodeParser != null) { if (nodeParser != null) {
pepItem = nodeParser.parseExtension(parser); pepItem = nodeParser.parse(parser);
} }
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {

View file

@ -16,14 +16,17 @@
*/ */
package org.jivesoftware.smackx.ping.provider; package org.jivesoftware.smackx.ping.provider;
import org.jivesoftware.smack.packet.IQ; import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.ping.packet.Ping; import org.jivesoftware.smackx.ping.packet.Ping;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class PingProvider implements IQProvider { public class PingProvider extends IQProvider<Ping> {
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public Ping parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
// No need to use the ping constructor with arguments. IQ will already // No need to use the ping constructor with arguments. IQ will already
// have filled out all relevant fields ('from', 'to', 'id'). // have filled out all relevant fields ('from', 'to', 'id').
return new Ping(); return new Ping();

View file

@ -17,12 +17,13 @@
package org.jivesoftware.smackx.privacy.provider; package org.jivesoftware.smackx.privacy.provider;
import org.jivesoftware.smack.packet.DefaultPacketExtension; import org.jivesoftware.smack.packet.DefaultPacketExtension;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.privacy.packet.Privacy; import org.jivesoftware.smackx.privacy.packet.Privacy;
import org.jivesoftware.smackx.privacy.packet.PrivacyItem; import org.jivesoftware.smackx.privacy.packet.PrivacyItem;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@ -33,12 +34,11 @@ import java.util.ArrayList;
* *
* @author Francisco Vives * @author Francisco Vives
*/ */
public class PrivacyProvider implements IQProvider { public class PrivacyProvider extends IQProvider<Privacy> {
public PrivacyProvider() { @Override
} public Privacy parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
public IQ parseIQ(XmlPullParser parser) throws Exception {
Privacy privacy = new Privacy(); Privacy privacy = new Privacy();
/* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser /* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser
.getName(), parser.getNamespace(), parser)); */ .getName(), parser.getNamespace(), parser)); */
@ -78,7 +78,7 @@ public class PrivacyProvider implements IQProvider {
} }
// Parse the list complex type // Parse the list complex type
public void parseList(XmlPullParser parser, Privacy privacy) throws Exception { public void parseList(XmlPullParser parser, Privacy privacy) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
String listName = parser.getAttributeValue("", "name"); String listName = parser.getAttributeValue("", "name");
ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>(); ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
@ -100,7 +100,7 @@ public class PrivacyProvider implements IQProvider {
} }
// Parse the list complex type // Parse the list complex type
public PrivacyItem parseItem(XmlPullParser parser) throws Exception { public PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
// Retrieves the required attributes // Retrieves the required attributes
String actionValue = parser.getAttributeValue("", "action"); String actionValue = parser.getAttributeValue("", "action");

View file

@ -29,10 +29,10 @@ import org.jivesoftware.smackx.pubsub.Affiliation;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class AffiliationProvider extends EmbeddedExtensionProvider public class AffiliationProvider extends EmbeddedExtensionProvider<Affiliation>
{ {
@Override @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"))); return new Affiliation(attributeMap.get("node"), Affiliation.Type.valueOf(attributeMap.get("affiliation")));
} }

View file

@ -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>. * as specified in the <a href="http://xmpp.org/extensions/xep-0060.html#schemas-pubsub">affiliation schema</a>.
* *
* @author Robin Collier * @author Robin Collier
*/public class AffiliationsProvider extends EmbeddedExtensionProvider */public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension>
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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); return new AffiliationsExtension((List<Affiliation>)content);
} }

View file

@ -31,10 +31,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class ConfigEventProvider extends EmbeddedExtensionProvider public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent>
{ {
@Override @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) if (content.size() == 0)
return new ConfigurationEvent(attMap.get("node")); return new ConfigurationEvent(attMap.get("node"));

View file

@ -31,10 +31,10 @@ import org.jivesoftware.smackx.pubsub.NodeExtension;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class EventProvider extends EmbeddedExtensionProvider public class EventProvider extends EmbeddedExtensionProvider<EventElement>
{ {
@Override @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)); return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0));
} }

View file

@ -32,10 +32,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class FormNodeProvider extends EmbeddedExtensionProvider public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode>
{ {
@Override @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())); return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.jivesoftware.smackx.pubsub.provider; 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.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ProviderManager; 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.SimplePayload;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser; 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 * 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 * @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 id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node"); String node = parser.getAttributeValue(null, "node");

View file

@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class ItemsProvider extends EmbeddedExtensionProvider public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension>
{ {
@Override @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); return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.jivesoftware.smackx.pubsub.provider; 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.IQ;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider; 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.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses the root pubsub packet extensions of the {@link IQ} packet and returns * 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 * @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(); PubSub pubsub = new PubSub();
String namespace = parser.getNamespace(); String namespace = parser.getNamespace();
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace)); pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));

View file

@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.RetractItem;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class RetractEventProvider extends EmbeddedExtensionProvider public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem>
{ {
@Override @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")); return new RetractItem(attributeMap.get("id"));
} }

View file

@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class SimpleNodeProvider extends EmbeddedExtensionProvider public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension>
{ {
@Override @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")); return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node"));
} }

View file

@ -16,10 +16,12 @@
*/ */
package org.jivesoftware.smackx.pubsub.provider; 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.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.pubsub.Subscription; import org.jivesoftware.smackx.pubsub.Subscription;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses the <b>subscription</b> element out of the pubsub IQ message from * 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 * @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 jid = parser.getAttributeValue(null, "jid");
String nodeId = parser.getAttributeValue(null, "node"); String nodeId = parser.getAttributeValue(null, "node");
String subId = parser.getAttributeValue(null, "subid"); String subId = parser.getAttributeValue(null, "subid");

View file

@ -30,11 +30,11 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class SubscriptionsProvider extends EmbeddedExtensionProvider public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension>
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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); return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content);
} }

View file

@ -89,11 +89,11 @@ public class DeliveryReceipt implements PacketExtension
/** /**
* This Provider parses and returns DeliveryReceipt packets. * This Provider parses and returns DeliveryReceipt packets.
*/ */
public static class Provider extends EmbeddedExtensionProvider public static class Provider extends EmbeddedExtensionProvider<DeliveryReceipt>
{ {
@Override @Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, protected DeliveryReceipt createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends PacketExtension> content) Map<String, String> attributeMap, List<? extends PacketExtension> content)
{ {
return new DeliveryReceipt(attributeMap.get("id")); return new DeliveryReceipt(attributeMap.get("id"));

View file

@ -16,11 +16,14 @@
*/ */
package org.jivesoftware.smackx.receipts; package org.jivesoftware.smackx.receipts;
import java.io.IOException;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Represents a <b>message delivery receipt request</b> entry as specified by * Represents a <b>message delivery receipt request</b> entry as specified by
@ -86,9 +89,11 @@ public class DeliveryReceiptRequest implements PacketExtension
/** /**
* This Provider parses and returns DeliveryReceiptRequest packets. * This Provider parses and returns DeliveryReceiptRequest packets.
*/ */
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<DeliveryReceiptRequest> {
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) { public DeliveryReceiptRequest parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
return new DeliveryReceiptRequest(); return new DeliveryReceiptRequest();
} }
} }

View file

@ -16,19 +16,19 @@
*/ */
package org.jivesoftware.smackx.rsm.provider; package org.jivesoftware.smackx.rsm.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.rsm.packet.RSMSet; import org.jivesoftware.smackx.rsm.packet.RSMSet;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class RSMSetProvider implements PacketExtensionProvider { public class RSMSetProvider extends PacketExtensionProvider<RSMSet> {
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) public RSMSet parse(XmlPullParser parser, int initialDepth)
throws Exception { throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth();
String after = null; String after = null;
String before = null; String before = null;
int count = -1; int count = -1;

View file

@ -20,7 +20,9 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.FormField;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -84,7 +86,7 @@ class SimpleUserSearch extends IQ {
} }
} }
protected void parseItems(XmlPullParser parser) throws Exception { protected void parseItems(XmlPullParser parser) throws XmlPullParserException, IOException {
ReportedData data = new ReportedData(); ReportedData data = new ReportedData();
data.addColumn(new ReportedData.Column("JID", "jid", "text-single")); data.addColumn(new ReportedData.Column("JID", "jid", "text-single"));

View file

@ -16,6 +16,9 @@
*/ */
package org.jivesoftware.smackx.search; package org.jivesoftware.smackx.search;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -28,6 +31,7 @@ import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Implements the protocol currently used to search information repositories on the Jabber network. To date, the jabber:iq:search protocol * Implements the protocol currently used to search information repositories on the Jabber network. To date, the jabber:iq:search protocol
@ -124,16 +128,11 @@ public class UserSearch extends IQ {
/** /**
* Internal Search service Provider. * Internal Search service Provider.
*/ */
public static class Provider implements IQProvider { public static class Provider extends IQProvider<IQ> {
/** // FIXME this provider does return two different types of IQs
* Provider Constructor. @Override
*/ public IQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
UserSearch search = null; UserSearch search = null;
SimpleUserSearch simpleUserSearch = new SimpleUserSearch(); SimpleUserSearch simpleUserSearch = new SimpleUserSearch();
@ -169,7 +168,9 @@ public class UserSearch extends IQ {
} }
} }
private static void buildDataForm(SimpleUserSearch search, String instructions, XmlPullParser parser) throws Exception { private static void buildDataForm(SimpleUserSearch search,
String instructions, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
DataForm dataForm = new DataForm(Form.TYPE_FORM); DataForm dataForm = new DataForm(Form.TYPE_FORM);
boolean done = false; boolean done = false;
dataForm.setTitle("User Search"); dataForm.setTitle("User Search");

View file

@ -19,7 +19,9 @@ package org.jivesoftware.smackx.sharedgroups.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -58,16 +60,11 @@ public class SharedGroupsInfo extends IQ {
/** /**
* Internal Search service Provider. * Internal Search service Provider.
*/ */
public static class Provider implements IQProvider { public static class Provider extends IQProvider<SharedGroupsInfo> {
/** @Override
* Provider Constructor. public SharedGroupsInfo parse(XmlPullParser parser, int initialDepth)
*/ throws XmlPullParserException, IOException {
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
SharedGroupsInfo groupsInfo = new SharedGroupsInfo(); SharedGroupsInfo groupsInfo = new SharedGroupsInfo();
boolean done = false; boolean done = false;

View file

@ -16,20 +16,23 @@
*/ */
package org.jivesoftware.smackx.shim.provider; package org.jivesoftware.smackx.shim.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.shim.packet.Header; import org.jivesoftware.smackx.shim.packet.Header;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parses the header element as defined in <a href="http://xmpp.org/extensions/xep-0131">Stanza Headers and Internet Metadata (SHIM)</a>. * Parses the header element as defined in <a href="http://xmpp.org/extensions/xep-0131">Stanza Headers and Internet Metadata (SHIM)</a>.
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class HeaderProvider implements PacketExtensionProvider public class HeaderProvider extends PacketExtensionProvider<Header>
{ {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception @Override
{ public Header parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
String name = parser.getAttributeValue(null, "name"); String name = parser.getAttributeValue(null, "name");
String value = null; String value = null;

View file

@ -30,11 +30,11 @@ import org.jivesoftware.smackx.shim.packet.HeadersExtension;
* *
* @author Robin Collier * @author Robin Collier
*/ */
public class HeadersProvider extends EmbeddedExtensionProvider public class HeadersProvider extends EmbeddedExtensionProvider<HeadersExtension>
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) protected HeadersExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{ {
return new HeadersExtension((Collection<Header>)content); return new HeadersExtension((Collection<Header>)content);
} }

View file

@ -16,12 +16,13 @@
*/ */
package org.jivesoftware.smackx.si.provider; package org.jivesoftware.smackx.si.provider;
import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jxmpp.util.XmppDateTime; import org.jxmpp.util.XmppDateTime;
import org.jivesoftware.smackx.si.packet.StreamInitiation; import org.jivesoftware.smackx.si.packet.StreamInitiation;
@ -29,6 +30,7 @@ import org.jivesoftware.smackx.si.packet.StreamInitiation.File;
import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jivesoftware.smackx.xdata.provider.DataFormProvider; import org.jivesoftware.smackx.xdata.provider.DataFormProvider;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* The StreamInitiationProvider parses StreamInitiation packets. * The StreamInitiationProvider parses StreamInitiation packets.
@ -36,10 +38,12 @@ import org.xmlpull.v1.XmlPullParser;
* @author Alexander Wenckus * @author Alexander Wenckus
* *
*/ */
public class StreamInitiationProvider implements IQProvider { public class StreamInitiationProvider extends IQProvider<StreamInitiation> {
private static final Logger LOGGER = Logger.getLogger(StreamInitiationProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(StreamInitiationProvider.class.getName());
public IQ parseIQ(final XmlPullParser parser) throws Exception { @Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
boolean done = false; boolean done = false;
// si // si
@ -79,7 +83,7 @@ public class StreamInitiationProvider implements IQProvider {
isRanged = true; isRanged = true;
} else if (elementName.equals("x") } else if (elementName.equals("x")
&& namespace.equals("jabber:x:data")) { && namespace.equals("jabber:x:data")) {
form = (DataForm) dataFormProvider.parseExtension(parser); form = dataFormProvider.parse(parser);
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if (elementName.equals("si")) { if (elementName.equals("si")) {

View file

@ -16,7 +16,7 @@
*/ */
package org.jivesoftware.smackx.vcardtemp.provider; package org.jivesoftware.smackx.vcardtemp.provider;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.vcardtemp.packet.VCard; import org.jivesoftware.smackx.vcardtemp.packet.VCard;
@ -25,14 +25,17 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -44,12 +47,13 @@ import java.util.logging.Logger;
* @author Gaston Dombiak * @author Gaston Dombiak
* @author Derek DeMoro * @author Derek DeMoro
*/ */
public class VCardProvider implements IQProvider { public class VCardProvider extends IQProvider<VCard> {
private static final Logger LOGGER = Logger.getLogger(VCardProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(VCardProvider.class.getName());
private static final String PREFERRED_ENCODING = "UTF-8"; private static final String PREFERRED_ENCODING = "UTF-8";
public IQ parseIQ(XmlPullParser parser) throws Exception { @Override
public VCard parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
try { try {
int event = parser.getEventType(); int event = parser.getEventType();
@ -82,7 +86,11 @@ public class VCardProvider implements IQProvider {
} }
String xmlText = sb.toString(); String xmlText = sb.toString();
return createVCardFromXML(xmlText); try {
return createVCardFromXML(xmlText);
} catch (SAXException | ParserConfigurationException e) {
throw new SmackException(e);
}
} }
/** /**
@ -90,9 +98,12 @@ public class VCardProvider implements IQProvider {
* *
* @param xml the xml representing a users vCard. * @param xml the xml representing a users vCard.
* @return the VCard. * @return the VCard.
* @throws Exception if an exception occurs. * @throws IOException
* @throws SAXException
* @throws UnsupportedEncodingException
* @throws ParserConfigurationException
*/ */
public static VCard createVCardFromXML(String xml) throws Exception { public static VCard createVCardFromXML(String xml) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException {
VCard vCard = new VCard(); VCard vCard = new VCard();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

View file

@ -17,14 +17,15 @@
package org.jivesoftware.smackx.xdata.provider; package org.jivesoftware.smackx.xdata.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.RosterPacket; import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,16 +34,10 @@ import java.util.List;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DataFormProvider implements PacketExtensionProvider { public class DataFormProvider extends PacketExtensionProvider<DataForm> {
/** @Override
* Creates a new DataFormProvider. public DataForm parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public DataFormProvider() {
}
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
boolean done = false; boolean done = false;
DataForm dataForm = new DataForm(parser.getAttributeValue("", "type")); DataForm dataForm = new DataForm(parser.getAttributeValue("", "type"));
while (!done) { while (!done) {
@ -76,7 +71,7 @@ public class DataFormProvider implements PacketExtensionProvider {
return dataForm; return dataForm;
} }
private FormField parseField(XmlPullParser parser) throws Exception { private FormField parseField(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
FormField formField = new FormField(parser.getAttributeValue("", "var")); FormField formField = new FormField(parser.getAttributeValue("", "var"));
formField.setLabel(parser.getAttributeValue("", "label")); formField.setLabel(parser.getAttributeValue("", "label"));
@ -105,7 +100,7 @@ public class DataFormProvider implements PacketExtensionProvider {
return formField; return formField;
} }
private DataForm.Item parseItem(XmlPullParser parser) throws Exception { private DataForm.Item parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
List<FormField> fields = new ArrayList<FormField>(); List<FormField> fields = new ArrayList<FormField>();
while (!done) { while (!done) {
@ -123,7 +118,7 @@ public class DataFormProvider implements PacketExtensionProvider {
return new DataForm.Item(fields); return new DataForm.Item(fields);
} }
private DataForm.ReportedData parseReported(XmlPullParser parser) throws Exception { private DataForm.ReportedData parseReported(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
List<FormField> fields = new ArrayList<FormField>(); List<FormField> fields = new ArrayList<FormField>();
while (!done) { while (!done) {
@ -141,7 +136,7 @@ public class DataFormProvider implements PacketExtensionProvider {
return new DataForm.ReportedData(fields); return new DataForm.ReportedData(fields);
} }
private FormField.Option parseOption(XmlPullParser parser) throws Exception { private FormField.Option parseOption(XmlPullParser parser) throws XmlPullParserException, IOException {
boolean done = false; boolean done = false;
FormField.Option option = null; FormField.Option option = null;
String label = parser.getAttributeValue("", "label"); String label = parser.getAttributeValue("", "label");

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.xhtmlim.provider; package org.jivesoftware.smackx.xhtmlim.provider;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension; import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
@ -31,12 +30,12 @@ import java.io.IOException;
* *
* @author Florian Schmaus * @author Florian Schmaus
*/ */
public class XHTMLExtensionProvider implements PacketExtensionProvider { public class XHTMLExtensionProvider extends PacketExtensionProvider<XHTMLExtension> {
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws IOException, XmlPullParserException { public XHTMLExtension parse(XmlPullParser parser, int initialDepth) throws IOException, XmlPullParserException {
XHTMLExtension xhtmlExtension = new XHTMLExtension(); XHTMLExtension xhtmlExtension = new XHTMLExtension();
int startDepth = parser.getDepth();
while (true) { while (true) {
int eventType = parser.getEventType(); int eventType = parser.getEventType();
String name = parser.getName(); String name = parser.getName();
@ -45,7 +44,7 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
xhtmlExtension.addBody(PacketParserUtils.parseElement(parser)); xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if (name.equals(XHTMLExtension.ELEMENT) && parser.getDepth() <= startDepth) { if (parser.getDepth() == initialDepth) {
return xhtmlExtension; return xhtmlExtension;
} }
} }

View file

@ -194,7 +194,7 @@
<iqProvider> <iqProvider>
<elementName>data</elementName> <elementName>data</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace> <namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider</className> <className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$IQProvider</className>
</iqProvider> </iqProvider>
<iqProvider> <iqProvider>
@ -206,7 +206,7 @@
<extensionProvider> <extensionProvider>
<elementName>data</elementName> <elementName>data</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace> <namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider</className> <className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider$PacketExtensionProvider</className>
</extensionProvider> </extensionProvider>
<!-- Ad-Hoc Command --> <!-- Ad-Hoc Command -->

View file

@ -70,7 +70,7 @@ public class AMPExtensionTest {
assertEquals(XmlPullParser.START_TAG, parser.next()); assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals(AMPExtension.ELEMENT, parser.getName()); assertEquals(AMPExtension.ELEMENT, parser.getName());
PacketExtension extension = ampProvider.parseExtension(parser); PacketExtension extension = ampProvider.parse(parser);
assertTrue(extension instanceof AMPExtension); assertTrue(extension instanceof AMPExtension);
AMPExtension amp = (AMPExtension) extension; AMPExtension amp = (AMPExtension) extension;
@ -89,7 +89,7 @@ public class AMPExtensionTest {
assertEquals(XmlPullParser.START_TAG, parser.next()); assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals(AMPExtension.ELEMENT, parser.getName()); assertEquals(AMPExtension.ELEMENT, parser.getName());
PacketExtension extension = ampProvider.parseExtension(parser); PacketExtension extension = ampProvider.parse(parser);
assertTrue(extension instanceof AMPExtension); assertTrue(extension instanceof AMPExtension);
AMPExtension amp = (AMPExtension) extension; AMPExtension amp = (AMPExtension) extension;

View file

@ -53,7 +53,7 @@ public class OpenIQProviderTest {
.asString(outputProperties); .asString(outputProperties);
OpenIQProvider oip = new OpenIQProvider(); OpenIQProvider oip = new OpenIQProvider();
Open open = (Open) oip.parseIQ(getParser(control)); Open open = oip.parse(getParser(control));
assertEquals(StanzaType.IQ, open.getStanza()); assertEquals(StanzaType.IQ, open.getStanza());
} }
@ -68,7 +68,7 @@ public class OpenIQProviderTest {
.asString(outputProperties); .asString(outputProperties);
OpenIQProvider oip = new OpenIQProvider(); OpenIQProvider oip = new OpenIQProvider();
Open open = (Open) oip.parseIQ(getParser(control)); Open open = oip.parse(getParser(control));
assertEquals(StanzaType.MESSAGE, open.getStanza()); assertEquals(StanzaType.MESSAGE, open.getStanza());
} }

View file

@ -69,7 +69,7 @@ public class DelayInformationTest extends InitExtensions {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
delayInfo = (DelayInformation) p.parseExtension(parser); delayInfo = (DelayInformation) p.parse(parser);
assertEquals("capulet.com", delayInfo.getFrom()); assertEquals("capulet.com", delayInfo.getFrom());
assertEquals(date, delayInfo.getStamp()); assertEquals(date, delayInfo.getStamp());
@ -85,7 +85,7 @@ public class DelayInformationTest extends InitExtensions {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
delayInfo = (DelayInformation) p.parseExtension(parser); delayInfo = (DelayInformation) p.parse(parser);
assertEquals("capulet.com", delayInfo.getFrom()); assertEquals("capulet.com", delayInfo.getFrom());
assertEquals(date, delayInfo.getStamp()); assertEquals(date, delayInfo.getStamp());
@ -109,7 +109,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", "2002-09-10T23:08:25.12Z") .a("stamp", "2002-09-10T23:08:25.12Z")
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
GregorianCalendar cal = (GregorianCalendar) calendar.clone(); GregorianCalendar cal = (GregorianCalendar) calendar.clone();
cal.add(Calendar.MILLISECOND, 12); cal.add(Calendar.MILLISECOND, 12);
@ -122,7 +122,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", "2002-09-10T23:08:25Z") .a("stamp", "2002-09-10T23:08:25Z")
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
assertEquals(calendar.getTime(), delayInfo.getStamp()); assertEquals(calendar.getTime(), delayInfo.getStamp());
@ -133,7 +133,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", "2002-9-10T23:08:25Z") .a("stamp", "2002-9-10T23:08:25Z")
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
assertEquals(calendar.getTime(), delayInfo.getStamp()); assertEquals(calendar.getTime(), delayInfo.getStamp());
} }
@ -152,7 +152,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", "20020910T23:08:25") .a("stamp", "20020910T23:08:25")
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
assertEquals(calendar.getTime(), delayInfo.getStamp()); assertEquals(calendar.getTime(), delayInfo.getStamp());
@ -172,7 +172,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", dateFormat.format(dateInPast.getTime())) .a("stamp", dateFormat.format(dateInPast.getTime()))
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
assertEquals(dateInPast.getTime(), delayInfo.getStamp()); assertEquals(dateInPast.getTime(), delayInfo.getStamp());
@ -183,7 +183,7 @@ public class DelayInformationTest extends InitExtensions {
.a("stamp", "200868T09:16:20") .a("stamp", "200868T09:16:20")
.asString(outputProperties); .asString(outputProperties);
delayInfo = (DelayInformation) p.parseExtension(PacketParserUtils.getParserFor(control)); delayInfo = (DelayInformation) p.parse(PacketParserUtils.getParserFor(control));
Date controlDate = XmppDateTime.parseDate("2008-06-08T09:16:20.0Z"); Date controlDate = XmppDateTime.parseDate("2008-06-08T09:16:20.0Z");
assertEquals(controlDate, delayInfo.getStamp()); assertEquals(controlDate, delayInfo.getStamp());

View file

@ -47,7 +47,7 @@ public class ForwardedTest {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
fwd = (Forwarded) new ForwardedProvider().parseExtension(parser); fwd = (Forwarded) new ForwardedProvider().parse(parser);
// no delay in packet // no delay in packet
assertEquals(null, fwd.getDelayInformation()); assertEquals(null, fwd.getDelayInformation());
@ -71,6 +71,6 @@ public class ForwardedTest {
.asString(outputProperties); .asString(outputProperties);
parser = PacketParserUtils.getParserFor(control); parser = PacketParserUtils.getParserFor(control);
new ForwardedProvider().parseExtension(parser); new ForwardedProvider().parse(parser);
} }
} }

View file

@ -40,7 +40,7 @@ public class XHTMLExtensionProviderTest {
parser.next(); parser.next();
XHTMLExtensionProvider provider = new XHTMLExtensionProvider(); XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
PacketExtension extension = provider.parseExtension(parser); PacketExtension extension = provider.parse(parser, parser.getDepth());
assertThat(extension, instanceOf(XHTMLExtension.class)); assertThat(extension, instanceOf(XHTMLExtension.class));
XHTMLExtension attachmentsInfo = (XHTMLExtension) extension; XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;

View file

@ -17,12 +17,14 @@
package org.jivesoftware.smackx.jingleold.nat; package org.jivesoftware.smackx.jingleold.nat;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -34,6 +36,7 @@ import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* RTPBridge IQ Packet used to request and retrieve a RTPBridge Candidates that can be used for a Jingle Media Transmission between two parties that are behind NAT. * RTPBridge IQ Packet used to request and retrieve a RTPBridge Candidates that can be used for a Jingle Media Transmission between two parties that are behind NAT.
@ -316,13 +319,12 @@ public class RTPBridge extends IQ {
* *
* @author Thiago Rocha * @author Thiago Rocha
*/ */
public static class Provider implements IQProvider { public static class Provider extends IQProvider<RTPBridge> {
public Provider() { @Override
super(); public RTPBridge parse(XmlPullParser parser, int initialDepth)
} throws SmackException, XmlPullParserException,
IOException {
public IQ parseIQ(XmlPullParser parser) throws Exception {
boolean done = false; boolean done = false;
@ -330,7 +332,7 @@ public class RTPBridge extends IQ {
String elementName; String elementName;
if (!parser.getNamespace().equals(RTPBridge.NAMESPACE)) if (!parser.getNamespace().equals(RTPBridge.NAMESPACE))
throw new Exception("Not a RTP Bridge packet"); throw new SmackException("Not a RTP Bridge packet");
RTPBridge iq = new RTPBridge(); RTPBridge iq = new RTPBridge();

View file

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smackx.jingleold.nat; package org.jivesoftware.smackx.jingleold.nat;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -32,6 +33,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT. * STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT.
@ -119,13 +121,12 @@ public class STUN extends IQ {
* *
* @author Thiago Rocha * @author Thiago Rocha
*/ */
public static class Provider implements IQProvider { public static class Provider extends IQProvider<STUN> {
public Provider() { @Override
super(); public STUN parse(XmlPullParser parser, int initialDepth)
} throws SmackException, XmlPullParserException,
IOException {
public IQ parseIQ(XmlPullParser parser) throws Exception {
boolean done = false; boolean done = false;
@ -133,7 +134,7 @@ public class STUN extends IQ {
String elementName; String elementName;
if (!parser.getNamespace().equals(NAMESPACE)) if (!parser.getNamespace().equals(NAMESPACE))
throw new Exception("Not a STUN packet"); throw new SmackException("Not a STUN packet");
STUN iq = new STUN(); STUN iq = new STUN();

View file

@ -122,7 +122,7 @@ public class JingleError implements PacketExtension {
return NAMESPACE; return NAMESPACE;
} }
public static class Provider implements PacketExtensionProvider { public static class Provider extends PacketExtensionProvider<PacketExtension> {
private PacketExtension audioInfo; private PacketExtension audioInfo;
@ -135,8 +135,8 @@ public class JingleError implements PacketExtension {
/** /**
* Parse a JingleDescription.Audio extension. * Parse a JingleDescription.Audio extension.
*/ */
public PacketExtension parseExtension(final XmlPullParser parser) @Override
throws Exception { public PacketExtension parse(XmlPullParser parser, int initialDepth) {
PacketExtension result = null; PacketExtension result = null;
if (audioInfo != null) { if (audioInfo != null) {

View file

@ -16,36 +16,30 @@
*/ */
package org.jivesoftware.smackx.jingleold.provider; package org.jivesoftware.smackx.jingleold.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.jingleold.media.PayloadType; import org.jivesoftware.smackx.jingleold.media.PayloadType;
import org.jivesoftware.smackx.jingleold.packet.JingleContentDescription; import org.jivesoftware.smackx.jingleold.packet.JingleContentDescription;
import org.jivesoftware.smackx.jingleold.packet.JingleContentDescription.JinglePayloadType; import org.jivesoftware.smackx.jingleold.packet.JingleContentDescription.JinglePayloadType;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parser for a Jingle description * Parser for a Jingle description
* *
* @author Alvaro Saurin <alvaro.saurin@gmail.com> * @author Alvaro Saurin <alvaro.saurin@gmail.com>
*/ */
public abstract class JingleContentDescriptionProvider implements PacketExtensionProvider { public abstract class JingleContentDescriptionProvider extends PacketExtensionProvider<JingleContentDescription> {
/**
* Default constructor
*/
public JingleContentDescriptionProvider() {
super();
}
/** /**
* Parse a iq/jingle/description/payload-type element. * Parse a iq/jingle/description/payload-type element.
* *
* @param parser the input to parse * @param parser the input to parse
* @return a payload type element * @return a payload type element
* @throws Exception
*/ */
protected JinglePayloadType parsePayload(final XmlPullParser parser) protected JinglePayloadType parsePayload(final XmlPullParser parser) {
throws Exception {
int ptId = 0; int ptId = 0;
String ptName; String ptName;
int ptChannels = 0; int ptChannels = 0;
@ -70,9 +64,14 @@ public abstract class JingleContentDescriptionProvider implements PacketExtensio
* *
* @param parser the input to parse * @param parser the input to parse
* @return a description element * @return a description element
* @throws Exception * @throws IOException
* @throws XmlPullParserException
* @throws SmackException
*/ */
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception { @Override
public JingleContentDescription parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException, SmackException {
boolean done = false; boolean done = false;
JingleContentDescription desc = getInstance(); JingleContentDescription desc = getInstance();
@ -84,7 +83,7 @@ public abstract class JingleContentDescriptionProvider implements PacketExtensio
if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) { if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) {
desc.addJinglePayloadType(parsePayload(parser)); desc.addJinglePayloadType(parsePayload(parser));
} else { } else {
throw new Exception("Unknow element \"" + name + "\" in content."); throw new SmackException("Unknow element \"" + name + "\" in content.");
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if (name.equals(JingleContentDescription.NODENAME)) { if (name.equals(JingleContentDescription.NODENAME)) {
@ -106,18 +105,10 @@ public abstract class JingleContentDescriptionProvider implements PacketExtensio
*/ */
public static class Audio extends JingleContentDescriptionProvider { public static class Audio extends JingleContentDescriptionProvider {
/**
* Default constructor
*/
public Audio() {
super();
}
/** /**
* Parse an audio payload type. * Parse an audio payload type.
*/ */
public JinglePayloadType parsePayload(final XmlPullParser parser) public JinglePayloadType parsePayload(final XmlPullParser parser) {
throws Exception {
JinglePayloadType pte = super.parsePayload(parser); JinglePayloadType pte = super.parsePayload(parser);
PayloadType.Audio pt = new PayloadType.Audio(pte.getPayloadType()); PayloadType.Audio pt = new PayloadType.Audio(pte.getPayloadType());
int ptClockRate = 0; int ptClockRate = 0;

View file

@ -27,27 +27,14 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Alvaro Saurin * @author Alvaro Saurin
*/ */
public class JingleContentInfoProvider implements PacketExtensionProvider { public class JingleContentInfoProvider {
/**
* Creates a new provider. ProviderManager requires that every
* PacketExtensionProvider has a public, no-argument constructor
*/
public JingleContentInfoProvider() {
super();
}
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception {
// This method must be overwritten by subclasses...
return null;
}
/** /**
* JingleDescription.Audio info provider * JingleDescription.Audio info provider
*/ */
public static class Audio extends JingleContentInfoProvider { public static class Audio extends PacketExtensionProvider<PacketExtension> {
private PacketExtension audioInfo; private final PacketExtension audioInfo;
/** /**
* Empty constructor. * Empty constructor.
@ -69,8 +56,8 @@ public class JingleContentInfoProvider implements PacketExtensionProvider {
/** /**
* Parse a JingleDescription.Audio extension. * Parse a JingleDescription.Audio extension.
*/ */
public PacketExtension parseExtension(final XmlPullParser parser) @Override
throws Exception { public PacketExtension parse(XmlPullParser parser, int initialDepth) {
PacketExtension result = null; PacketExtension result = null;
if (audioInfo != null) { if (audioInfo != null) {

View file

@ -16,7 +16,6 @@
*/ */
package org.jivesoftware.smackx.jingleold.provider; package org.jivesoftware.smackx.jingleold.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.jingleold.packet.JingleContent; import org.jivesoftware.smackx.jingleold.packet.JingleContent;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -26,30 +25,19 @@ import org.xmlpull.v1.XmlPullParser;
* *
* @author Jeff Williams * @author Jeff Williams
*/ */
public class JingleContentProvider implements PacketExtensionProvider { public class JingleContentProvider extends PacketExtensionProvider<JingleContent> {
/**
* Creates a new provider. ProviderManager requires that every
* PacketExtensionProvider has a public, no-argument constructor
*/
public JingleContentProvider() {
super();
}
/** /**
* Parse a JingleContent extension. * Parse a JingleContent extension.
*/ */
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception { @Override
PacketExtension result = null; public JingleContent parse(XmlPullParser parser, int initialDepth) {
String elementName = parser.getName(); String elementName = parser.getName();
String creator = parser.getAttributeValue("", JingleContent.CREATOR); String creator = parser.getAttributeValue("", JingleContent.CREATOR);
String name = parser.getAttributeValue("", JingleContent.NAME); String name = parser.getAttributeValue("", JingleContent.NAME);
// Try to get an Audio content info // Try to get an Audio content info
result = new JingleContent(creator, name); return new JingleContent(creator, name);
return result;
} }
} }

View file

@ -16,25 +16,21 @@
*/ */
package org.jivesoftware.smackx.jingleold.provider; package org.jivesoftware.smackx.jingleold.provider;
import org.jivesoftware.smack.packet.PacketExtension; import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.jingleold.media.PayloadType; import org.jivesoftware.smackx.jingleold.media.PayloadType;
import org.jivesoftware.smackx.jingleold.packet.JingleDescription; import org.jivesoftware.smackx.jingleold.packet.JingleDescription;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Parser for a Jingle description * Parser for a Jingle description
* *
* @author Alvaro Saurin <alvaro.saurin@gmail.com> * @author Alvaro Saurin <alvaro.saurin@gmail.com>
*/ */
public abstract class JingleDescriptionProvider implements PacketExtensionProvider { public abstract class JingleDescriptionProvider extends PacketExtensionProvider<JingleDescription> {
/**
* Default constructor
*/
public JingleDescriptionProvider() {
super();
}
/** /**
* Parse a iq/jingle/description/payload-type element. * Parse a iq/jingle/description/payload-type element.
@ -42,9 +38,8 @@ public abstract class JingleDescriptionProvider implements PacketExtensionProvid
* @param parser * @param parser
* the input to parse * the input to parse
* @return a payload type element * @return a payload type element
* @throws Exception
*/ */
protected PayloadType parsePayload(final XmlPullParser parser) throws Exception { protected PayloadType parsePayload(final XmlPullParser parser) {
int ptId = 0; int ptId = 0;
String ptName; String ptName;
int ptChannels = 0; int ptChannels = 0;
@ -70,9 +65,11 @@ public abstract class JingleDescriptionProvider implements PacketExtensionProvid
* @param parser * @param parser
* the input to parse * the input to parse
* @return a description element * @return a description element
* @throws Exception * @throws SmackException
* @throws IOException
* @throws XmlPullParserException
*/ */
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception { public JingleDescription parse(XmlPullParser parser, int initialDepth) throws SmackException, XmlPullParserException, IOException {
boolean done = false; boolean done = false;
JingleDescription desc = getInstance(); JingleDescription desc = getInstance();
@ -84,7 +81,7 @@ public abstract class JingleDescriptionProvider implements PacketExtensionProvid
if (name.equals(PayloadType.NODENAME)) { if (name.equals(PayloadType.NODENAME)) {
desc.addPayloadType(parsePayload(parser)); desc.addPayloadType(parsePayload(parser));
} else { } else {
throw new Exception("Unknow element \"" + name + "\" in content."); throw new SmackException("Unknow element \"" + name + "\" in content.");
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if (name.equals(JingleDescription.NODENAME)) { if (name.equals(JingleDescription.NODENAME)) {
@ -106,17 +103,10 @@ public abstract class JingleDescriptionProvider implements PacketExtensionProvid
*/ */
public static class Audio extends JingleDescriptionProvider { public static class Audio extends JingleDescriptionProvider {
/**
* Default constructor
*/
public Audio() {
super();
}
/** /**
* Parse an audio payload type. * Parse an audio payload type.
*/ */
public PayloadType parsePayload(final XmlPullParser parser) throws Exception { public PayloadType parsePayload(final XmlPullParser parser) {
PayloadType pte = super.parsePayload(parser); PayloadType pte = super.parsePayload(parser);
PayloadType.Audio pt = new PayloadType.Audio(pte); PayloadType.Audio pt = new PayloadType.Audio(pte);
int ptClockRate = 0; int ptClockRate = 0;

Some files were not shown because too many files have changed in this diff Show more