1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 02:39:42 +02: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 2017 Florian Schmaus.
* Copyright 2017-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.
@ -16,9 +16,13 @@
*/
package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smackx.ox.element.CryptElement;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link org.jivesoftware.smack.provider.ExtensionElementProvider} implementation for the {@link CryptElement}.
@ -28,8 +32,7 @@ public class CryptElementProvider extends OpenPgpContentElementProvider<CryptEle
public static final CryptElementProvider INSTANCE = new CryptElementProvider();
@Override
public CryptElement parse(XmlPullParser parser, int initialDepth)
throws Exception {
public CryptElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
return new CryptElement(data.to, data.rpad, data.timestamp, data.payload);

View file

@ -20,6 +20,7 @@ import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
@ -78,10 +79,10 @@ public abstract class OpenPgpContentElementProvider<O extends OpenPgpContentElem
}
@Override
public abstract O parse(XmlPullParser parser, int initialDepth) throws Exception;
public abstract O parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException;
protected static OpenPgpContentElementData parseOpenPgpContentElementData(XmlPullParser parser, int initialDepth)
throws Exception {
throws XmlPullParserException, IOException, ParseException {
Set<Jid> to = new HashSet<>();
Date timestamp = null;
String rpad = null;

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus.
* Copyright 2017-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.
@ -16,10 +16,13 @@
*/
package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.ox.element.OpenPgpElement;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link ExtensionElementProvider} implementation for the {@link OpenPgpElement}.
@ -29,7 +32,7 @@ public class OpenPgpElementProvider extends ExtensionElementProvider<OpenPgpElem
public static final OpenPgpElementProvider TEST_INSTANCE = new OpenPgpElementProvider();
@Override
public OpenPgpElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public OpenPgpElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String base64EncodedOpenPgpMessage = parser.nextText();
return new OpenPgpElement(base64EncodedOpenPgpMessage);
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2018 Paul Schaub.
* Copyright 2018-2019 Paul Schaub.
*
* 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,9 @@ package org.jivesoftware.smackx.ox.provider;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.Date;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
@ -26,6 +28,7 @@ import org.jivesoftware.smackx.ox.element.PubkeyElement;
import org.jxmpp.util.XmppDateTime;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link ExtensionElementProvider} implementation for the {@link PubkeyElement}.
@ -35,7 +38,7 @@ public class PubkeyElementProvider extends ExtensionElementProvider<PubkeyElemen
public static final PubkeyElementProvider TEST_INSTANCE = new PubkeyElementProvider();
@Override
public PubkeyElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public PubkeyElement parse(XmlPullParser parser, int initialDepth) throws ParseException, XmlPullParserException, IOException {
String dateString = parser.getAttributeValue(null, PubkeyElement.ATTR_DATE);
Date date = dateString != null ? XmppDateTime.parseXEP0082Date(dateString) : null;
while (true) {

View file

@ -19,6 +19,8 @@ package org.jivesoftware.smackx.ox.provider;
import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
@ -27,13 +29,14 @@ import org.jivesoftware.smackx.ox.element.PublicKeysListElement;
import org.jxmpp.util.XmppDateTime;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public final class PublicKeysListElementProvider extends ExtensionElementProvider<PublicKeysListElement> {
public static final PublicKeysListElementProvider TEST_INSTANCE = new PublicKeysListElementProvider();
@Override
public PublicKeysListElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public PublicKeysListElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
PublicKeysListElement.Builder builder = PublicKeysListElement.builder();

View file

@ -16,12 +16,14 @@
*/
package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import java.nio.charset.Charset;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.ox.element.SecretkeyElement;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link ExtensionElementProvider} implementation for the {@link SecretkeyElement}.
@ -31,7 +33,7 @@ public class SecretkeyElementProvider extends ExtensionElementProvider<Secretkey
public static final SecretkeyElementProvider TEST_INSTANCE = new SecretkeyElementProvider();
@Override
public SecretkeyElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public SecretkeyElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String data = parser.nextText();
return new SecretkeyElement(data.getBytes(Charset.forName("UTF-8")));
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus.
* Copyright 2017-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.
@ -16,12 +16,15 @@
*/
package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import java.text.ParseException;
import java.util.logging.Logger;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ox.element.SignElement;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link org.jivesoftware.smack.provider.ExtensionElementProvider} implementation for the {@link SignElement}.
@ -32,7 +35,7 @@ public class SignElementProvider extends OpenPgpContentElementProvider<SignEleme
public static final SignElementProvider INSTANCE = new SignElementProvider();
@Override
public SignElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public SignElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
if (StringUtils.isNotEmpty(data.rpad)) {

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus, 2018 Paul Schaub.
* Copyright 2017-2019 Florian Schmaus, 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,9 +16,13 @@
*/
package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import java.text.ParseException;
import org.jivesoftware.smackx.ox.element.SigncryptElement;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* {@link org.jivesoftware.smack.provider.ExtensionElementProvider} implementation for the {@link SigncryptElement}.
@ -28,7 +32,7 @@ public class SigncryptElementProvider extends OpenPgpContentElementProvider<Sign
public static final SigncryptElementProvider INSTANCE = new SigncryptElementProvider();
@Override
public SigncryptElement parse(XmlPullParser parser, int initialDepth) throws Exception {
public SigncryptElement parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth);
return new SigncryptElement(data.to, data.rpad, data.timestamp, data.payload);
}