mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 02:39:42 +02:00
Introduce SmackParsingException
This commit is contained in:
parent
163ca2b009
commit
7dee3b88a2
54 changed files with 277 additions and 155 deletions
|
@ -33,7 +33,6 @@ import java.security.SecureRandom;
|
|||
import java.security.Security;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -106,6 +105,7 @@ import org.jivesoftware.smack.packet.StreamError;
|
|||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.packet.TopLevelStreamElement;
|
||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.NonzaProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
|
@ -1167,7 +1167,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
return successNonza;
|
||||
}
|
||||
|
||||
protected final void parseAndProcessNonza(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException {
|
||||
protected final void parseAndProcessNonza(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
final String element = parser.getName();
|
||||
final String namespace = parser.getNamespace();
|
||||
final String key = XmppStringUtils.generateKey(element, namespace);
|
||||
|
@ -1567,7 +1567,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
return this.fromMode;
|
||||
}
|
||||
|
||||
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
streamFeatures.clear();
|
||||
final int initialDepth = parser.getDepth();
|
||||
while (true) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Florian Schmaus
|
||||
* Copyright 2018-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.
|
||||
|
@ -17,12 +17,12 @@
|
|||
package org.jivesoftware.smack.compress.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.compress.packet.Failure;
|
||||
import org.jivesoftware.smack.packet.StanzaError;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.NonzaProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
||||
|
@ -39,7 +39,7 @@ public final class FailureProvider extends NonzaProvider<Failure> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Failure parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
|
||||
public Failure parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
Failure.CompressFailureError compressFailureError = null;
|
||||
StanzaError stanzaError = null;
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smack.fsm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -51,6 +50,7 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.StreamError;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.sasl.SASLErrorException;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge;
|
||||
|
@ -304,7 +304,7 @@ public abstract class AbstractXmppStateMachineConnection extends AbstractXMPPCon
|
|||
}
|
||||
|
||||
protected final void parseAndProcessElement(String element) throws XmlPullParserException, IOException,
|
||||
InterruptedException, StreamErrorException, SmackException, ParseException {
|
||||
InterruptedException, StreamErrorException, SmackException, SmackParsingException {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(element);
|
||||
|
||||
// Skip the enclosing stream open what is guaranteed to be there.
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.parsing;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
|
||||
public class SmackParsingException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected SmackParsingException(Exception exception) {
|
||||
super(exception);
|
||||
}
|
||||
|
||||
public static class SmackTextParseException extends SmackParsingException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SmackTextParseException(ParseException parsingException) {
|
||||
super(parsingException);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SmackUriSyntaxParsingException extends SmackParsingException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SmackUriSyntaxParsingException(URISyntaxException uriSyntaxException) {
|
||||
super(uriSyntaxException);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,13 +17,13 @@
|
|||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -85,7 +85,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
|
||||
|
||||
@Override
|
||||
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException {
|
||||
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final String namespace = parser.getNamespace();
|
||||
final String name = parser.getName();
|
||||
final int attributeCount = parser.getAttributeCount();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014-2018 Florian Schmaus
|
||||
* Copyright © 2014-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.
|
||||
|
@ -20,9 +20,9 @@ package org.jivesoftware.smack.provider;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -61,7 +61,7 @@ public abstract class Provider<E extends Element> {
|
|||
return elementClass;
|
||||
}
|
||||
|
||||
public final E parse(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException {
|
||||
public final E parse(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
// XPP3 calling convention assert: Parser should be at start tag
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
|
||||
|
@ -73,5 +73,5 @@ public abstract class Provider<E extends Element> {
|
|||
return e;
|
||||
}
|
||||
|
||||
public abstract E parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, ParseException;
|
||||
public abstract E parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackParsingException;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
* Copyright 2003-2007 Jive Software, 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.
|
||||
|
@ -19,7 +19,6 @@ package org.jivesoftware.smack.util;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -43,6 +42,7 @@ import org.jivesoftware.smack.packet.StanzaError;
|
|||
import org.jivesoftware.smack.packet.StartTls;
|
||||
import org.jivesoftware.smack.packet.StreamError;
|
||||
import org.jivesoftware.smack.packet.UnparsedIQ;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
|
@ -218,9 +218,9 @@ public class PacketParserUtils {
|
|||
* @return a Message packet.
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
* @throws SmackParsingException
|
||||
*/
|
||||
public static Message parseMessage(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
public static Message parseMessage(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
assert (parser.getName().equals(Message.ELEMENT));
|
||||
|
||||
|
@ -504,9 +504,9 @@ public class PacketParserUtils {
|
|||
* @return a Presence packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws ParseException
|
||||
* @throws SmackParsingException
|
||||
*/
|
||||
public static Presence parsePresence(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
public static Presence parsePresence(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final int initialDepth = parser.getDepth();
|
||||
|
||||
|
@ -791,9 +791,9 @@ public class PacketParserUtils {
|
|||
* @return an stream error packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws ParseException
|
||||
* @throws SmackParsingException
|
||||
*/
|
||||
public static StreamError parseStreamError(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
public static StreamError parseStreamError(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final int initialDepth = parser.getDepth();
|
||||
List<ExtensionElement> extensions = new ArrayList<>();
|
||||
Map<String, String> descriptiveTexts = null;
|
||||
|
@ -843,9 +843,9 @@ public class PacketParserUtils {
|
|||
* @return an error sub-packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws ParseException
|
||||
* @throws SmackParsingException
|
||||
*/
|
||||
public static StanzaError.Builder parseError(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
public static StanzaError.Builder parseError(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final int initialDepth = parser.getDepth();
|
||||
Map<String, String> descriptiveTexts = null;
|
||||
List<ExtensionElement> extensions = new ArrayList<>();
|
||||
|
@ -916,10 +916,10 @@ public class PacketParserUtils {
|
|||
* @return an extension element.
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
* @throws ParseException
|
||||
* @throws SmackParsingException
|
||||
*/
|
||||
public static ExtensionElement parseExtensionElement(String elementName, String namespace,
|
||||
XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
// See if a provider is registered to handle the extension.
|
||||
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||
|
@ -988,24 +988,24 @@ public class PacketParserUtils {
|
|||
}
|
||||
|
||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, ParseException {
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
addExtensionElement(packet, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
|
||||
String namespace) throws XmlPullParserException, IOException, ParseException {
|
||||
String namespace) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
||||
packet.addExtension(packetExtension);
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, ParseException {
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser,
|
||||
String elementName, String namespace) throws XmlPullParserException, IOException, ParseException {
|
||||
String elementName, String namespace) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
||||
collection.add(packetExtension);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014-2018 Florian Schmaus
|
||||
* Copyright © 2014-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.
|
||||
|
@ -26,6 +26,10 @@ import java.util.Locale;
|
|||
import javax.xml.XMLConstants;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.EntityFullJid;
|
||||
import org.jxmpp.jid.EntityJid;
|
||||
|
@ -261,19 +265,41 @@ public class ParserUtils {
|
|||
return s;
|
||||
}
|
||||
|
||||
public static Date getDateFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
String dateString = parser.nextText();
|
||||
return XmppDateTime.parseDate(dateString);
|
||||
public static Date getDateFromOptionalXep82String(String dateString) throws SmackTextParseException {
|
||||
if (dateString == null) {
|
||||
return null;
|
||||
}
|
||||
return getDateFromXep82String(dateString);
|
||||
}
|
||||
|
||||
public static URI getUriFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
public static Date getDateFromXep82String(String dateString) throws SmackTextParseException {
|
||||
try {
|
||||
return XmppDateTime.parseXEP0082Date(dateString);
|
||||
} catch (ParseException e) {
|
||||
throw new SmackParsingException.SmackTextParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Date getDateFromString(String dateString) throws SmackTextParseException {
|
||||
try {
|
||||
return XmppDateTime.parseDate(dateString);
|
||||
} catch (ParseException e) {
|
||||
throw new SmackParsingException.SmackTextParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Date getDateFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException, SmackTextParseException {
|
||||
String dateString = parser.nextText();
|
||||
return getDateFromString(dateString);
|
||||
}
|
||||
|
||||
public static URI getUriFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException, SmackUriSyntaxParsingException {
|
||||
String uriString = parser.nextText();
|
||||
try {
|
||||
return new URI(uriString);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
// TODO: Should be SmackParseException (or subclass of).
|
||||
throw new IOException(e);
|
||||
throw new SmackParsingException.SmackUriSyntaxParsingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue