Commit ced9012f authored by Grigory Fedorov's avatar Grigory Fedorov

Extension and IQ providers changed. At least avatars and v-cards work now. #502

parent 4ac97c37
......@@ -22,6 +22,9 @@ import android.os.Handler;
import com.xabber.android.R;
import com.xabber.android.service.XabberService;
import org.jivesoftware.smack.provider.ProviderFileLoader;
import org.jivesoftware.smack.provider.ProviderManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
......@@ -133,6 +136,8 @@ public class Application extends android.app.Application {
}
private void onLoad() {
ProviderManager.addLoader(new ProviderFileLoader(getResources().openRawResource(R.raw.smack)));
for (OnLoadListener listener : getManagers(OnLoadListener.class)) {
LogManager.i(listener, "onLoad");
listener.onLoad();
......
......@@ -97,7 +97,7 @@ public class ContactVcardViewerFragment extends Fragment implements OnVCardListe
if (!VCard.NAMESPACE.equals(parser.getNamespace())) {
throw new IllegalStateException(parser.getNamespace());
}
vCard = (VCard) (new VCardProvider()).parseIQ(parser);
vCard = (VCard) (new VCardProvider()).parse(parser);
} catch (Exception e) {
LogManager.exception(this, e);
}
......
......@@ -15,7 +15,11 @@
package com.xabber.xmpp;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Provides common interface to parse extensions.
......@@ -24,12 +28,105 @@ import org.xmlpull.v1.XmlPullParser;
* @author alexander.ivanov
*/
public abstract class AbstractExtensionProvider<Extension extends PacketExtension>
extends AbstractProvider<Extension>
// TODO
// implements PacketExtensionProvider
extends org.jivesoftware.smack.provider.ExtensionElementProvider<Extension>
{
public Extension parseExtension(XmlPullParser parser) throws Exception {
/**
* Creates an instance.
* <p/>
* Parser position mustn't be changed.
*
* @param parser
* @return
*/
abstract protected Extension createInstance(XmlPullParser parser);
/**
* Parse XML tag and create instance.
*
* @param parser an XML parser.
* @return new instance.
* @throws Exception if an error occurs while parsing.
*/
public Extension provideInstance(XmlPullParser parser) throws IOException, XmlPullParserException, SmackException {
Extension instance = createInstance(parser);
return parseTag(parser, instance);
}
/**
* Parse XML tag and populate element instance. At the beginning of the
* method call, the XML parser will be positioned on the opening tag. At the
* end of the method call, the parser <b>must</b> be positioned on the end
* of processed tag.
*
* @param parser an XML parser.
* @param instance instance to be updated.
* @return updated or replaced instance.
* @throws Exception if an error occurs parsing the XML.
*/
public Extension parseTag(XmlPullParser parser, Extension instance) throws IOException, XmlPullParserException, SmackException {
String name = parser.getName();
instance = preProcess(parser, instance);
while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (!parseInner(parser, instance))
ProviderUtils.skipTag(parser);
} else if (eventType == XmlPullParser.END_TAG) {
if (name.equals(parser.getName()))
break;
else
throw new IllegalStateException();
} else if (eventType == XmlPullParser.END_DOCUMENT)
break;
}
return postProcess(instance);
}
/**
* Updates instance from tag name or attributes.
* <p/>
* Parser position mustn't be changed.
*
* @param instance
* @param parser
* @return modified instance.
*/
protected Extension preProcess(XmlPullParser parser, Extension instance) {
return instance;
}
/**
* Called when packet have been fully parsed.
* <p/>
* Parser position mustn't be changed.
*
* @param instance
* @return modified instance.
*/
protected Extension postProcess(Extension instance) {
return instance;
}
/**
* Parses inner tag.
* <p/>
* Parser position either <b>must</b> be move to the end of processed tag,
* either <b>mustn't</b> be changed at all.
*
* @param parser
* @param instance
* @return Whether parser position have been changed.
* @throws Exception
*/
protected boolean parseInner(XmlPullParser parser, Extension instance) throws XmlPullParserException, IOException, SmackException {
return false;
}
@Override
public Extension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
return provideInstance(parser);
}
......
......@@ -14,22 +14,117 @@
*/
package com.xabber.xmpp;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Provides common interface to parse iq packets.
*
* @param <T>
* @author alexander.ivanov
*/
// TODO
public abstract class AbstractIQProvider<T extends IQ> extends AbstractProvider<T>
//implements IQProvider
{
public abstract class AbstractIQProvider<Extension extends IQ> extends IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
return provideInstance(parser);
/**
* Creates an instance.
* <p/>
* Parser position mustn't be changed.
*
* @param parser
* @return
*/
abstract protected Extension createInstance(XmlPullParser parser);
/**
* Parse XML tag and create instance.
*
* @param parser an XML parser.
* @return new instance.
* @throws Exception if an error occurs while parsing.
*/
public Extension provideInstance(XmlPullParser parser) throws IOException, XmlPullParserException, SmackException {
Extension instance = createInstance(parser);
return parseTag(parser, instance);
}
/**
* Parse XML tag and populate element instance. At the beginning of the
* method call, the XML parser will be positioned on the opening tag. At the
* end of the method call, the parser <b>must</b> be positioned on the end
* of processed tag.
*
* @param parser an XML parser.
* @param instance instance to be updated.
* @return updated or replaced instance.
* @throws Exception if an error occurs parsing the XML.
*/
public Extension parseTag(XmlPullParser parser, Extension instance) throws IOException, XmlPullParserException, SmackException {
String name = parser.getName();
instance = preProcess(parser, instance);
while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (!parseInner(parser, instance))
ProviderUtils.skipTag(parser);
} else if (eventType == XmlPullParser.END_TAG) {
if (name.equals(parser.getName()))
break;
else
throw new IllegalStateException();
} else if (eventType == XmlPullParser.END_DOCUMENT)
break;
}
return postProcess(instance);
}
/**
* Updates instance from tag name or attributes.
* <p/>
* Parser position mustn't be changed.
*
* @param instance
* @param parser
* @return modified instance.
*/
protected Extension preProcess(XmlPullParser parser, Extension instance) {
return instance;
}
/**
* Called when packet have been fully parsed.
* <p/>
* Parser position mustn't be changed.
*
* @param instance
* @return modified instance.
*/
protected Extension postProcess(Extension instance) {
return instance;
}
/**
* Parses inner tag.
* <p/>
* Parser position either <b>must</b> be move to the end of processed tag,
* either <b>mustn't</b> be changed at all.
*
* @param parser
* @param instance
* @return Whether parser position have been changed.
* @throws Exception
*/
protected boolean parseInner(XmlPullParser parser, Extension instance) throws XmlPullParserException, IOException, SmackException {
return false;
}
@Override
public Element parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
return provideInstance(parser);
}
}
......@@ -15,6 +15,9 @@
package com.xabber.xmpp;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Provide common interface to populate java object from received xml.
......@@ -45,7 +48,7 @@ public abstract class AbstractInflater<T extends Instance> {
* @param instance
* @return modified instance.
*/
protected T postProcess(T instance) throws Exception {
protected T postProcess(T instance) {
return instance;
}
......@@ -60,8 +63,7 @@ public abstract class AbstractInflater<T extends Instance> {
* @return Whether parser position have been changed.
* @throws Exception
*/
protected boolean parseInner(XmlPullParser parser, T instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, T instance) throws IOException, XmlPullParserException {
return false;
}
......@@ -76,7 +78,7 @@ public abstract class AbstractInflater<T extends Instance> {
* @return updated or replaced instance.
* @throws Exception if an error occurs parsing the XML.
*/
public T parseTag(XmlPullParser parser, T instance) throws Exception {
public T parseTag(XmlPullParser parser, T instance) throws IOException, XmlPullParserException {
String name = parser.getName();
instance = preProcess(parser, instance);
while (true) {
......
......@@ -15,6 +15,9 @@
package com.xabber.xmpp;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Provide common interface to create new object from received XML.
......@@ -42,7 +45,7 @@ public abstract class AbstractProvider<T extends Instance> extends
* @return new instance.
* @throws Exception if an error occurs while parsing.
*/
public T provideInstance(XmlPullParser parser) throws Exception {
public T provideInstance(XmlPullParser parser) throws IOException, XmlPullParserException {
T instance = createInstance(parser);
return parseTag(parser, instance);
}
......
......@@ -14,6 +14,13 @@
*/
package com.xabber.xmpp;
import com.xabber.android.data.LogManager;
import org.jxmpp.util.XmppDateTime;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
......@@ -24,12 +31,6 @@ import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jivesoftware.smack.util.StringUtils;
import org.jxmpp.util.XmppDateTime;
import org.xmlpull.v1.XmlPullParser;
import com.xabber.android.data.LogManager;
/**
* Set of functions commonly used by packet providers.
*
......@@ -117,7 +118,7 @@ public class ProviderUtils {
* @return Empty string if there is no inner text elements.
* @throws Exception
*/
public static String parseText(XmlPullParser parser) throws Exception {
public static String parseText(XmlPullParser parser) throws IOException, XmlPullParserException {
return parseText(parser, -1);
}
......@@ -132,8 +133,7 @@ public class ProviderUtils {
* position will be at the and of the tag.
* @throws Exception
*/
public static String parseText(XmlPullParser parser, int maximum)
throws Exception {
public static String parseText(XmlPullParser parser, int maximum) throws IOException, XmlPullParserException {
final StringBuilder text = new StringBuilder();
int inner = 1;
boolean overflow = false;
......@@ -168,7 +168,7 @@ public class ProviderUtils {
break;
}
if (overflow)
throw new OverflowReceiverBufferException();
throw new IOException("Overflow");
return text.toString();
}
......@@ -179,8 +179,7 @@ public class ProviderUtils {
* @throws IllegalStateException If closed tags are incompatible with opened one.
* @throws Exception
*/
public static void skipTag(XmlPullParser parser)
throws Exception {
public static void skipTag(XmlPullParser parser) throws IOException, XmlPullParserException {
LinkedList<String> tags = new LinkedList<String>();
tags.add(parser.getName());
while (!tags.isEmpty()) {
......@@ -220,7 +219,7 @@ public class ProviderUtils {
* data.
* @throws Exception
*/
public static Integer parseInteger(XmlPullParser parser) throws Exception {
public static Integer parseInteger(XmlPullParser parser) throws IOException, XmlPullParserException {
return parseInteger(parseText(parser, -1));
}
......@@ -232,7 +231,7 @@ public class ProviderUtils {
* data.
* @throws Exception
*/
public static Integer parseBoolean(XmlPullParser parser) throws Exception {
public static Integer parseBoolean(XmlPullParser parser) throws IOException, XmlPullParserException {
return parseInteger(parseText(parser, -1));
}
......@@ -244,7 +243,7 @@ public class ProviderUtils {
* data.
* @throws Exception
*/
public static Date parseDateTime(XmlPullParser parser) throws Exception {
public static Date parseDateTime(XmlPullParser parser) throws IOException, XmlPullParserException {
return parseDateTime(parseText(parser, -1));
}
......
......@@ -15,10 +15,13 @@
package com.xabber.xmpp.archive;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public abstract class AbstractMessageProvider<T extends AbstractMessage>
extends AbstractProvider<T> {
......@@ -36,8 +39,7 @@ public abstract class AbstractMessageProvider<T extends AbstractMessage>
}
@Override
protected boolean parseInner(XmlPullParser parser, T instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, T instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -18,9 +18,13 @@ import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
import com.xabber.xmpp.rsm.Set;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class ChatProvider extends AbstractIQProvider<Chat>
//TODO
......@@ -55,8 +59,7 @@ public class ChatProvider extends AbstractIQProvider<Chat>
}
@Override
protected boolean parseInner(XmlPullParser parser, Chat instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Chat instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -18,9 +18,13 @@ import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
import com.xabber.xmpp.rsm.Set;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class ListProvider extends AbstractIQProvider<List> {
......@@ -43,8 +47,7 @@ public class ListProvider extends AbstractIQProvider<List> {
}
@Override
protected boolean parseInner(XmlPullParser parser, List instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, List instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -18,9 +18,13 @@ import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
import com.xabber.xmpp.rsm.Set;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class ModifiedProvider extends AbstractIQProvider<Modified> {
......@@ -37,8 +41,7 @@ public class ModifiedProvider extends AbstractIQProvider<Modified> {
}
@Override
protected boolean parseInner(XmlPullParser parser, Modified instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Modified instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -14,9 +14,12 @@
*/
package com.xabber.xmpp.archive;
import java.io.IOException;
import java.util.NoSuchElementException;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
......@@ -24,8 +27,7 @@ import com.xabber.xmpp.ProviderUtils;
public class PrefProvider extends AbstractIQProvider<Pref> {
@Override
protected boolean parseInner(XmlPullParser parser, Pref instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Pref instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -14,11 +14,15 @@
*/
package com.xabber.xmpp.avatar;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractExtensionProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public class VCardUpdateProvider extends AbstractExtensionProvider<VCardUpdate> {
@Override
......@@ -27,8 +31,7 @@ public class VCardUpdateProvider extends AbstractExtensionProvider<VCardUpdate>
}
@Override
protected boolean parseInner(XmlPullParser parser, VCardUpdate instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, VCardUpdate instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -2,11 +2,15 @@ package com.xabber.xmpp.carbon;
import com.xabber.xmpp.AbstractExtensionProvider;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.jivesoftware.smackx.delay.provider.DelayInformationProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Packet extension for XEP-0297: Stanza Forwarding. This class implements
......@@ -29,9 +33,9 @@ public class ForwardedProvider extends AbstractExtensionProvider<Forwarded> {
return new Forwarded(null, null);
}
@Override
public Forwarded parseExtension(XmlPullParser parser) throws Exception {
public Forwarded parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
DelayInformationProvider delayInformationProvider = new DelayInformationProvider();
DelayInformation delayInformation = null;
Stanza packet = null;
......@@ -44,13 +48,13 @@ public class ForwardedProvider extends AbstractExtensionProvider<Forwarded> {
delayInformation = delayInformationProvider.parse(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_NAME))
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(delayInformation, packet);
}
}
......@@ -22,8 +22,7 @@ public class ReceivedProvider extends AbstractExtensionProvider<Received> {
}
@Override
protected boolean parseInner(XmlPullParser parser, Received instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Received instance) {
Forwarded forwarded = null;
if (parser.getName().equals(Forwarded.ELEMENT_NAME)) {
......
......@@ -23,8 +23,7 @@ public class SentProvider extends AbstractExtensionProvider<Sent> {
}
@Override
protected boolean parseInner(XmlPullParser parser, Sent instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Sent instance) {
Forwarded forwarded = null;
......
......@@ -14,11 +14,15 @@
*/
package com.xabber.xmpp.rsm;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractExtensionProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public class SetProvider extends AbstractExtensionProvider<Set> {
@Override
......@@ -27,8 +31,7 @@ public class SetProvider extends AbstractExtensionProvider<Set> {
}
@Override
protected boolean parseInner(XmlPullParser parser, Set instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Set instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
if (Set.AFTER_NAME.equals(parser.getName()))
......
......@@ -16,10 +16,14 @@ package com.xabber.xmpp.ssn;
import com.xabber.xmpp.AbstractExtensionProvider;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class FeatureProvider extends AbstractExtensionProvider<Feature> {
......@@ -29,8 +33,7 @@ public class FeatureProvider extends AbstractExtensionProvider<Feature> {
}
@Override
protected boolean parseInner(XmlPullParser parser, Feature instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Feature instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
if (DataForm.ELEMENT.equals(parser.getName())
......
......@@ -14,10 +14,13 @@
*/
package com.xabber.xmpp.time;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
......@@ -28,8 +31,7 @@ public class TimeProvider extends AbstractIQProvider<Time> {
"^([+-])(\\d{2}):(\\d{2})$|^(Z)$", Pattern.CASE_INSENSITIVE);
@Override
protected boolean parseInner(XmlPullParser parser, Time instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Time instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -14,20 +14,21 @@
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.Instance;
import com.xabber.xmpp.OverflowReceiverBufferException;
import com.xabber.xmpp.ProviderUtils;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder<T>>
extends AbstractProvider<Inner> {
@Override
protected boolean parseInner(XmlPullParser parser, Inner instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Inner instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (instance.getPayload() == null)
......@@ -36,8 +37,7 @@ abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder
return inflatePayload(parser, instance);
}
protected boolean createPayload(XmlPullParser parser, Inner instance)
throws Exception {
protected boolean createPayload(XmlPullParser parser, Inner instance) {
if (AbstractBinaryData.TYPE_NAME.equals(parser.getName())
|| AbstractBinaryData.BINVAL_NAME.equals(parser.getName()))
instance.setPayload(createBinaryData());
......@@ -52,8 +52,7 @@ abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder
protected abstract T createExternalData();
protected boolean inflatePayload(XmlPullParser parser, Inner instance)
throws Exception {
protected boolean inflatePayload(XmlPullParser parser, Inner instance) throws IOException, XmlPullParserException {
if (instance.getPayload() instanceof AbstractBinaryData)
return inflateBinaryData(parser,
(AbstractBinaryData) instance.getPayload());
......@@ -64,8 +63,7 @@ abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder
return false;
}
protected boolean inflateBinaryData(XmlPullParser parser,
AbstractBinaryData payload) throws Exception {
protected boolean inflateBinaryData(XmlPullParser parser, AbstractBinaryData payload) throws IOException, XmlPullParserException {
if (AbstractBinaryData.TYPE_NAME.equals(parser.getName()))
payload.setType(ProviderUtils.parseText(parser));
else if (AbstractBinaryData.BINVAL_NAME.equals(parser.getName())) {
......@@ -73,7 +71,7 @@ abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder
try {
value = ProviderUtils.parseText(parser,
AbstractBinaryData.MAX_ENCODED_DATA_SIZE);
} catch (OverflowReceiverBufferException e) {
} catch (Exception e) {
return true;
}
payload.setData(Base64.decode(value));
......@@ -82,8 +80,7 @@ abstract class AbstractDataProvider<T extends Instance, Inner extends DataHolder
return true;
}
protected boolean inflateExternalData(XmlPullParser parser,
AbstractExternalData payload) throws Exception {
protected boolean inflateExternalData(XmlPullParser parser, AbstractExternalData payload) throws IOException, XmlPullParserException {
if (AbstractExternalData.EXTVAL_NAME.equals(parser.getName()))
payload.setValue(ProviderUtils.parseText(parser));
else
......
......@@ -15,16 +15,18 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
abstract class AbstractTypedDataProvider<Type extends Enum<?>, Instance extends AbstractTypedData<Type>>
extends AbstractProvider<Instance> {
@Override
protected boolean parseInner(XmlPullParser parser, Instance instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Instance instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public abstract class AbstractTypedDataWithValueProvider<Type extends Enum<?>, Instance extends AbstractTypedDataWithValue<Type>>
extends AbstractTypedDataProvider<Type, Instance> {
@Override
protected boolean parseInner(XmlPullParser parser, Instance instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Instance instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (getValueName().equals(parser.getName())) {
......
......@@ -15,14 +15,16 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class AddressProvider extends AbstractTypedDataProvider<AddressType, Address> {
@Override
protected boolean parseInner(XmlPullParser parser, Address instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Address instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class CategoriesInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (VCard.KEYWORD_NAME.equals(parser.getName()))
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class ClassificationInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class GeoProvider extends AbstractProvider<Geo> {
@Override
protected boolean parseInner(XmlPullParser parser, Geo instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Geo instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Geo.LAT_NAME.equals(parser.getName()))
......
......@@ -14,17 +14,18 @@
*/
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.OverflowReceiverBufferException;
import com.xabber.xmpp.ProviderUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
class KeyProvider extends AbstractProvider<Key> {
@Override
protected boolean parseInner(XmlPullParser parser, Key instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Key instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Key.TYPE_NAME.equals(parser.getName()))
......@@ -34,7 +35,7 @@ class KeyProvider extends AbstractProvider<Key> {
try {
value = ProviderUtils.parseText(parser,
Key.MAX_ENCODED_DATA_SIZE);
} catch (OverflowReceiverBufferException e) {
} catch (Exception e) {
return true;
}
instance.setEncodedData(value);
......
......@@ -15,14 +15,16 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class LabelProvider extends AbstractTypedDataProvider<AddressType, Label> {
@Override
protected boolean parseInner(XmlPullParser parser, Label instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Label instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Label.LINE_NAME.equals(parser.getName())) {
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractInflater;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class NameInflater extends AbstractInflater<VCard> {
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, VCard instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class OrganizationProvider extends AbstractProvider<Organization> {
@Override
protected boolean parseInner(XmlPullParser parser, Organization instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, Organization instance) throws IOException, XmlPullParserException {
if (super.parseInner(parser, instance))
return true;
if (Organization.ORGNAME_NAME.equals(parser.getName()))
......
......@@ -15,15 +15,17 @@
package com.xabber.xmpp.vcard;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
class SoundHolderProvider extends
AbstractDataProvider<Sound, DataHolder<Sound>> {
@Override
protected boolean createPayload(XmlPullParser parser,
DataHolder<Sound> instance) throws Exception {
protected boolean createPayload(XmlPullParser parser, DataHolder<Sound> instance) {
if (super.createPayload(parser, instance))
return true;
if (PhoneticSound.PHONETIC_NAME.equals(parser.getName()))
......@@ -48,8 +50,7 @@ class SoundHolderProvider extends
}
@Override
protected boolean inflatePayload(XmlPullParser parser,
DataHolder<Sound> instance) throws Exception {
protected boolean inflatePayload(XmlPullParser parser, DataHolder<Sound> instance) throws IOException, XmlPullParserException {
if (super.inflatePayload(parser, instance))
return true;
if (instance.getPayload() instanceof PhoneticSound)
......@@ -59,8 +60,7 @@ class SoundHolderProvider extends
return false;
}
protected boolean inflatePhoneticSound(XmlPullParser parser,
PhoneticSound payload) throws Exception {
protected boolean inflatePhoneticSound(XmlPullParser parser, PhoneticSound payload) throws IOException, XmlPullParserException {
if (PhoneticSound.PHONETIC_NAME.equals(parser.getName()))
payload.setValue(ProviderUtils.parseText(parser));
else
......
......@@ -14,11 +14,15 @@
*/
package com.xabber.xmpp.vcard;
import org.jivesoftware.smack.SmackException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.xabber.xmpp.AbstractIQProvider;
import com.xabber.xmpp.ProviderUtils;
import java.io.IOException;
public class VCardProvider extends AbstractIQProvider<VCard> {
@Override
......@@ -27,8 +31,7 @@ public class VCardProvider extends AbstractIQProvider<VCard> {
}
@Override
protected boolean parseInner(XmlPullParser parser, VCard instance)
throws Exception {
protected boolean parseInner(XmlPullParser parser, VCard instance) throws XmlPullParserException, IOException, SmackException {
if (super.parseInner(parser, instance))
return true;
String name = parser.getName();
......
<?xml version="1.0"?>
<!-- Providers file for default Smack extensions -->
<smackProviders>
<!-- Message Events -->
<extensionProvider>
<elementName>x</elementName>
<namespace>jabber:x:event</namespace>
<className>org.jivesoftware.smackx.provider.MessageEventProvider</className>
</extensionProvider>
<!-- Chat State -->
<extensionProvider>
<elementName>active</elementName>
<namespace>http://jabber.org/protocol/chatstates</namespace>
<className>org.jivesoftware.smackx.packet.ChatStateExtension$Provider</className>
</extensionProvider>
<extensionProvider>
<elementName>composing</elementName>
<namespace>http://jabber.org/protocol/chatstates</namespace>
<className>org.jivesoftware.smackx.packet.ChatStateExtension$Provider</className>
</extensionProvider>
<extensionProvider>
<elementName>paused</elementName>
<namespace>http://jabber.org/protocol/chatstates</namespace>
<className>org.jivesoftware.smackx.packet.ChatStateExtension$Provider</className>
</extensionProvider>
<extensionProvider>
<elementName>inactive</elementName>
<namespace>http://jabber.org/protocol/chatstates</namespace>
<className>org.jivesoftware.smackx.packet.ChatStateExtension$Provider</className>
</extensionProvider>
<extensionProvider>
<elementName>gone</elementName>
<namespace>http://jabber.org/protocol/chatstates</namespace>
<className>org.jivesoftware.smackx.packet.ChatStateExtension$Provider</className>
</extensionProvider>
<!-- Service Discovery # Items -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/disco#items</namespace>
<className>org.jivesoftware.smackx.provider.DiscoverItemsProvider</className>
</iqProvider>
<!-- Service Discovery # Info -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/disco#info</namespace>
<className>org.jivesoftware.smackx.provider.DiscoverInfoProvider</className>
</iqProvider>
<!-- Data Forms-->
<extensionProvider>
<elementName>x</elementName>
<namespace>jabber:x:data</namespace>
<className>org.jivesoftware.smackx.provider.DataFormProvider</className>
</extensionProvider>
<!-- MUC User -->
<extensionProvider>
<elementName>x</elementName>
<namespace>http://jabber.org/protocol/muc#user</namespace>
<className>org.jivesoftware.smackx.provider.MUCUserProvider</className>
</extensionProvider>
<!-- MUC Admin -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/muc#admin</namespace>
<className>org.jivesoftware.smackx.provider.MUCAdminProvider</className>
</iqProvider>
<!-- MUC Owner -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/muc#owner</namespace>
<className>org.jivesoftware.smackx.provider.MUCOwnerProvider</className>
</iqProvider>
<!-- Delayed Delivery -->
<extensionProvider>
<elementName>x</elementName>
<namespace>jabber:x:delay</namespace>
<className>org.jivesoftware.smackx.provider.DelayInformationProvider</className>
</extensionProvider>
<extensionProvider>
<elementName>delay</elementName>
<namespace>urn:xmpp:delay</namespace>
<className>org.jivesoftware.smackx.provider.DelayInfoProvider</className>
</extensionProvider>
<!-- VCard -->
<iqProvider>
......@@ -102,78 +9,6 @@
<className>com.xabber.xmpp.vcard.VCardProvider</className>
</iqProvider>
<!-- Offline Message Requests -->
<iqProvider>
<elementName>offline</elementName>
<namespace>http://jabber.org/protocol/offline</namespace>
<className>org.jivesoftware.smackx.packet.OfflineMessageRequest$Provider</className>
</iqProvider>
<!-- Offline Message Indicator -->
<extensionProvider>
<elementName>offline</elementName>
<namespace>http://jabber.org/protocol/offline</namespace>
<className>org.jivesoftware.smackx.packet.OfflineMessageInfo$Provider</className>
</extensionProvider>
<!-- User Search -->
<iqProvider>
<elementName>query</elementName>
<namespace>jabber:iq:search</namespace>
<className>org.jivesoftware.smackx.search.UserSearch$Provider</className>
</iqProvider>
<!-- FileTransfer -->
<iqProvider>
<elementName>si</elementName>
<namespace>http://jabber.org/protocol/si</namespace>
<className>org.jivesoftware.smackx.provider.StreamInitiationProvider</className>
</iqProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/bytestreams</namespace>
<className>org.jivesoftware.smackx.bytestreams.socks5.provider.BytestreamsProvider</className>
</iqProvider>
<iqProvider>
<elementName>open</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.OpenIQProvider</className>
</iqProvider>
<iqProvider>
<elementName>data</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider</className>
</iqProvider>
<iqProvider>
<elementName>close</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.CloseIQProvider</className>
</iqProvider>
<extensionProvider>
<elementName>data</elementName>
<namespace>http://jabber.org/protocol/ibb</namespace>
<className>org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider</className>
</extensionProvider>
<!-- Privacy -->
<iqProvider>
<elementName>query</elementName>
<namespace>jabber:iq:privacy</namespace>
<className>org.jivesoftware.smack.provider.PrivacyProvider</className>
</iqProvider>
<!-- Ping -->
<iqProvider>
<elementName>ping</elementName>
<namespace>urn:xmpp:ping</namespace>
<className>org.jivesoftware.smackx.packet.Ping</className>
</iqProvider>
<!-- vCardUpdate -->
<extensionProvider>
<elementName>x</elementName>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment