mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 14:01:08 +01: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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue