mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Merge pull request #413 from adiaholic/xep-0156
HttpLookupMethod: Position parser at START_ELEMENT before parsing
This commit is contained in:
commit
36d61d9e52
3 changed files with 14 additions and 8 deletions
|
@ -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…
Reference in a new issue