mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-07 11:31:10 +01:00
Add support for <text/> elements in SM's <failed/> element
Also introduce AbstractTextElement and StanzaErrorTextElement. Fixes SMACK-760.
This commit is contained in:
parent
1448fa4632
commit
813219179f
5 changed files with 158 additions and 13 deletions
|
|
@ -16,8 +16,12 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.sm.packet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Nonza;
|
||||
import org.jivesoftware.smack.packet.StanzaErrorTextElement;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
|
@ -189,30 +193,46 @@ public class StreamManagement {
|
|||
public static class Failed implements Nonza {
|
||||
public static final String ELEMENT = "failed";
|
||||
|
||||
private XMPPError.Condition condition;
|
||||
private final XMPPError.Condition condition;
|
||||
|
||||
private final List<StanzaErrorTextElement> textElements;
|
||||
|
||||
|
||||
public Failed() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public Failed(XMPPError.Condition condition) {
|
||||
public Failed(XMPPError.Condition condition, List<StanzaErrorTextElement> textElements) {
|
||||
this.condition = condition;
|
||||
if (textElements == null) {
|
||||
this.textElements = Collections.emptyList();
|
||||
} else {
|
||||
this.textElements = Collections.unmodifiableList(textElements);
|
||||
}
|
||||
}
|
||||
|
||||
public XMPPError.Condition getXMPPErrorCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public List<StanzaErrorTextElement> getTextElements() {
|
||||
return textElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
if (condition != null) {
|
||||
xml.rightAngleBracket();
|
||||
xml.append(condition.toString());
|
||||
xml.xmlnsAttribute(XMPPError.NAMESPACE);
|
||||
xml.closeElement(ELEMENT);
|
||||
}
|
||||
else {
|
||||
if (condition == null && textElements.isEmpty()) {
|
||||
xml.closeEmptyElement();
|
||||
} else {
|
||||
xml.rightAngleBracket();
|
||||
if (condition != null) {
|
||||
// TODO This should use StanzaError (formerly XMPPError) in Smack 4.3 (see SMACK-769)
|
||||
xml.append(condition.toString());
|
||||
xml.xmlnsAttribute(XMPPError.NAMESPACE);
|
||||
}
|
||||
xml.append(textElements);
|
||||
xml.closeElement(ELEMENT);
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@
|
|||
package org.jivesoftware.smack.sm.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.AbstractTextElement;
|
||||
import org.jivesoftware.smack.packet.StanzaErrorTextElement;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.sm.packet.StreamManagement.AckAnswer;
|
||||
import org.jivesoftware.smack.sm.packet.StreamManagement.AckRequest;
|
||||
|
|
@ -46,6 +50,7 @@ public class ParseStreamManagement {
|
|||
ParserUtils.assertAtStartTag(parser);
|
||||
String name;
|
||||
XMPPError.Condition condition = null;
|
||||
List<StanzaErrorTextElement> textElements = new ArrayList<>(4);
|
||||
outerloop:
|
||||
while (true) {
|
||||
int event = parser.next();
|
||||
|
|
@ -54,7 +59,14 @@ public class ParseStreamManagement {
|
|||
name = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
if (XMPPError.NAMESPACE.equals(namespace)) {
|
||||
condition = XMPPError.Condition.fromString(name);
|
||||
if (name.equals(AbstractTextElement.ELEMENT)) {
|
||||
String lang = ParserUtils.getXmlLang(parser);
|
||||
String text = parser.nextText();
|
||||
StanzaErrorTextElement stanzaErrorTextElement = new StanzaErrorTextElement(text, lang);
|
||||
textElements.add(stanzaErrorTextElement);
|
||||
} else {
|
||||
condition = XMPPError.Condition.fromString(name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
|
|
@ -66,7 +78,7 @@ public class ParseStreamManagement {
|
|||
}
|
||||
}
|
||||
ParserUtils.assertAtEndTag(parser);
|
||||
return new Failed(condition);
|
||||
return new Failed(condition, textElements);
|
||||
}
|
||||
|
||||
public static Resumed resumed(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue