mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 18:48:00 +01:00
Merge branch '4.4'
This commit is contained in:
commit
0c013e4f29
5 changed files with 46 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2019 Florian Schmaus
|
* Copyright 2019-2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -133,7 +133,7 @@ public class XmlEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XmlEnvironment from(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) {
|
public static XmlEnvironment from(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) {
|
||||||
String namespace = parser.getNamespace();
|
String namespace = parser.getDefaultNamespace();
|
||||||
String xmlLang = ParserUtils.getXmlLang(parser);
|
String xmlLang = ParserUtils.getXmlLang(parser);
|
||||||
return new XmlEnvironment(namespace, xmlLang, outerXmlEnvironment);
|
return new XmlEnvironment(namespace, xmlLang, outerXmlEnvironment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2019 Florian Schmaus
|
* Copyright 2019-2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,6 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
|
@ -207,6 +210,34 @@ public class XmlPullParserTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||||
|
public void testGetNamespace(SmackTestUtil.XmlPullParserKind parserKind)
|
||||||
|
throws XmlPullParserException, IOException {
|
||||||
|
String xml = "<foo:bar xmlns='namespace' xmlns:foo='foo-namespace'/>";
|
||||||
|
XmlPullParser parser = SmackTestUtil.getParserFor(xml, parserKind);
|
||||||
|
|
||||||
|
String parsedName = parser.getName();
|
||||||
|
assertEquals("bar", parsedName);
|
||||||
|
|
||||||
|
String parsedPrefix = parser.getPrefix();
|
||||||
|
assertEquals("foo", parsedPrefix);
|
||||||
|
|
||||||
|
String parsedPrefixNamespace = parser.getNamespace(parsedPrefix);
|
||||||
|
assertEquals("foo-namespace", parsedPrefixNamespace);
|
||||||
|
|
||||||
|
String parsedNamespace = parser.getNamespace();
|
||||||
|
assertEquals("foo-namespace", parsedNamespace);
|
||||||
|
|
||||||
|
List<Function<XmlPullParser, String>> defaultNamespaceRetrievers = new ArrayList<>();
|
||||||
|
defaultNamespaceRetrievers.add(p -> p.getNamespace(null));
|
||||||
|
defaultNamespaceRetrievers.add(p -> p.getDefaultNamespace());
|
||||||
|
for (Function<XmlPullParser, String> defaultNamespaceRetriever : defaultNamespaceRetrievers) {
|
||||||
|
String defaultNamespace = defaultNamespaceRetriever.apply(parser);
|
||||||
|
assertEquals("namespace", defaultNamespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void assertAttributeHolds(XmlPullParser parser, int attributeIndex, String expectedLocalpart,
|
private static void assertAttributeHolds(XmlPullParser parser, int attributeIndex, String expectedLocalpart,
|
||||||
String expectedPrefix, String expectedNamespace) {
|
String expectedPrefix, String expectedNamespace) {
|
||||||
QName qname = parser.getAttributeQName(attributeIndex);
|
QName qname = parser.getAttributeQName(attributeIndex);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2020 Florian Schmaus
|
* Copyright 2020-2021 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
package org.jivesoftware.smackx.bob.element;
|
package org.jivesoftware.smackx.bob.element;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.StanzaView;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.jivesoftware.smackx.bob.BoBData;
|
import org.jivesoftware.smackx.bob.BoBData;
|
||||||
|
@ -94,8 +94,8 @@ public class BoBDataExtension implements ExtensionElement {
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BoBDataExtension from(Message message) {
|
public static BoBDataExtension from(StanzaView stanza) {
|
||||||
return message.getExtension(BoBDataExtension.class);
|
return stanza.getExtension(BoBDataExtension.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,6 +494,9 @@ public final class DataForm implements ExtensionElement {
|
||||||
* @return a reference to this builder.
|
* @return a reference to this builder.
|
||||||
*/
|
*/
|
||||||
public Builder addItem(Item item) {
|
public Builder addItem(Item item) {
|
||||||
|
if (items == null) {
|
||||||
|
items = new ArrayList<>();
|
||||||
|
}
|
||||||
items.add(item);
|
items.add(item);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2019 Florian Schmaus.
|
* Copyright 2019-2021 Florian Schmaus.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -75,6 +75,10 @@ public interface XmlPullParser {
|
||||||
|
|
||||||
String getNamespace(String prefix);
|
String getNamespace(String prefix);
|
||||||
|
|
||||||
|
default String getDefaultNamespace() {
|
||||||
|
return getNamespace(null);
|
||||||
|
}
|
||||||
|
|
||||||
int getDepth();
|
int getDepth();
|
||||||
|
|
||||||
String getPositionDescription();
|
String getPositionDescription();
|
||||||
|
|
Loading…
Reference in a new issue