1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 05:22:06 +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
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_
@ -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
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_
@ -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();
boolean done = false;
DiscoverItems.Item item;
String jid = "";
String name = "";
String action = "";
String node = "";
discoverItems.setNode(parser.getAttributeValue("", "node"));
while (!done) {
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) {
switch (eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
switch (elementName) {
case "item":
// Initialize the variables from the parsed XML
jid = parser.getAttributeValue("", "jid");
name = parser.getAttributeValue("", "name");
node = parser.getAttributeValue("", "node");
action = parser.getAttributeValue("", "action");
break;
}
else if (eventType == XmlPullParser.END_TAG && "item".equals(parser.getName())) {
break;
case XmlPullParser.END_TAG:
String elementName = parser.getName();
switch (elementName) {
case "item":
// 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;
}
else if (eventType == XmlPullParser.END_TAG && "query".equals(parser.getName())) {
done = true;
}
}
return discoverItems;

View file

@ -125,7 +125,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser
XmlPullParser parser = getParserFromXML(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
assertNotNull(packet);
@ -317,7 +317,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser
XmlPullParser parser = getParserFromXML(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.getChildElementXML());
@ -356,7 +356,7 @@ public class PrivacyProviderTest extends SmackTestCase {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
Privacy packet = (Privacy) (new PrivacyProvider()).parse(parser);
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.StartTls;
import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smack.rosterstore.RosterStore;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jxmpp.util.XmppStringUtils;
@ -1052,9 +1052,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeature = PacketParserUtils.parseCompressionFeature(parser);
break;
default:
StreamFeatureProvider provider = ProviderManager.getStreamFeatureProvider(name, namespace);
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (provider != null) {
streamFeature = provider.parseStreamFeature(parser);
streamFeature = provider.parse(parser);
}
break;
}

View file

@ -16,14 +16,17 @@
*/
package org.jivesoftware.smack.provider;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
*
@ -78,11 +81,12 @@ import org.xmlpull.v1.XmlPullParser;
*
* @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 name = parser.getName();
Map<String, String> attMap = new HashMap<String, String>();
@ -93,16 +97,17 @@ abstract public class EmbeddedExtensionProvider implements PacketExtensionProvid
}
List<PacketExtension> extensions = new ArrayList<PacketExtension>();
int tag;
do
{
int tag = parser.next();
tag = parser.next();
if (tag == XmlPullParser.START_TAG)
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);
}
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;
import org.jivesoftware.smack.packet.PacketExtension;
/**
* Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the
* {@link ProviderLoader}.
@ -32,7 +34,7 @@ public final class ExtensionProviderInfo extends AbstractProviderInfo {
* @param namespace Namespace that provider parses.
* @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);
}

View file

@ -18,27 +18,14 @@
package org.jivesoftware.smack.provider;
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
* interface <b>must</b> have a public, no-argument constructor.
* abstract class <b>must</b> have a public, no-argument constructor.
*
* @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 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);
}

View file

@ -17,27 +17,16 @@
package org.jivesoftware.smack.provider;
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
* 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
*/
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 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.XmlPullParserException;
/**
*
*/
public interface StreamFeatureProvider {
public abstract class Provider<E extends Element> {
/**
*
* @param parser an XML parser.
* @return a new PacketExtension instance.
* @throws XmlPullParserException if an error occurs parsing the XML.
*/
public PacketExtension parseStreamFeature(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException;
public final E parse(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
// XPP3 calling convention assert: Parser should be at start tag
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
E e = parse(parser, initialDepth);
// 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.
// Add the provider to the map.
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)) {
iqProviders.add(new IQProviderInfo(elementName, namespace, (Class<? extends IQ>)provider));
}
else {
exceptions.add(new IllegalArgumentException(
className
+ " is neither IQProvider or IQ class"));
}
break;
case "extensionProvider":
// 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
// of the class.
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)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, provider));
}
else {
exceptions.add(new IllegalArgumentException(
className
+ " is neither PacketExtensionProvider or PacketExtension class"));
}
break;
case "streamFeatureProvider":
sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace,
(StreamFeatureProvider) provider.newInstance()));
(PacketExtensionProvider<PacketExtension>) provider.newInstance()));
break;
default:
LOGGER.warning("Unkown provider type: " + typeName);

View file

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

View file

@ -16,6 +16,8 @@
*/
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 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);
}

View file

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

View file

@ -31,6 +31,14 @@ public class ParserUtils {
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.
*

View file

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

View file

@ -72,12 +72,12 @@ public class ParsingExceptionTest {
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 NAMESPACE = "http://smack.jivesoftware.org/exception";
@Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public PacketExtension parse(XmlPullParser parser, int initialDepth) throws SmackException {
throw new SmackException("Test Exception");
}

View file

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

View file

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

View file

@ -16,13 +16,16 @@
*/
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.util.PacketParserUtils;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
import org.jivesoftware.smackx.forward.Forwarded;
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* This class implements the {@link PacketExtensionProvider} to parse
@ -31,9 +34,13 @@ import org.xmlpull.v1.XmlPullParser;
* @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());
Forwarded fwd = null;
@ -41,13 +48,13 @@ public class CarbonManagerProvider implements PacketExtensionProvider {
while (!done) {
int eventType = parser.next();
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()))
done = true;
}
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);
}
}

View file

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

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.StringUtils;
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.provider.HeaderProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@ -33,7 +36,7 @@ import java.util.Set;
* @author Andriy Tsykholyas
* @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_HEADER = "header";
@ -56,9 +59,11 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
* @param parser parser
* @param elementName name of concrete implementation of this 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;
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();
Set<Header> set = new HashSet<Header>();
boolean done = false;
@ -92,7 +97,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals(ELEMENT_HEADER)) {
Header header = (Header) provider.parseExtension(parser);
Header header = provider.parse(parser);
set.add(header);
}
} else if (eventType == XmlPullParser.END_TAG) {
@ -104,7 +109,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
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;
boolean done = false;
@ -143,7 +148,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
return data;
}
private AbstractHttpOverXmpp.Text parseText(XmlPullParser parser) throws Exception {
private AbstractHttpOverXmpp.Text parseText(XmlPullParser parser) throws XmlPullParserException, IOException {
String text = null;
boolean done = false;
@ -166,7 +171,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
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();
boolean done = false;
boolean startClosed = true;
@ -214,7 +219,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
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
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;
boolean done = false;
@ -254,7 +259,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
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);
AbstractHttpOverXmpp.ChunkedBase64 child = new AbstractHttpOverXmpp.ChunkedBase64(streamId);
boolean done = false;
@ -275,7 +280,7 @@ public abstract class AbstractHttpOverXmppProvider implements IQProvider {
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);
AbstractHttpOverXmpp.Ibb child = new AbstractHttpOverXmpp.Ibb(sid);
boolean done = false;

View file

@ -16,10 +16,12 @@
*/
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.smackx.hoxt.packet.Base64BinaryChunk;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Packet provider for base64 binary chunks.
@ -27,16 +29,10 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas
* @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
*/
public class Base64BinaryChunkProvider implements PacketExtensionProvider {
/**
* Required no-argument constructor.
*/
public Base64BinaryChunkProvider() {
}
public class Base64BinaryChunkProvider extends PacketExtensionProvider<Base64BinaryChunk> {
@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 nrString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_NR);
String lastString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_LAST);

View file

@ -16,10 +16,13 @@
*/
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.HttpOverXmppReq;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Req packet provider.
@ -27,7 +30,7 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas
* @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";
@ -42,7 +45,8 @@ public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider {
}
@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 resource = parser.getAttributeValue("", ATTRIBUTE_RESOURCE);
String version = parser.getAttributeValue("", ATTRIBUTE_VERSION);

View file

@ -16,9 +16,12 @@
*/
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.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Resp packet provider.
@ -26,21 +29,16 @@ import org.xmlpull.v1.XmlPullParser;
* @author Andriy Tsykholyas
* @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 ATTRIBUTE_STATUS_MESSAGE = "statusMessage";
private static final String ATTRIBUTE_STATUS_CODE = "statusCode";
/**
* Mandatory no argument constructor.
*/
public HttpOverXmppRespProvider() {
}
@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 statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE);
String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);

View file

@ -52,7 +52,7 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
cc = (CarbonExtension) new CarbonManagerProvider().parse(parser);
fwd = cc.getForwarded();
// meta
@ -83,7 +83,7 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
cc = (CarbonExtension) new CarbonManagerProvider().parse(parser);
assertEquals(CarbonExtension.Direction.received, cc.getDirection());
@ -102,6 +102,6 @@ public class CarbonTest extends ExperimentalInitializerTest {
.asString(outputProperties);
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("Content-Length", "0");
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
@ -72,10 +72,10 @@ public class AbstractHttpOverXmppProviderTest {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Host", "clayster.com");
AbstractHttpOverXmppProvider provider = new HttpOverXmppReqProvider();
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parseIQ(parser);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppReq);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppReq) iq).getReq();
@ -181,10 +181,10 @@ public class AbstractHttpOverXmppProviderTest {
}
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string, tag);
IQ iq = provider.parseIQ(parser);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
return body;

View file

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

View file

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

View file

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

View file

@ -25,10 +25,10 @@ import org.xmlpull.v1.XmlPullParser;
* @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;
int numTires = 0;

View file

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

View file

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

View file

@ -215,7 +215,7 @@ public class Bookmarks implements PrivateData {
super();
}
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception {
public PrivateData parsePrivateData(XmlPullParser parser) throws XmlPullParserException, IOException {
Bookmarks storage = new Bookmarks();
boolean done = false;
@ -265,7 +265,7 @@ public class Bookmarks implements PrivateData {
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 autojoin = parser.getAttributeValue("", "autojoin");
String jid = parser.getAttributeValue("", "jid");

View file

@ -16,7 +16,6 @@
*/
package org.jivesoftware.smackx.bytestreams.ibb.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
import org.xmlpull.v1.XmlPullParser;
@ -26,9 +25,10 @@ import org.xmlpull.v1.XmlPullParser;
*
* @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");
return new Close(sid);
}

View file

@ -16,13 +16,13 @@
*/
package org.jivesoftware.smackx.bytestreams.ibb.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* 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
*/
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> {
private static final PacketExtensionProvider packetExtensionProvider = new PacketExtensionProvider();
@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 static class PacketExtensionProvider extends org.jivesoftware.smack.provider.PacketExtensionProvider<DataPacketExtension> {
@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);
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
DataPacketExtension data = (DataPacketExtension) parseExtension(parser);
IQ iq = new Data(data);
return iq;
}
}

View file

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

View file

@ -16,19 +16,23 @@
*/
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.smackx.bytestreams.socks5.packet.Bytestream;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses a bytestream packet.
*
* @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;
Bytestream toReturn = new Bytestream();

View file

@ -19,17 +19,15 @@ package org.jivesoftware.smackx.caps.provider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.StreamFeatureProvider;
import org.jivesoftware.smackx.caps.EntityCapsManager;
import org.jivesoftware.smackx.caps.packet.CapsExtension;
import org.xmlpull.v1.XmlPullParser;
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 {
String hash = 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;
}
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;
try {
state = ChatState.valueOf(parser.getName());

View file

@ -17,8 +17,9 @@
package org.jivesoftware.smackx.commands.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.provider.IQProvider;
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.provider.DataFormProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The AdHocCommandDataProvider parses AdHocCommandData packets.
*
* @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;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
@ -93,7 +97,7 @@ public class AdHocCommandDataProvider implements IQProvider {
adHocCommandData.addAction(AdHocCommand.Action.prev);
}
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")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
@ -115,38 +119,44 @@ public class AdHocCommandDataProvider implements IQProvider {
return adHocCommandData;
}
public static class BadActionError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class BadActionError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badAction);
}
}
public static class MalformedActionError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class MalformedActionError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.malformedAction);
}
}
public static class BadLocaleError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class BadLocaleError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badLocale);
}
}
public static class BadPayloadError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class BadPayloadError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badPayload);
}
}
public static class BadSessionIDError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class BadSessionIDError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badSessionid);
}
}
public static class SessionExpiredError implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public static class SessionExpiredError extends PacketExtensionProvider<AdHocCommandData.SpecificError> {
@Override
public AdHocCommandData.SpecificError parse(XmlPullParser parser, int initialDepth) {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.sessionExpired);
}
}

View file

@ -16,17 +16,22 @@
*/
package org.jivesoftware.smackx.delay.provider;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public abstract class AbstractDelayInformationProvider implements PacketExtensionProvider {
public abstract class AbstractDelayInformationProvider extends PacketExtensionProvider<DelayInformation> {
@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 from = parser.getAttributeValue("", "from");
String reason = null;
@ -46,10 +51,14 @@ public abstract class AbstractDelayInformationProvider implements PacketExtensio
} else {
parser.next();
}
assert(parser.getEventType() == XmlPullParser.END_TAG);
Date stamp = parseDate(stampString);
Date stamp;
try {
stamp = parseDate(stampString);
} catch (ParseException e) {
throw new SmackException(e);
}
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;
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.util.PacketParserUtils;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The DiscoverInfoProvider parses Service Discovery information packets.
*
* @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();
boolean done = false;
DiscoverInfo.Identity identity = null;

View file

@ -17,19 +17,23 @@
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.smackx.disco.packet.DiscoverItems;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The DiscoverInfoProvider parses Service Discovery items packets.
*
* @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();
boolean done = false;
DiscoverItems.Item item;

View file

@ -16,13 +16,16 @@
*/
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.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.jivesoftware.smackx.forward.Forwarded;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* This class implements the {@link PacketExtensionProvider} to parse
@ -30,8 +33,10 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Georg Lukas
*/
public class ForwardedProvider implements PacketExtensionProvider {
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public class ForwardedProvider extends PacketExtensionProvider<Forwarded> {
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
DelayInformation di = null;
Packet packet = null;
@ -43,13 +48,13 @@ public class ForwardedProvider implements PacketExtensionProvider {
di = (DelayInformation)PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser);
else if (parser.getName().equals("message"))
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))
done = true;
}
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);
}
}

View file

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

View file

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

View file

