1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02:00

Bump ErrorProne to 2.5.1 and refactor Providers a bit

This also resulted in a refactoring of the Providers and parsing
Exceptions. NumberFormatException and ParseException can now be thrown
directly, the wrapping in a SmackParsingException is down at a higher
layer, i.e. in AbstractProvider.
This commit is contained in:
Florian Schmaus 2021-01-28 22:05:47 +01:00
parent 1df0763f92
commit a7b3303f3e
136 changed files with 574 additions and 551 deletions

View file

@ -73,18 +73,10 @@ public class OfferConfirmation extends SimpleIQ {
parser.next();
String elementName = parser.getName();
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "user-jid".equals(elementName)) {
try {
confirmation.setUserJID(parser.nextText());
}
catch (NumberFormatException nfe) {
}
confirmation.setUserJID(parser.nextText());
}
else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "session-id".equals(elementName)) {
try {
confirmation.setSessionID(Long.valueOf(parser.nextText()));
}
catch (NumberFormatException nfe) {
}
confirmation.setSessionID(Long.valueOf(parser.nextText()));
}
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "offer-confirmation".equals(elementName)) {
done = true;

View file

@ -238,7 +238,8 @@ public class AgentStatus implements ExtensionElement {
public static class Provider extends ExtensionElementProvider<AgentStatus> {
@Override
public AgentStatus parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
public AgentStatus parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, ParseException {
AgentStatus agentStatus = new AgentStatus();
agentStatus.workgroupJID = ParserUtils.getBareJidAttribute(parser);
@ -249,7 +250,8 @@ public class AgentStatus implements ExtensionElement {
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if ("chat".equals(parser.getName())) {
agentStatus.currentChats.add(parseChatInfo(parser));
ChatInfo chatInfo = parseChatInfo(parser);
agentStatus.currentChats.add(chatInfo);
}
else if ("max-chats".equals(parser.getName())) {
agentStatus.maxChats = Integer.parseInt(parser.nextText());
@ -263,17 +265,13 @@ public class AgentStatus implements ExtensionElement {
return agentStatus;
}
private static ChatInfo parseChatInfo(XmlPullParser parser) {
private static ChatInfo parseChatInfo(XmlPullParser parser) throws ParseException {
String sessionID = parser.getAttributeValue("", "sessionID");
String userID = parser.getAttributeValue("", "userID");
Date date = null;
try {
synchronized (UTC_FORMAT) {
date = UTC_FORMAT.parse(parser.getAttributeValue("", "startTime"));
}
}
catch (ParseException e) {
synchronized (UTC_FORMAT) {
date = UTC_FORMAT.parse(parser.getAttributeValue("", "startTime"));
}
String email = parser.getAttributeValue("", "email");

View file

@ -28,8 +28,6 @@ import java.util.TimeZone;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -137,7 +135,8 @@ public class OccupantsInfo extends IQ {
public static class Provider extends IQProvider<OccupantsInfo> {
@Override
public OccupantsInfo parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackTextParseException {
public OccupantsInfo parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, ParseException {
OccupantsInfo occupantsInfo = new OccupantsInfo(parser.getAttributeValue("", "roomID"));
boolean done = false;
@ -155,7 +154,7 @@ public class OccupantsInfo extends IQ {
}
private static OccupantInfo parseOccupantInfo(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackTextParseException {
throws XmlPullParserException, IOException, ParseException {
boolean done = false;
String jid = null;
String nickname = null;
@ -170,11 +169,7 @@ public class OccupantsInfo extends IQ {
} else if (eventType == XmlPullParser.Event.START_ELEMENT &&
"joined".equals(parser.getName())) {
synchronized (UTC_FORMAT) {
try {
joined = UTC_FORMAT.parse(parser.nextText());
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT &&
"occupant".equals(parser.getName())) {

View file

@ -28,8 +28,6 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -147,7 +145,7 @@ public final class QueueDetails implements ExtensionElement {
@Override
public QueueDetails parse(XmlPullParser parser,
int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
IOException, SmackTextParseException {
IOException, TextParseException, ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
QueueDetails queueDetails = new QueueDetails();
@ -178,19 +176,10 @@ public final class QueueDetails implements ExtensionElement {
time = Integer.parseInt(parser.nextText());
}
else if ("join-time".equals(parser.getName())) {
try {
joinTime = dateFormat.parse(parser.nextText());
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
joinTime = dateFormat.parse(parser.nextText());
}
else if (parser.getName().equals("waitTime")) {
Date wait;
try {
wait = dateFormat.parse(parser.nextText());
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
Date wait = dateFormat.parse(parser.nextText());
LOGGER.fine(wait.toString());
}

View file

@ -24,8 +24,6 @@ import java.util.Date;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -128,7 +126,7 @@ public class QueueOverview implements ExtensionElement {
@Override
public QueueOverview parse(XmlPullParser parser,
int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
IOException, SmackTextParseException {
IOException, TextParseException, ParseException {
QueueOverview queueOverview = new QueueOverview();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
@ -142,11 +140,7 @@ public class QueueOverview implements ExtensionElement {
queueOverview.setAverageWaitTime(Integer.parseInt(parser.nextText()));
}
else if ("oldest".equals(parser.getName())) {
try {
queueOverview.setOldestEntry(dateFormat.parse(parser.nextText()));
} catch (ParseException e) {
throw new SmackParsingException.SmackTextParseException(e);
}
queueOverview.setOldestEntry(dateFormat.parse(parser.nextText()));
}
else if ("status".equals(parser.getName())) {
queueOverview.setStatus(WorkgroupQueue.Status.fromString(parser.nextText()));

View file

@ -106,18 +106,10 @@ public class QueueUpdate implements ExtensionElement {
parser.next();
String elementName = parser.getName();
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "position".equals(elementName)) {
try {
position = Integer.parseInt(parser.nextText());
}
catch (NumberFormatException nfe) {
}
position = Integer.parseInt(parser.nextText());
}
else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "time".equals(elementName)) {
try {
timeRemaining = Integer.parseInt(parser.nextText());
}
catch (NumberFormatException nfe) {
}
timeRemaining = Integer.parseInt(parser.nextText());
}
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "queue-status".equals(elementName)) {
done = true;

View file

@ -47,7 +47,8 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
}
@Override
public Transcripts parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
public Transcripts parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, TextParseException, ParseException {
Jid userID = ParserUtils.getJidAttribute(parser, "userID");
List<Transcripts.TranscriptSummary> summaries = new ArrayList<>();
@ -56,7 +57,8 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("transcript")) {
summaries.add(parseSummary(parser));
Transcripts.TranscriptSummary summary = parseSummary(parser);
summaries.add(summary);
}
}
else if (eventType == XmlPullParser.Event.END_ELEMENT) {
@ -70,7 +72,7 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
}
private static Transcripts.TranscriptSummary parseSummary(XmlPullParser parser)
throws IOException, XmlPullParserException {
throws IOException, XmlPullParserException, ParseException {
String sessionID = parser.getAttributeValue("", "sessionID");
Date joinTime = null;
Date leftTime = null;
@ -81,18 +83,14 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("joinTime")) {
try {
synchronized (UTC_FORMAT) {
joinTime = UTC_FORMAT.parse(parser.nextText());
}
} catch (ParseException e) { }
synchronized (UTC_FORMAT) {
joinTime = UTC_FORMAT.parse(parser.nextText());
}
}
else if (parser.getName().equals("leftTime")) {
try {
synchronized (UTC_FORMAT) {
leftTime = UTC_FORMAT.parse(parser.nextText());
}
} catch (ParseException e) { }
synchronized (UTC_FORMAT) {
leftTime = UTC_FORMAT.parse(parser.nextText());
}
}
else if (parser.getName().equals("agents")) {
agents = parseAgents(parser);
@ -109,7 +107,7 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
}
private static List<Transcripts.AgentDetail> parseAgents(XmlPullParser parser)
throws IOException, XmlPullParserException {
throws IOException, XmlPullParserException, ParseException {
List<Transcripts.AgentDetail> agents = new ArrayList<>();
String agentJID = null;
Date joinTime = null;
@ -123,18 +121,14 @@ public class TranscriptsProvider extends IQProvider<Transcripts> {
agentJID = parser.nextText();
}
else if (parser.getName().equals("joinTime")) {
try {
synchronized (UTC_FORMAT) {
joinTime = UTC_FORMAT.parse(parser.nextText());
}
} catch (ParseException e) { }
synchronized (UTC_FORMAT) {
joinTime = UTC_FORMAT.parse(parser.nextText());
}
}
else if (parser.getName().equals("leftTime")) {
try {
synchronized (UTC_FORMAT) {
leftTime = UTC_FORMAT.parse(parser.nextText());
}
} catch (ParseException e) { }
synchronized (UTC_FORMAT) {
leftTime = UTC_FORMAT.parse(parser.nextText());
}
}
else if (parser.getName().equals("agent")) {
agentJID = null;