mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
[core] Pass down the XML environment in IQChildElementXmlStringBuilder
This allows to avoid redundant XML namespaces within IQs, like for example here: <iq xmlns='jabber:client' id='EKP8I-1' type='set'> <jingle xmlns='urn:xmpp:jingle:1' action='content-accept' sid='MySession'> <content xmlns='urn:xmpp:jingle:1' creator='initiator' name='Hello world'> </content> </jingle> </iq> Fixes SMACK-917 Reported-by: Jonathan Lennox
This commit is contained in:
parent
585bcb4dc8
commit
b243a40e26
5 changed files with 19 additions and 18 deletions
|
@ -202,7 +202,7 @@ public abstract class IQ extends Stanza implements IqView {
|
||||||
|
|
||||||
// Add the query section if there is one.
|
// Add the query section if there is one.
|
||||||
IQChildElementXmlStringBuilder iqChildElement = getIQChildElementBuilder(
|
IQChildElementXmlStringBuilder iqChildElement = getIQChildElementBuilder(
|
||||||
new IQChildElementXmlStringBuilder(this));
|
new IQChildElementXmlStringBuilder(getChildElementName(), getChildElementNamespace(), null, xml.getXmlEnvironment()));
|
||||||
// TOOD: Document the cases where iqChildElement is null but childElementName not. And if there are none, change
|
// TOOD: Document the cases where iqChildElement is null but childElementName not. And if there are none, change
|
||||||
// the logic.
|
// the logic.
|
||||||
if (iqChildElement == null) {
|
if (iqChildElement == null) {
|
||||||
|
@ -399,17 +399,16 @@ public abstract class IQ extends Stanza implements IqView {
|
||||||
|
|
||||||
private boolean isEmptyElement;
|
private boolean isEmptyElement;
|
||||||
|
|
||||||
private IQChildElementXmlStringBuilder(IQ iq) {
|
public IQChildElementXmlStringBuilder(ExtensionElement extensionElement,
|
||||||
this(iq.getChildElementName(), iq.getChildElementNamespace());
|
XmlEnvironment enclosingXmlEnvironment) {
|
||||||
|
this(extensionElement.getElementName(), extensionElement.getNamespace(), extensionElement.getLanguage(),
|
||||||
|
enclosingXmlEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQChildElementXmlStringBuilder(ExtensionElement pe) {
|
private IQChildElementXmlStringBuilder(String elementName, String xmlNs, String xmlLang,
|
||||||
this(pe.getElementName(), pe.getNamespace());
|
XmlEnvironment enclosingXmlEnvironment) {
|
||||||
}
|
super(elementName, xmlNs, xmlLang, enclosingXmlEnvironment);
|
||||||
|
this.element = elementName;
|
||||||
private IQChildElementXmlStringBuilder(String element, String namespace) {
|
|
||||||
prelude(element, namespace);
|
|
||||||
this.element = element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmptyElement() {
|
public void setEmptyElement() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2014-2020 Florian Schmaus
|
* Copyright 2014-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.
|
||||||
|
@ -53,11 +53,13 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment) {
|
public XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment) {
|
||||||
sb = new LazyStringBuilder();
|
this(element.getElementName(), element.getNamespace(), element.getLanguage(), enclosingXmlEnvironment);
|
||||||
halfOpenElement(element);
|
}
|
||||||
|
|
||||||
|
public XmlStringBuilder(String elementName, String xmlNs, String xmlLang, XmlEnvironment enclosingXmlEnvironment) {
|
||||||
|
sb = new LazyStringBuilder();
|
||||||
|
halfOpenElement(elementName);
|
||||||
|
|
||||||
String xmlNs = element.getNamespace();
|
|
||||||
String xmlLang = element.getLanguage();
|
|
||||||
if (enclosingXmlEnvironment == null) {
|
if (enclosingXmlEnvironment == null) {
|
||||||
xmlnsAttribute(xmlNs);
|
xmlnsAttribute(xmlNs);
|
||||||
xmllangAttribute(xmlLang);
|
xmllangAttribute(xmlLang);
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class DataPacketExtension implements ExtensionElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||||
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this, enclosingNamespace));
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class RoomInvitation implements ExtensionElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||||
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this, enclosingNamespace));
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class RoomTransfer implements ExtensionElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||||
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this, enclosingNamespace));
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue