Merge pull request #413 from adiaholic/xep-0156

HttpLookupMethod: Position parser at START_ELEMENT before parsing
listEqualsHashcode
Florian Schmaus 2 years ago committed by GitHub
commit 36d61d9e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      smack-core/src/main/java/org/jivesoftware/smack/altconnections/HttpLookupMethod.java
  2. 9
      smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
  3. 11
      smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -132,6 +133,7 @@ public final class HttpLookupMethod {
* @throws URISyntaxException exception to indicate that a string could not be parsed as a URI reference
*/
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser parser, String relation) throws IOException, XmlPullParserException, URISyntaxException {
ParserUtils.forwardToStartElement(parser);
List<URI> uriList = new ArrayList<>();
int initialDepth = parser.getDepth();

@ -82,14 +82,7 @@ public class PacketParserUtils {
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
XmlPullParser parser = SmackXmlParser.newXmlParser(reader);
// Wind the parser forward to the first start tag
XmlPullParser.Event event = parser.getEventType();
while (event != XmlPullParser.Event.START_ELEMENT) {
if (event == XmlPullParser.Event.END_DOCUMENT) {
throw new IllegalArgumentException("Document contains no start tag");
}
event = parser.next();
}
ParserUtils.forwardToStartElement(parser);
return parser;
}

@ -63,6 +63,17 @@ public class ParserUtils {
assert parser.getEventType() == XmlPullParser.Event.END_ELEMENT;
}
public static void forwardToStartElement(XmlPullParser parser) throws XmlPullParserException, IOException {
// Wind the parser forward to the first start tag
XmlPullParser.Event event = parser.getEventType();
while (event != XmlPullParser.Event.START_ELEMENT) {
if (event == XmlPullParser.Event.END_DOCUMENT) {
throw new IllegalArgumentException("Document contains no start tag");
}
event = parser.next();
}
}
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
throws XmlPullParserException, IOException {
XmlPullParser.Event event = parser.getEventType();

Loading…
Cancel
Save