mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-21 22:02:06 +01:00
Merge branch '4.4'
This commit is contained in:
commit
1a963cc794
2 changed files with 40 additions and 6 deletions
|
@ -299,7 +299,7 @@ public class PacketParserUtils {
|
||||||
*/
|
*/
|
||||||
public static CharSequence parseContentDepth(XmlPullParser parser, int depth, boolean fullNamespaces) throws XmlPullParserException, IOException {
|
public static CharSequence parseContentDepth(XmlPullParser parser, int depth, boolean fullNamespaces) throws XmlPullParserException, IOException {
|
||||||
if (parser.supportsRoundtrip()) {
|
if (parser.supportsRoundtrip()) {
|
||||||
return parseContentDepthWithRoundtrip(parser, depth, fullNamespaces);
|
return parseContentDepthWithRoundtrip(parser, depth);
|
||||||
} else {
|
} else {
|
||||||
return parseContentDepthWithoutRoundtrip(parser, depth, fullNamespaces);
|
return parseContentDepthWithoutRoundtrip(parser, depth, fullNamespaces);
|
||||||
}
|
}
|
||||||
|
@ -368,8 +368,7 @@ public class PacketParserUtils {
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedVariable")
|
private static XmlStringBuilder parseContentDepthWithRoundtrip(XmlPullParser parser, int depth)
|
||||||
private static CharSequence parseContentDepthWithRoundtrip(XmlPullParser parser, int depth, boolean fullNamespaces)
|
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
XmlStringBuilder sb = new XmlStringBuilder();
|
XmlStringBuilder sb = new XmlStringBuilder();
|
||||||
XmlPullParser.Event event = parser.getEventType();
|
XmlPullParser.Event event = parser.getEventType();
|
||||||
|
@ -377,10 +376,9 @@ public class PacketParserUtils {
|
||||||
outerloop: while (true) {
|
outerloop: while (true) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case START_ELEMENT:
|
case START_ELEMENT:
|
||||||
if (startElementJustSeen) {
|
|
||||||
sb.rightAngleBracket();
|
|
||||||
}
|
|
||||||
startElementJustSeen = true;
|
startElementJustSeen = true;
|
||||||
|
String openElementTag = parser.getText();
|
||||||
|
sb.append(openElementTag);
|
||||||
break;
|
break;
|
||||||
case END_ELEMENT:
|
case END_ELEMENT:
|
||||||
boolean isEmptyElement = false;
|
boolean isEmptyElement = false;
|
||||||
|
|
|
@ -854,4 +854,40 @@ public class PacketParserUtilsTest {
|
||||||
StanzaError error = PacketParserUtils.parseError(parser);
|
StanzaError error = PacketParserUtils.parseError(parser);
|
||||||
assertEquals(text, error.getDescriptiveText());
|
assertEquals(text, error.getDescriptiveText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||||
|
public void testParseElementSimple(SmackTestUtil.XmlPullParserKind parserKind) throws TransformerException, ParserConfigurationException, FactoryConfigurationError, XmlPullParserException, IOException {
|
||||||
|
String unknownElement = XMLBuilder.create("unknown-element")
|
||||||
|
.ns("https://example.org/non-existent")
|
||||||
|
.e("inner")
|
||||||
|
.t("test")
|
||||||
|
.asString(outputProperties);
|
||||||
|
|
||||||
|
XmlPullParser xmlPullParser = SmackTestUtil.getParserFor(unknownElement, parserKind);
|
||||||
|
|
||||||
|
CharSequence unknownElementParsed = PacketParserUtils.parseElement(xmlPullParser);
|
||||||
|
assertXmlSimilar(unknownElement, unknownElementParsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||||
|
public void testParseElementExtended(SmackTestUtil.XmlPullParserKind parserKind) throws TransformerException, ParserConfigurationException, FactoryConfigurationError, XmlPullParserException, IOException {
|
||||||
|
String unknownElement = XMLBuilder.create("unknown-element")
|
||||||
|
.ns("https://example.org/non-existent")
|
||||||
|
.a("attribute-outer", "foo")
|
||||||
|
.e("inner")
|
||||||
|
.a("attribute-inner", "bar")
|
||||||
|
.a("attribute-inner-2", "baz")
|
||||||
|
.t("test")
|
||||||
|
.up()
|
||||||
|
.e("empty-element")
|
||||||
|
.up()
|
||||||
|
.asString(outputProperties);
|
||||||
|
|
||||||
|
XmlPullParser xmlPullParser = SmackTestUtil.getParserFor(unknownElement, parserKind);
|
||||||
|
|
||||||
|
CharSequence unknownElementParsed = PacketParserUtils.parseElement(xmlPullParser);
|
||||||
|
assertXmlSimilar(unknownElement, unknownElementParsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue