1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +01:00

Merge branch '4.4'

This commit is contained in:
Florian Schmaus 2022-02-03 08:43:32 +01:00
commit ad9867ebdf
9 changed files with 208 additions and 64 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2021 Florian Schmaus
* Copyright 2017-2022 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -105,9 +105,17 @@ public class JingleReason implements XmlElement {
}
protected final Reason reason;
private final String text;
private final XmlElement element;
public JingleReason(Reason reason) {
this(reason, null, null);
}
public JingleReason(Reason reason, String text, XmlElement element) {
this.reason = reason;
this.text = text;
this.element = element;
}
@Override
@ -120,6 +128,26 @@ public class JingleReason implements XmlElement {
return NAMESPACE;
}
/**
* An optional text that provides human-readable information about the reason for the action.
*
* @return a human-readable text with information regarding this reason or <code>null</code>.
* @since 4.4.5
*/
public String getText() {
return text;
}
/**
* An optional element that provides more detailed machine-readable information about the reason for the action.
*
* @return an elemnet with machine-readable information about this reason or <code>null</code>.
* @since 4.4.5
*/
public XmlElement getElement() {
return element;
}
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
@ -142,7 +170,11 @@ public class JingleReason implements XmlElement {
private final String sessionId;
public AlternativeSession(String sessionId) {
super(Reason.alternative_session);
this(sessionId, null, null);
}
public AlternativeSession(String sessionId, String text, XmlElement element) {
super(Reason.alternative_session, text, element);
if (StringUtils.isNullOrEmpty(sessionId)) {
throw new NullPointerException("SessionID must not be null or empty.");
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2021 Florian Schmaus
* Copyright 2017-2022 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,10 +21,12 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.StandardExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
import org.jivesoftware.smack.provider.IqProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -76,16 +78,7 @@ public class JingleProvider extends IqProvider<Jingle> {
builder.addJingleContent(content);
break;
case JingleReason.ELEMENT:
parser.next();
String reasonString = parser.getName();
JingleReason reason;
if (reasonString.equals("alternative-session")) {
parser.next();
String sid = parser.nextText();
reason = new JingleReason.AlternativeSession(sid);
} else {
reason = new JingleReason(Reason.fromString(reasonString));
}
JingleReason reason = parseJingleReason(parser);
builder.setReason(reason);
break;
default:
@ -178,4 +171,57 @@ public class JingleProvider extends IqProvider<Jingle> {
return builder.build();
}
public static JingleReason parseJingleReason(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackParsingException {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
final String jingleNamespace = parser.getNamespace();
JingleReason.Reason reason = null;
XmlElement element = null;
String text = null;
// 'sid' is only set if the reason is 'alternative-session'.
String sid = null;
outerloop: while (true) {
XmlPullParser.TagEvent event = parser.nextTag();
switch (event) {
case START_ELEMENT:
String elementName = parser.getName();
String namespace = parser.getNamespace();
if (namespace.equals(jingleNamespace)) {
switch (elementName) {
case "text":
text = parser.nextText();
break;
case "alternative-session":
parser.next();
sid = parser.nextText();
break;
default:
reason = Reason.fromString(elementName);
break;
}
} else {
element = PacketParserUtils.parseExtensionElement(elementName, namespace, parser, null);
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
JingleReason res;
if (sid != null) {
res = new JingleReason.AlternativeSession(sid, text, element);
} else {
res = new JingleReason(reason, text, element);
}
return res;
}
}