2014-07-14 19:22:02 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.muc.provider;
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jivesoftware.smack.util.ParserUtils;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-08-24 18:30:18 +02:00
|
|
|
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
|
|
|
import org.jivesoftware.smackx.muc.MUCRole;
|
2014-07-14 19:22:02 +02:00
|
|
|
import org.jivesoftware.smackx.muc.packet.Destroy;
|
|
|
|
import org.jivesoftware.smackx.muc.packet.MUCItem;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-05-27 19:29:51 +02:00
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
2014-07-14 19:22:02 +02:00
|
|
|
|
|
|
|
public class MUCParserUtils {
|
2014-10-07 21:15:20 +02:00
|
|
|
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
|
2014-08-24 18:30:18 +02:00
|
|
|
int initialDepth = parser.getDepth();
|
|
|
|
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
|
2015-02-14 17:15:02 +01:00
|
|
|
Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
|
2014-08-24 18:30:18 +02:00
|
|
|
MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
|
2015-02-14 17:15:02 +01:00
|
|
|
Jid jid = ParserUtils.getJidAttribute(parser);
|
|
|
|
Jid actor = null;
|
2015-09-28 13:05:06 +02:00
|
|
|
Resourcepart actorNick = null;
|
2014-08-24 18:30:18 +02:00
|
|
|
String reason = null;
|
|
|
|
outerloop: while (true) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
2014-08-24 18:30:18 +02:00
|
|
|
switch (eventType) {
|
2019-05-06 22:06:13 +02:00
|
|
|
case START_ELEMENT:
|
2014-08-24 18:30:18 +02:00
|
|
|
String name = parser.getName();
|
|
|
|
switch (name) {
|
|
|
|
case "actor":
|
2015-02-14 17:15:02 +01:00
|
|
|
actor = ParserUtils.getJidAttribute(parser);
|
2015-09-28 13:05:06 +02:00
|
|
|
// TODO change to
|
|
|
|
// actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
|
|
|
|
// once a newer version of JXMPP is used that supports from(null).
|
|
|
|
String actorNickString = parser.getAttributeValue("", "nick");
|
|
|
|
if (actorNickString != null) {
|
|
|
|
actorNick = Resourcepart.from(actorNickString);
|
|
|
|
}
|
2014-08-24 18:30:18 +02:00
|
|
|
break;
|
|
|
|
case "reason":
|
|
|
|
reason = parser.nextText();
|
|
|
|
break;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
2015-03-23 09:27:15 +01:00
|
|
|
break;
|
2019-05-06 22:06:13 +02:00
|
|
|
case END_ELEMENT:
|
2014-08-24 18:30:18 +02:00
|
|
|
if (parser.getDepth() == initialDepth) {
|
|
|
|
break outerloop;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
2014-08-24 18:30:18 +02:00
|
|
|
break;
|
2019-05-06 22:06:13 +02:00
|
|
|
default:
|
|
|
|
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
|
|
|
break;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-28 13:05:06 +02:00
|
|
|
return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
public static Destroy parseDestroy(XmlPullParser parser) throws XmlPullParserException, IOException {
|
2015-03-11 21:31:37 +01:00
|
|
|
final int initialDepth = parser.getDepth();
|
2015-05-27 19:29:51 +02:00
|
|
|
final EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
|
2015-03-11 21:31:37 +01:00
|
|
|
String reason = null;
|
|
|
|
outerloop: while (true) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
2015-03-11 21:31:37 +01:00
|
|
|
switch (eventType) {
|
2019-05-06 22:06:13 +02:00
|
|
|
case START_ELEMENT:
|
2015-03-11 21:31:37 +01:00
|
|
|
final String name = parser.getName();
|
|
|
|
switch (name) {
|
|
|
|
case "reason":
|
|
|
|
reason = parser.nextText();
|
|
|
|
break;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
2015-03-11 21:31:37 +01:00
|
|
|
break;
|
2019-05-06 22:06:13 +02:00
|
|
|
case END_ELEMENT:
|
2015-03-11 21:31:37 +01:00
|
|
|
if (initialDepth == parser.getDepth()) {
|
|
|
|
break outerloop;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
2015-03-11 21:31:37 +01:00
|
|
|
break;
|
2019-05-06 22:06:13 +02:00
|
|
|
default:
|
|
|
|
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
|
|
|
break;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-11 21:31:37 +01:00
|
|
|
return new Destroy(jid, reason);
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
}
|