1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-13 00:21:07 +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

@ -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;
}