From a41430b1fd6f284d09ba7859bc6c4d5a06d4b63d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 31 Aug 2019 16:56:44 +0200 Subject: [PATCH] Use nextTag and switch in provider --- .../avatar/provider/MetadataProvider.java | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/provider/MetadataProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/provider/MetadataProvider.java index 4490bb007..4514c8bd9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/provider/MetadataProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/provider/MetadataProvider.java @@ -46,37 +46,36 @@ public class MetadataProvider extends ExtensionElementProvider metadataInfos = null; List pointers = null; - while (true) { - XmlPullParser.Event eventType = parser.next(); + outerloop: while (true) { + XmlPullParser.TagEvent eventType = parser.nextTag(); - if (eventType == XmlPullParser.Event.START_ELEMENT) { + switch (eventType) { + case START_ELEMENT: + if (parser.getName().equals("info")) { + if (metadataInfos == null) { + metadataInfos = new ArrayList<>(); + } - if (parser.getName().equals("info")) { - if (metadataInfos == null) { - metadataInfos = new ArrayList<>(); + MetadataInfo info = parseInfo(parser); + if (info.getId() != null) { + metadataInfos.add(info); + } } - MetadataInfo info = parseInfo(parser); - if (info.getId() != null) { - metadataInfos.add(info); + if (parser.getName().equals("pointer")) { + if (pointers == null) { + pointers = new ArrayList<>(); + } + + pointers.add(parsePointer(parser)); } - } - - if (parser.getName().equals("pointer")) { - if (pointers == null) { - pointers = new ArrayList<>(); - } - - pointers.add(parsePointer(parser)); - } - - } else if (eventType == XmlPullParser.Event.END_ELEMENT) { - if (parser.getDepth() == initialDepth) { break; - } + case END_ELEMENT: + if (parser.getDepth() == initialDepth) { + break outerloop; + } } } - return new MetadataExtension(metadataInfos, pointers); } @@ -126,25 +125,28 @@ public class MetadataProvider extends ExtensionElementProvider fields = null; - while (true) { - XmlPullParser.Event eventType2 = parser.next(); + outperloop: while (true) { + XmlPullParser.TagEvent tag = parser.nextTag(); - if (eventType2 == XmlPullParser.Event.START_ELEMENT) { - if (parser.getName().equals("x")) { - namespace = parser.getNamespace(); - } else { - if (fields == null) { - fields = new HashMap<>(); + switch (tag) { + case START_ELEMENT: + if (parser.getName().equals("x")) { + namespace = parser.getNamespace(); + } else { + if (fields == null) { + fields = new HashMap<>(); + } + + String name = parser.getName(); + Object value = parser.nextText(); + fields.put(name, value); } - - String name = parser.getName(); - Object value = parser.nextText(); - fields.put(name, value); - } - } else if (eventType2 == XmlPullParser.Event.END_ELEMENT) { - if (parser.getDepth() == pointerDepth) { break; - } + + case END_ELEMENT: + if (parser.getDepth() == pointerDepth) { + break outperloop; + } } }