mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Rework XML Element hierarchy and XmlStringBuilder
- Reduce the amount of types that are subtypes of NamedElement. See javadoc of NamedElement for rationale. - Work more with XmlEnvironment in XmlStringBuilder. - Some minor changes to XmlStringBuilder API.
This commit is contained in:
parent
e9bcdf3e6d
commit
65576cf3c2
74 changed files with 653 additions and 523 deletions
|
@ -212,19 +212,19 @@ public class MultipleRecipientManager {
|
|||
if (to != null) {
|
||||
for (Jid jid : to) {
|
||||
packet.setTo(jid);
|
||||
connection.sendStanza(new PacketCopy(packet.toXML()));
|
||||
connection.sendStanza(new PacketCopy(packet));
|
||||
}
|
||||
}
|
||||
if (cc != null) {
|
||||
for (Jid jid : cc) {
|
||||
packet.setTo(jid);
|
||||
connection.sendStanza(new PacketCopy(packet.toXML()));
|
||||
connection.sendStanza(new PacketCopy(packet));
|
||||
}
|
||||
}
|
||||
if (bcc != null) {
|
||||
for (Jid jid : bcc) {
|
||||
packet.setTo(jid);
|
||||
connection.sendStanza(new PacketCopy(packet.toXML()));
|
||||
connection.sendStanza(new PacketCopy(packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +297,7 @@ public class MultipleRecipientManager {
|
|||
*/
|
||||
private static final class PacketCopy extends Stanza {
|
||||
|
||||
private final String elementName;
|
||||
private final CharSequence text;
|
||||
|
||||
/**
|
||||
|
@ -305,8 +306,9 @@ public class MultipleRecipientManager {
|
|||
*
|
||||
* @param text the whole text of the stanza to send
|
||||
*/
|
||||
private PacketCopy(CharSequence text) {
|
||||
this.text = text;
|
||||
private PacketCopy(Stanza stanza) {
|
||||
this.elementName = stanza.getElementName();
|
||||
this.text = stanza.toXML();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,6 +321,11 @@ public class MultipleRecipientManager {
|
|||
return toXML().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return elementName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
@ -129,7 +128,7 @@ public class MultipleAddresses implements ExtensionElement {
|
|||
return buf;
|
||||
}
|
||||
|
||||
public static final class Address implements NamedElement {
|
||||
public static final class Address implements ExtensionElement {
|
||||
|
||||
public static final String ELEMENT = "address";
|
||||
|
||||
|
@ -193,10 +192,15 @@ public class MultipleAddresses implements ExtensionElement {
|
|||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
buf.halfOpenElement(this).attribute("type", type);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.attribute("type", type);
|
||||
buf.optAttribute("jid", jid);
|
||||
buf.optAttribute("node", node);
|
||||
buf.optAttribute("desc", description);
|
||||
|
@ -209,5 +213,6 @@ public class MultipleAddresses implements ExtensionElement {
|
|||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.InternetAddress;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -260,13 +260,20 @@ public class Bytestream extends IQ {
|
|||
return xml;
|
||||
}
|
||||
|
||||
private abstract static class BytestreamExtensionElement implements ExtensionElement {
|
||||
@Override
|
||||
public final String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stanza extension that represents a potential SOCKS5 proxy for the file transfer. Stream hosts
|
||||
* are forwarded to the target of the file transfer who then chooses and connects to one.
|
||||
*
|
||||
* @author Alexander Wenckus
|
||||
*/
|
||||
public static class StreamHost implements NamedElement {
|
||||
public static class StreamHost extends BytestreamExtensionElement {
|
||||
|
||||
public static String ELEMENTNAME = "streamhost";
|
||||
|
||||
|
@ -342,7 +349,7 @@ public class Bytestream extends IQ {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.attribute("jid", getJID());
|
||||
xml.attribute("host", address);
|
||||
if (getPort() != 0) {
|
||||
|
@ -366,7 +373,7 @@ public class Bytestream extends IQ {
|
|||
*
|
||||
* @author Alexander Wenckus
|
||||
*/
|
||||
public static class StreamHostUsed implements NamedElement {
|
||||
public static class StreamHostUsed extends BytestreamExtensionElement {
|
||||
|
||||
public static String ELEMENTNAME = "streamhost-used";
|
||||
|
||||
|
@ -397,7 +404,7 @@ public class Bytestream extends IQ {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.attribute("jid", getJID());
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
|
@ -409,7 +416,7 @@ public class Bytestream extends IQ {
|
|||
*
|
||||
* @author Alexander Wenckus
|
||||
*/
|
||||
public static class Activate implements NamedElement {
|
||||
public static class Activate extends BytestreamExtensionElement {
|
||||
|
||||
public static String ELEMENTNAME = "activate";
|
||||
|
||||
|
@ -440,12 +447,13 @@ public class Bytestream extends IQ {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.rightAngleBracket();
|
||||
xml.escape(getTarget());
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,7 +103,7 @@ public class DelayInformation implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.attribute("stamp", XmppDateTime.formatXEP0082Date(stamp));
|
||||
xml.optAttribute("from", from);
|
||||
xml.rightAngleBracket();
|
||||
|
|
|
@ -72,10 +72,10 @@ public class Forwarded implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.rightAngleBracket();
|
||||
xml.optElement(getDelayInformation());
|
||||
xml.append(forwardedPacket.toXML(NAMESPACE));
|
||||
xml.append(forwardedPacket);
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -24,9 +25,10 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
/**
|
||||
* Jingle content element.
|
||||
*/
|
||||
public final class JingleContent implements NamedElement {
|
||||
public final class JingleContent implements FullyQualifiedElement {
|
||||
|
||||
public static final String ELEMENT = "content";
|
||||
public static final String NAMESPACE = Jingle.NAMESPACE;
|
||||
|
||||
public static final String CREATOR_ATTRIBUTE_NAME = "creator";
|
||||
|
||||
|
@ -132,8 +134,13 @@ public final class JingleContent implements NamedElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
|
||||
xml.attribute(CREATOR_ATTRIBUTE_NAME, creator);
|
||||
xml.optAttribute(DISPOSITION_ATTRIBUTE_NAME, disposition);
|
||||
xml.attribute(NAME_ATTRIBUTE_NAME, name);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014-2017 Florian Schmaus
|
||||
* Copyright © 2014-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,18 +16,12 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
|
||||
/**
|
||||
* An element found usually in 'description' elements.
|
||||
*
|
||||
*/
|
||||
public abstract class JingleContentDescriptionChildElement implements NamedElement {
|
||||
public interface JingleContentDescriptionChildElement extends FullyQualifiedElement {
|
||||
|
||||
public static final String ELEMENT = "payload-type";
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,6 +20,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
|
@ -66,8 +67,8 @@ public abstract class JingleContentTransport implements ExtensionElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
|
||||
addExtraAttributes(xml);
|
||||
|
||||
if (candidates.isEmpty() && info == null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
|
||||
/**
|
||||
* An element found usually in Jingle 'transport' elements.
|
||||
*
|
||||
*/
|
||||
public abstract class JingleContentTransportCandidate implements NamedElement {
|
||||
public abstract class JingleContentTransportCandidate implements FullyQualifiedElement {
|
||||
|
||||
public static final String ELEMENT = "candidate";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
* Copyright 2017 Paul Schaub, 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
|
||||
/**
|
||||
* Abstract JingleContentTransportInfo element.
|
||||
*/
|
||||
public abstract class JingleContentTransportInfo implements NamedElement {
|
||||
public interface JingleContentTransportInfo extends FullyQualifiedElement {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,7 +19,8 @@ package org.jivesoftware.smackx.jingle.element;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -29,9 +30,10 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
* @see <a href="https://xmpp.org/extensions/xep-0166.html#def-reason">XEP-0166 § 7.4</a>
|
||||
*
|
||||
*/
|
||||
public class JingleReason implements NamedElement {
|
||||
public class JingleReason implements FullyQualifiedElement {
|
||||
|
||||
public static final String ELEMENT = "reason";
|
||||
public static final String NAMESPACE = Jingle.NAMESPACE;
|
||||
|
||||
public static AlternativeSession AlternativeSession(String sessionId) {
|
||||
return new AlternativeSession(sessionId);
|
||||
|
@ -114,11 +116,16 @@ public class JingleReason implements NamedElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
|
||||
xml.rightAngleBracket();
|
||||
|
||||
xml.emptyElement(reason.asString);
|
||||
xml.emptyElement(reason);
|
||||
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.InternetAddress;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
@ -33,6 +34,8 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
|||
*/
|
||||
public final class JingleS5BTransportCandidate extends JingleContentTransportCandidate {
|
||||
|
||||
public static final String NAMESPACE = JingleS5BTransport.NAMESPACE_V1;
|
||||
|
||||
public static final String ATTR_CID = "cid";
|
||||
public static final String ATTR_HOST = "host";
|
||||
public static final String ATTR_JID = "jid";
|
||||
|
@ -130,10 +133,15 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
|
|||
return new Bytestream.StreamHost(jid, host, port);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
|
||||
xml.attribute(ATTR_CID, cid);
|
||||
xml.attribute(ATTR_HOST, host);
|
||||
xml.attribute(ATTR_JID, jid);
|
||||
|
@ -207,4 +215,5 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
|
|||
return new JingleS5BTransportCandidate(cid, host, jid, port, priority, type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
||||
|
@ -23,7 +24,14 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
|||
/**
|
||||
* Class representing possible SOCKS5 TransportInfo elements.
|
||||
*/
|
||||
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
|
||||
public abstract class JingleS5BTransportInfo implements JingleContentTransportInfo {
|
||||
|
||||
public static final String NAMESPACE = JingleS5BTransport.NAMESPACE_V1;
|
||||
|
||||
@Override
|
||||
public final String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
public abstract static class JingleS5BCandidateTransportInfo extends JingleS5BTransportInfo {
|
||||
public static final String ATTR_CID = "cid";
|
||||
|
@ -39,9 +47,8 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo
|
|||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
public final XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
|
||||
xml.attribute(ATTR_CID, getCandidateId());
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
package org.jivesoftware.smackx.mood.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -107,8 +109,8 @@ public class MoodElement implements ExtensionElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
|
||||
|
||||
if (mood == null && text == null) {
|
||||
// Empty mood element used as STOP signal
|
||||
|
@ -152,7 +154,7 @@ public class MoodElement implements ExtensionElement {
|
|||
* {@link NamedElement} which represents the mood.
|
||||
* This element has the element name of the mood selected from {@link Mood}.
|
||||
*/
|
||||
public static class MoodSubjectElement implements NamedElement {
|
||||
public static class MoodSubjectElement implements FullyQualifiedElement {
|
||||
|
||||
private final Mood mood;
|
||||
private final MoodConcretisation concretisation;
|
||||
|
@ -168,16 +170,17 @@ public class MoodElement implements ExtensionElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
|
||||
|
||||
if (concretisation == null) {
|
||||
return xml.emptyElement(getElementName());
|
||||
return xml.closeEmptyElement();
|
||||
}
|
||||
|
||||
return xml.openElement(getElementName())
|
||||
.append(concretisation.toXML())
|
||||
.closeElement(getElementName());
|
||||
xml.rightAngleBracket()
|
||||
.append(concretisation)
|
||||
.closeElement(this);
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,5 +200,10 @@ public class MoodElement implements ExtensionElement {
|
|||
public MoodConcretisation getConcretisation() {
|
||||
return concretisation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ public class MUCUser implements ExtensionElement {
|
|||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public static class Decline implements NamedElement {
|
||||
public static class Decline implements ExtensionElement {
|
||||
public static final String ELEMENT = "decline";
|
||||
|
||||
private final String reason;
|
||||
|
@ -370,7 +370,7 @@ public class MUCUser implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
||||
xml.optAttribute("to", getTo());
|
||||
xml.optAttribute("from", getFrom());
|
||||
xml.rightAngleBracket();
|
||||
|
@ -383,6 +383,11 @@ public class MUCUser implements ExtensionElement {
|
|||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -417,7 +417,7 @@ public final class FormField implements FullyQualifiedElement {
|
|||
} else {
|
||||
buf.rightAngleBracket();
|
||||
|
||||
buf.append(formFieldChildElements, enclosingNamespace);
|
||||
buf.append(formFieldChildElements);
|
||||
|
||||
buf.closeElement(this);
|
||||
}
|
||||
|
|
|
@ -325,15 +325,10 @@ public class DataForm implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, xmlEnvironment);
|
||||
buf.attribute("type", getType());
|
||||
buf.rightAngleBracket();
|
||||
|
||||
XmlEnvironment dataFormxmlEnvironment = XmlEnvironment.builder()
|
||||
.withNamespace(NAMESPACE)
|
||||
.withNext(xmlEnvironment)
|
||||
.build();
|
||||
|
||||
buf.optElement("title", getTitle());
|
||||
for (String instruction : getInstructions()) {
|
||||
buf.element("instructions", instruction);
|
||||
|
@ -347,7 +342,7 @@ public class DataForm implements ExtensionElement {
|
|||
buf.append(item.toXML());
|
||||
}
|
||||
// Add all form fields.
|
||||
buf.append(getFields(), dataFormxmlEnvironment);
|
||||
buf.append(getFields());
|
||||
for (Element element : extensionElements) {
|
||||
buf.append(element.toXML());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Anno van Vliet
|
||||
* Copyright 2014 Anno van Vliet, 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,7 +20,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
|
@ -96,24 +95,14 @@ public class DataLayout implements ExtensionElement {
|
|||
buf.optAttribute("label", getLabel());
|
||||
buf.rightAngleBracket();
|
||||
|
||||
walkList(buf, getPageLayout());
|
||||
buf.append(getPageLayout());
|
||||
|
||||
buf.closeElement(this);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param buf TODO javadoc me please
|
||||
* @param pageLayout TODO javadoc me please
|
||||
*/
|
||||
private static void walkList(XmlStringBuilder buf, List<DataFormLayoutElement> pageLayout) {
|
||||
for (DataFormLayoutElement object : pageLayout) {
|
||||
buf.append(object.toXML());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Fieldref implements DataFormLayoutElement{
|
||||
public static class Fieldref extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "fieldref";
|
||||
private final String var;
|
||||
|
@ -128,7 +117,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.attribute("var", getVar());
|
||||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
|
@ -150,7 +139,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Section implements DataFormLayoutElement{
|
||||
public static class Section extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "section";
|
||||
private final List<DataFormLayoutElement> sectionLayout = new ArrayList<>();
|
||||
|
@ -188,11 +177,12 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.optAttribute("label", getLabel());
|
||||
buf.rightAngleBracket();
|
||||
|
||||
walkList(buf, getSectionLayout());
|
||||
buf.append(getSectionLayout());
|
||||
|
||||
buf.closeElement(ELEMENT);
|
||||
return buf;
|
||||
}
|
||||
|
@ -213,13 +203,13 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Reportedref implements DataFormLayoutElement{
|
||||
public static class Reportedref extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "reportedref";
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
}
|
||||
|
@ -231,7 +221,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Text implements DataFormLayoutElement{
|
||||
public static class Text extends DataFormLayoutElement{
|
||||
public static final String ELEMENT = "text";
|
||||
private final String text;
|
||||
|
||||
|
@ -245,8 +235,10 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
buf.element(ELEMENT, getText());
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.rightAngleBracket();
|
||||
buf.escape(getText());
|
||||
buf.closeElement(this);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -266,7 +258,11 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public interface DataFormLayoutElement extends NamedElement {
|
||||
public abstract static class DataFormLayoutElement implements ExtensionElement {
|
||||
@Override
|
||||
public final String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Anno van Vliet
|
||||
* Copyright 2014 Anno van Vliet, 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,7 +19,8 @@ package org.jivesoftware.smackx.xdatavalidation.packet;
|
|||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.datatypes.UInt32;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -336,7 +337,7 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
* This element indicates for "list-multi", that a minimum and maximum number of options should be selected and/or
|
||||
* entered.
|
||||
*/
|
||||
public static class ListRange implements NamedElement {
|
||||
public static class ListRange implements FullyQualifiedElement {
|
||||
|
||||
public static final String ELEMENT = "list-range";
|
||||
private final UInt32 min;
|
||||
|
@ -363,8 +364,8 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingXmlEnvironment);
|
||||
buf.optAttribute("min", getMin());
|
||||
buf.optAttribute("max", getMax());
|
||||
buf.closeEmptyElement();
|
||||
|
@ -394,6 +395,11 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,7 +70,7 @@ public class JingleContentTest extends SmackTestSuite {
|
|||
assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
|
||||
|
||||
String xml =
|
||||
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
|
||||
"<content xmlns='urn:xmpp:jingle:1' creator='initiator' disposition='session' name='A name' senders='both'>" +
|
||||
"</content>";
|
||||
assertEquals(xml, content1.toXML().toString());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
* Copyright 2017-2019 Paul Schaub, 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test JingleReason functionality.
|
||||
|
@ -31,56 +32,67 @@ public class JingleReasonTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void parserTest() {
|
||||
assertEquals("<reason><success/></reason>",
|
||||
JingleReason.Success.toXML().toString());
|
||||
assertEquals("<reason><busy/></reason>",
|
||||
JingleReason.Busy.toXML().toString());
|
||||
assertEquals("<reason><cancel/></reason>",
|
||||
JingleReason.Cancel.toXML().toString());
|
||||
assertEquals("<reason><connectivity-error/></reason>",
|
||||
JingleReason.ConnectivityError.toXML().toString());
|
||||
assertEquals("<reason><decline/></reason>",
|
||||
JingleReason.Decline.toXML().toString());
|
||||
assertEquals("<reason><expired/></reason>",
|
||||
JingleReason.Expired.toXML().toString());
|
||||
assertEquals("<reason><unsupported-transports/></reason>",
|
||||
JingleReason.UnsupportedTransports.toXML().toString());
|
||||
assertEquals("<reason><failed-transport/></reason>",
|
||||
JingleReason.FailedTransport.toXML().toString());
|
||||
assertEquals("<reason><general-error/></reason>",
|
||||
JingleReason.GeneralError.toXML().toString());
|
||||
assertEquals("<reason><gone/></reason>",
|
||||
JingleReason.Gone.toXML().toString());
|
||||
assertEquals("<reason><media-error/></reason>",
|
||||
JingleReason.MediaError.toXML().toString());
|
||||
assertEquals("<reason><security-error/></reason>",
|
||||
JingleReason.SecurityError.toXML().toString());
|
||||
assertEquals("<reason><unsupported-applications/></reason>",
|
||||
JingleReason.UnsupportedApplications.toXML().toString());
|
||||
assertEquals("<reason><timeout/></reason>",
|
||||
JingleReason.Timeout.toXML().toString());
|
||||
assertEquals("<reason><failed-application/></reason>",
|
||||
JingleReason.FailedApplication.toXML().toString());
|
||||
assertEquals("<reason><incompatible-parameters/></reason>",
|
||||
JingleReason.IncompatibleParameters.toXML().toString());
|
||||
assertEquals("<reason><alternative-session><sid>1234</sid></alternative-session></reason>",
|
||||
JingleReason.AlternativeSession("1234").toXML().toString());
|
||||
assertReasonXml("<reason><success/></reason>",
|
||||
JingleReason.Success);
|
||||
assertReasonXml("<reason><busy/></reason>",
|
||||
JingleReason.Busy);
|
||||
assertReasonXml("<reason><cancel/></reason>",
|
||||
JingleReason.Cancel);
|
||||
assertReasonXml("<reason><connectivity-error/></reason>",
|
||||
JingleReason.ConnectivityError);
|
||||
assertReasonXml("<reason><decline/></reason>",
|
||||
JingleReason.Decline);
|
||||
assertReasonXml("<reason><expired/></reason>",
|
||||
JingleReason.Expired);
|
||||
assertReasonXml("<reason><unsupported-transports/></reason>",
|
||||
JingleReason.UnsupportedTransports);
|
||||
assertReasonXml("<reason><failed-transport/></reason>",
|
||||
JingleReason.FailedTransport);
|
||||
assertReasonXml("<reason><general-error/></reason>",
|
||||
JingleReason.GeneralError);
|
||||
assertReasonXml("<reason><gone/></reason>",
|
||||
JingleReason.Gone);
|
||||
assertReasonXml("<reason><media-error/></reason>",
|
||||
JingleReason.MediaError);
|
||||
assertReasonXml("<reason><security-error/></reason>",
|
||||
JingleReason.SecurityError);
|
||||
assertReasonXml("<reason><unsupported-applications/></reason>",
|
||||
JingleReason.UnsupportedApplications);
|
||||
assertReasonXml("<reason><timeout/></reason>",
|
||||
JingleReason.Timeout);
|
||||
assertReasonXml("<reason><failed-application/></reason>",
|
||||
JingleReason.FailedApplication);
|
||||
assertReasonXml("<reason><incompatible-parameters/></reason>",
|
||||
JingleReason.IncompatibleParameters);
|
||||
assertReasonXml("<reason><alternative-session><sid>1234</sid></alternative-session></reason>",
|
||||
JingleReason.AlternativeSession("1234"));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
private static void assertReasonXml(String expected, JingleReason reason) {
|
||||
String actualXml = reason.toXML(JingleReason.NAMESPACE).toString();
|
||||
assertEquals(expected, actualXml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alternativeSessionEmptyStringTest() {
|
||||
// Alternative sessionID must not be empty
|
||||
JingleReason.AlternativeSession("");
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
// Alternative sessionID must not be empty
|
||||
JingleReason.AlternativeSession("")
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void alternativeSessionNullStringTest() {
|
||||
// Alternative sessionID must not be null
|
||||
JingleReason.AlternativeSession(null);
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
// Alternative sessionID must not be null
|
||||
JingleReason.AlternativeSession(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void illegalArgumentTest() {
|
||||
JingleReason.Reason.fromString("illegal-reason");
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
JingleReason.Reason.fromString("illegal-reason")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue