1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-14 19:42:05 +01:00

Use nextTag and switch in provider

This commit is contained in:
Paul Schaub 2019-08-31 16:56:44 +02:00
parent 609ace2f0d
commit a41430b1fd

View file

@ -46,37 +46,36 @@ public class MetadataProvider extends ExtensionElementProvider<MetadataExtension
List<MetadataInfo> metadataInfos = null; List<MetadataInfo> metadataInfos = null;
List<MetadataPointer> pointers = null; List<MetadataPointer> pointers = null;
while (true) { outerloop: while (true) {
XmlPullParser.Event eventType = parser.next(); 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")) { MetadataInfo info = parseInfo(parser);
if (metadataInfos == null) { if (info.getId() != null) {
metadataInfos = new ArrayList<>(); metadataInfos.add(info);
}
} }
MetadataInfo info = parseInfo(parser); if (parser.getName().equals("pointer")) {
if (info.getId() != null) { if (pointers == null) {
metadataInfos.add(info); 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; break;
} case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
} }
} }
return new MetadataExtension(metadataInfos, pointers); return new MetadataExtension(metadataInfos, pointers);
} }
@ -126,25 +125,28 @@ public class MetadataProvider extends ExtensionElementProvider<MetadataExtension
String namespace = null; String namespace = null;
HashMap<String, Object> fields = null; HashMap<String, Object> fields = null;
while (true) { outperloop: while (true) {
XmlPullParser.Event eventType2 = parser.next(); XmlPullParser.TagEvent tag = parser.nextTag();
if (eventType2 == XmlPullParser.Event.START_ELEMENT) { switch (tag) {
if (parser.getName().equals("x")) { case START_ELEMENT:
namespace = parser.getNamespace(); if (parser.getName().equals("x")) {
} else { namespace = parser.getNamespace();
if (fields == null) { } else {
fields = new HashMap<>(); 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; break;
}
case END_ELEMENT:
if (parser.getDepth() == pointerDepth) {
break outperloop;
}
} }
} }