@ -17,7 +17,11 @@
package org.jivesoftware.smackx.iqprivate.provider;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
/**
@ -37,7 +41,6 @@ public interface PrivateDataProvider {
*
* @param parser an XML parser.
* @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;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class RegistrationProvider implements IQProvider {
public class RegistrationProvider extends IQProvider<Registration> {
@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
public Registration parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String instruction = null;
Map<String, String> fields = new HashMap<String, String>();
List<PacketExtension> packetExtensions = new LinkedList<PacketExtension>();

View file

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

View file

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

View file

@ -17,20 +17,21 @@
package org.jivesoftware.smackx.jiveproperties.provider;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
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());
@ -45,10 +46,13 @@ public class JivePropertiesExtensionProvider implements PacketExtensionProvider
*
* @param parser the XML parser, positioned at the start of a properties sub-packet.
* @return a map of the properties.
* @throws Exception if an error occurs while parsing the properties.
* @throws IOException
* @throws XmlPullParserException
*/
@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>();
while (true) {
int eventType = parser.next();

View file

@ -17,11 +17,14 @@
package org.jivesoftware.smackx.muc.packet;
import java.io.IOException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* 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);
}
public static class Provider implements PacketExtensionProvider {
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
public static class Provider extends PacketExtensionProvider<GroupChatInvitation> {
@Override
public GroupChatInvitation parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
String roomAddress = parser.getAttributeValue("", "jid");
// Advance to end of extension.
parser.next();

View file

@ -17,19 +17,23 @@
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.smackx.muc.packet.MUCAdmin;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
*
* @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();
boolean done = false;
while (!done) {

View file

@ -17,20 +17,25 @@
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.util.PacketParserUtils;
import org.jivesoftware.smackx.muc.packet.MUCOwner;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
*
* @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();
boolean done = false;
while (!done) {

View file

@ -16,14 +16,17 @@
*/
package org.jivesoftware.smackx.muc.provider;
import java.io.IOException;
import org.jivesoftware.smackx.muc.MUCAffiliation;
import org.jivesoftware.smackx.muc.MUCRole;
import org.jivesoftware.smackx.muc.packet.Destroy;
import org.jivesoftware.smackx.muc.packet.MUCItem;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class MUCParserUtils {
public static MUCItem parseItem(XmlPullParser parser) throws Exception {
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth();
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
String nick = parser.getAttributeValue("", "nick");
@ -54,7 +57,7 @@ public class MUCParserUtils {
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;
Destroy destroy = new Destroy();
destroy.setJid(parser.getAttributeValue("", "jid"));

View file

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

View file

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

View file

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

View file

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

View file

@ -17,12 +17,15 @@
package org.jivesoftware.smackx.pep.provider;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
*
@ -38,19 +41,11 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Jeff Williams
*/
public class PEPProvider implements PacketExtensionProvider {
public class PEPProvider extends PacketExtensionProvider<PacketExtension> {
Map<String, PacketExtensionProvider> nodeParsers = new HashMap<String, PacketExtensionProvider>();
PacketExtension pepItem;
private static final Map<String, PacketExtensionProvider<?>> nodeParsers = new HashMap<String, PacketExtensionProvider<?>>();
/**
* Creates a new PEPProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
*/
public PEPProvider() {
}
public void registerPEPParserExtension(String node, PacketExtensionProvider pepItemParser) {
public static void registerPEPParserExtension(String node, PacketExtensionProvider<?> 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.
* @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;
while (!done) {
int eventType = parser.next();
@ -73,9 +72,9 @@ public class PEPProvider implements PacketExtensionProvider {
// Figure out the node for this event.
String node = parser.getAttributeValue("", "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) {
pepItem = nodeParser.parseExtension(parser);
pepItem = nodeParser.parse(parser);
}
}
} else if (eventType == XmlPullParser.END_TAG) {

View file

@ -16,14 +16,17 @@
*/
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.smackx.ping.packet.Ping;
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
// have filled out all relevant fields ('from', 'to', 'id').
return new Ping();

View file

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

View file

@ -29,10 +29,10 @@ import org.jivesoftware.smackx.pubsub.Affiliation;
*
* @author Robin Collier
*/
public class AffiliationProvider extends EmbeddedExtensionProvider
public class AffiliationProvider extends EmbeddedExtensionProvider<Affiliation>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected Affiliation createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new Affiliation(attributeMap.get("node"), Affiliation.Type.valueOf(attributeMap.get("affiliation")));
}

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>.
*
* @author Robin Collier
*/public class AffiliationsProvider extends EmbeddedExtensionProvider
*/public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension>
{
@SuppressWarnings("unchecked")
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new AffiliationsExtension((List<Affiliation>)content);
}

View file

@ -31,10 +31,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*
* @author Robin Collier
*/
public class ConfigEventProvider extends EmbeddedExtensionProvider
public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
{
if (content.size() == 0)
return new ConfigurationEvent(attMap.get("node"));

View file

@ -31,10 +31,10 @@ import org.jivesoftware.smackx.pubsub.NodeExtension;
*
* @author Robin Collier
*/
public class EventProvider extends EmbeddedExtensionProvider
public class EventProvider extends EmbeddedExtensionProvider<EventElement>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
{
return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0));
}

View file

@ -32,10 +32,10 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*
* @author Robin Collier
*/
public class FormNodeProvider extends EmbeddedExtensionProvider
public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
}

View file

@ -16,6 +16,9 @@
*/
package org.jivesoftware.smackx.pubsub.provider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ProviderManager;
@ -25,6 +28,7 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses an <b>item</b> element as is defined in both the {@link PubSubNamespace#BASIC} and
@ -34,10 +38,11 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Robin Collier
*/
public class ItemProvider implements PacketExtensionProvider
public class ItemProvider extends PacketExtensionProvider<Item>
{
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
@Override
public Item parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");

View file

@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension;
*
* @author Robin Collier
*/
public class ItemsProvider extends EmbeddedExtensionProvider
public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
}

View file

@ -16,6 +16,9 @@
*/
package org.jivesoftware.smackx.pubsub.provider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider;
@ -23,6 +26,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses the root pubsub packet extensions of the {@link IQ} packet and returns
@ -30,10 +34,11 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Robin Collier
*/
public class PubSubProvider implements IQProvider
public class PubSubProvider extends IQProvider<PubSub>
{
public IQ parseIQ(XmlPullParser parser) throws Exception
{
@Override
public PubSub parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
PubSub pubsub = new PubSub();
String namespace = parser.getNamespace();
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));

View file

@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.RetractItem;
*
* @author Robin Collier
*/
public class RetractEventProvider extends EmbeddedExtensionProvider
public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new RetractItem(attributeMap.get("id"));
}

View file

@ -30,10 +30,10 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType;
*
* @author Robin Collier
*/
public class SimpleNodeProvider extends EmbeddedExtensionProvider
public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension>
{
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node"));
}

View file

@ -16,10 +16,12 @@
*/
package org.jivesoftware.smackx.pubsub.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import java.io.IOException;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses the <b>subscription</b> element out of the pubsub IQ message from
@ -27,10 +29,11 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Robin Collier
*/
public class SubscriptionProvider implements PacketExtensionProvider
public class SubscriptionProvider extends PacketExtensionProvider<Subscription>
{
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
@Override
public Subscription parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
String jid = parser.getAttributeValue(null, "jid");
String nodeId = parser.getAttributeValue(null, "node");
String subId = parser.getAttributeValue(null, "subid");

View file

@ -30,11 +30,11 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
*
* @author Robin Collier
*/
public class SubscriptionsProvider extends EmbeddedExtensionProvider
public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension>
{
@SuppressWarnings("unchecked")
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
{
return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content);
}

View file

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

View file

@ -16,11 +16,14 @@
*/
package org.jivesoftware.smackx.receipts;
import java.io.IOException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* 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.
*/
public static class Provider implements PacketExtensionProvider {
public static class Provider extends PacketExtensionProvider<DeliveryReceiptRequest> {
@Override
public PacketExtension parseExtension(XmlPullParser parser) {
public DeliveryReceiptRequest parse(XmlPullParser parser,
int initialDepth) throws XmlPullParserException,
IOException {
return new DeliveryReceiptRequest();
}
}

View file

@ -16,19 +16,19 @@
*/
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.util.ParserUtils;
import org.jivesoftware.smackx.rsm.packet.RSMSet;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class RSMSetProvider implements PacketExtensionProvider {
public class RSMSetProvider extends PacketExtensionProvider<RSMSet> {
@Override
public PacketExtension parseExtension(XmlPullParser parser)
throws Exception {
int initialDepth = parser.getDepth();
public RSMSet parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
String after = null;
String before = null;
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.FormField;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
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();
data.addColumn(new ReportedData.Column("JID", "jid", "text-single"));

View file

@ -16,6 +16,9 @@
*/
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.NotConnectedException;
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.packet.DataForm;
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
@ -124,16 +128,11 @@ public class UserSearch extends IQ {
/**
* Internal Search service Provider.
*/
public static class Provider implements IQProvider {
public static class Provider extends IQProvider<IQ> {
/**
* Provider Constructor.
*/
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
// FIXME this provider does return two different types of IQs
@Override
public IQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
UserSearch search = null;
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);
boolean done = false;
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.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -58,16 +60,11 @@ public class SharedGroupsInfo extends IQ {
/**
* Internal Search service Provider.
*/
public static class Provider implements IQProvider {
public static class Provider extends IQProvider<SharedGroupsInfo> {
/**
* Provider Constructor.
*/
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
@Override
public SharedGroupsInfo parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
SharedGroupsInfo groupsInfo = new SharedGroupsInfo();
boolean done = false;

View file

@ -16,20 +16,23 @@
*/
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.smackx.shim.packet.Header;
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>.
*
* @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 value = null;

View file

@ -30,11 +30,11 @@ import org.jivesoftware.smackx.shim.packet.HeadersExtension;
*
* @author Robin Collier
*/
public class HeadersProvider extends EmbeddedExtensionProvider
public class HeadersProvider extends EmbeddedExtensionProvider<HeadersExtension>
{
@SuppressWarnings("unchecked")
@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);
}

View file

@ -16,12 +16,13 @@
*/
package org.jivesoftware.smackx.si.provider;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jxmpp.util.XmppDateTime;
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.provider.DataFormProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* The StreamInitiationProvider parses StreamInitiation packets.
@ -36,10 +38,12 @@ import org.xmlpull.v1.XmlPullParser;
* @author Alexander Wenckus
*
*/
public class StreamInitiationProvider implements IQProvider {
public class StreamInitiationProvider extends IQProvider<StreamInitiation> {
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;
// si
@ -79,7 +83,7 @@ public class StreamInitiationProvider implements IQProvider {
isRanged = true;
} else if (elementName.equals("x")
&& namespace.equals("jabber:x:data")) {
form = (DataForm) dataFormProvider.parseExtension(parser);
form = dataFormProvider.parse(parser);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (elementName.equals("si")) {

View file

@ -16,7 +16,7 @@
*/
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.util.StringUtils;
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.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@ -44,12 +47,13 @@ import java.util.logging.Logger;
* @author Gaston Dombiak
* @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 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();
try {
int event = parser.getEventType();
@ -82,7 +86,11 @@ public class VCardProvider implements IQProvider {
}
String xmlText = sb.toString();
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.
* @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();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

View file

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

View file

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

View file

@ -194,7 +194,7 @@
<iqProvider>
<elementName>data</elementName>
<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>
@ -206,7 +206,7 @@
<extensionProvider>
<elementName>data</elementName>
<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>
<!-- Ad-Hoc Command -->

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -17,12 +17,14 @@
package org.jivesoftware.smackx.jingleold.nat;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
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.packet.DiscoverInfo;
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.
@ -316,13 +319,12 @@ public class RTPBridge extends IQ {
*
* @author Thiago Rocha
*/
public static class Provider implements IQProvider {
public static class Provider extends IQProvider<RTPBridge> {
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
@Override
public RTPBridge parse(XmlPullParser parser, int initialDepth)
throws SmackException, XmlPullParserException,
IOException {
boolean done = false;
@ -330,7 +332,7 @@ public class RTPBridge extends IQ {
String elementName;
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();

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smackx.jingleold.nat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.DiscoverItems;
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.
@ -119,13 +121,12 @@ public class STUN extends IQ {
*
* @author Thiago Rocha
*/
public static class Provider implements IQProvider {
public static class Provider extends IQProvider<STUN> {
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
@Override
public STUN parse(XmlPullParser parser, int initialDepth)
throws SmackException, XmlPullParserException,
IOException {
boolean done = false;
@ -133,7 +134,7 @@ public class STUN extends IQ {
String elementName;
if (!parser.getNamespace().equals(NAMESPACE))
throw new Exception("Not a STUN packet");
throw new SmackException("Not a STUN packet");
STUN iq = new STUN();

View file

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

View file

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

View file

@ -27,27 +27,14 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Alvaro Saurin
*/
public class JingleContentInfoProvider implements PacketExtensionProvider {
/**
* 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;
}
public class JingleContentInfoProvider {
/**
* 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.
@ -69,8 +56,8 @@ public class JingleContentInfoProvider implements PacketExtensionProvider {
/**
* Parse a JingleDescription.Audio extension.
*/
public PacketExtension parseExtension(final XmlPullParser parser)
throws Exception {
@Override
public PacketExtension parse(XmlPullParser parser, int initialDepth) {
PacketExtension result = null;
if (audioInfo != null) {

View file

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

View file

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

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