mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +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 java.util.List;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
import org.jivesoftware.smack.util.ParserUtils;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
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
|
* @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 {
|
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser parser, String relation) throws IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
ParserUtils.forwardToStartElement(parser);
|
||||||
List<URI> uriList = new ArrayList<>();
|
List<URI> uriList = new ArrayList<>();
|
||||||
int initialDepth = parser.getDepth();
|
int initialDepth = parser.getDepth();
|
||||||
|
|
||||||
|
|
|
@ -82,14 +82,7 @@ public class PacketParserUtils {
|
||||||
|
|
||||||
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
|
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
|
||||||
XmlPullParser parser = SmackXmlParser.newXmlParser(reader);
|
XmlPullParser parser = SmackXmlParser.newXmlParser(reader);
|
||||||
// Wind the parser forward to the first start tag
|
ParserUtils.forwardToStartElement(parser);
|
||||||
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();
|
|
||||||
}
|
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,17 @@ public class ParserUtils {
|
||||||
assert parser.getEventType() == XmlPullParser.Event.END_ELEMENT;
|
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)
|
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
XmlPullParser.Event event = parser.getEventType();
|
XmlPullParser.Event event = parser.getEventType();
|
||||||
|
|
Loading…
Reference in a new issue