2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* 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.pubsub.provider;
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2018-03-21 14:47:22 +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-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.pubsub.Subscription;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2018-03-21 14:47:22 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2017-12-13 23:10:11 +01:00
|
|
|
* Parses the <b>subscription</b> element out of the PubSub IQ message from
|
2014-02-17 23:58:40 +01:00
|
|
|
* the server as specified in the <a href="http://xmpp.org/extensions/xep-0060.html#schemas-pubsub">subscription schema</a>.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Robin Collier
|
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public class SubscriptionProvider extends ExtensionElementProvider<Subscription> {
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public Subscription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
2014-10-07 21:15:20 +02:00
|
|
|
throws XmlPullParserException, IOException {
|
2018-03-21 14:47:22 +01:00
|
|
|
Jid jid = ParserUtils.getJidAttribute(parser);
|
2017-02-07 22:02:40 +01:00
|
|
|
String nodeId = parser.getAttributeValue(null, "node");
|
|
|
|
String subId = parser.getAttributeValue(null, "subid");
|
|
|
|
String state = parser.getAttributeValue(null, "subscription");
|
|
|
|
boolean isRequired = false;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event tag = parser.next();
|
2017-02-07 22:02:40 +01:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("subscribe-options")) {
|
2017-02-07 22:02:40 +01:00
|
|
|
tag = parser.next();
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("required"))
|
2017-02-07 22:02:40 +01:00
|
|
|
isRequired = true;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
while (tag != XmlPullParser.Event.END_ELEMENT && !parser.getName().equals("subscribe-options")) tag = parser.next();
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
while (parser.getEventType() != XmlPullParser.Event.END_ELEMENT) parser.next();
|
2019-07-24 09:18:39 +02:00
|
|
|
return new Subscription(jid, nodeId, subId, state == null ? null : Subscription.State.valueOf(state), isRequired);
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
}
|