1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +01:00

Rework exceptions in the parsing / provider subsystem

This commit is contained in:
Florian Schmaus 2019-02-05 10:41:50 +01:00
parent 4c42d0cd32
commit 083dac8b83
130 changed files with 504 additions and 342 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus
* Copyright © 2009 Jonas Ådahl, 2011-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.caps.provider;
import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.caps.EntityCapsManager;
@ -30,8 +29,7 @@ import org.xmlpull.v1.XmlPullParserException;
public class CapsExtensionProvider extends ExtensionElementProvider<CapsExtension> {
@Override
public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
SmackException {
public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String hash, version, node;
if (parser.getEventType() == XmlPullParser.START_TAG
&& parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT)) {
@ -39,20 +37,23 @@ public class CapsExtensionProvider extends ExtensionElementProvider<CapsExtensio
version = parser.getAttributeValue(null, "ver");
node = parser.getAttributeValue(null, "node");
} else {
throw new SmackException("Malformed Caps element");
// TODO: Should be SmackParsingException.
throw new IOException("Malformed Caps element");
}
parser.next();
if (!(parser.getEventType() == XmlPullParser.END_TAG
&& parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT))) {
throw new SmackException("Malformed nested Caps element");
// TODO: Should be SmackParsingException.
throw new IOException("Malformed nested Caps element");
}
if (hash != null && version != null && node != null) {
return new CapsExtension(node, version, hash);
} else {
throw new SmackException("Caps element with missing attributes. Attributes: hash=" + hash + " version="
// TODO: Should be SmackParsingException.
throw new IOException("Caps element with missing attributes. Attributes: hash=" + hash + " version="
+ version + " node=" + node);
}
}