Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
| 3 | * you may not use this file except in compliance with the License.
|
| 4 | * You may obtain a copy of the License at
|
| 5 | *
|
| 6 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 7 | *
|
| 8 | * Unless required by applicable law or agreed to in writing, software
|
| 9 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 11 | * See the License for the specific language governing permissions and
|
| 12 | * limitations under the License.
|
| 13 | */
|
| 14 | package org.jivesoftware.smackx.pubsub.provider;
|
| 15 |
|
| 16 | import org.jivesoftware.smack.packet.PacketExtension;
|
| 17 | import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
| 18 | import org.jivesoftware.smackx.pubsub.Subscription;
|
| 19 | import org.xmlpull.v1.XmlPullParser;
|
| 20 |
|
| 21 | /**
|
| 22 | * Parses the <b>subscription</b> element out of the pubsub IQ message from
|
| 23 | * the server as specified in the <a href="http://xmpp.org/extensions/xep-0060.html#schemas-pubsub">subscription schema</a>.
|
| 24 | *
|
| 25 | * @author Robin Collier
|
| 26 | */
|
| 27 | public class SubscriptionProvider implements PacketExtensionProvider
|
| 28 | {
|
| 29 | public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
| 30 | {
|
| 31 | String jid = parser.getAttributeValue(null, "jid");
|
| 32 | String nodeId = parser.getAttributeValue(null, "node");
|
| 33 | String subId = parser.getAttributeValue(null, "subid");
|
| 34 | String state = parser.getAttributeValue(null, "subscription");
|
| 35 | boolean isRequired = false;
|
| 36 |
|
| 37 | int tag = parser.next();
|
| 38 |
|
| 39 | if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options"))
|
| 40 | {
|
| 41 | tag = parser.next();
|
| 42 |
|
| 43 | if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))
|
| 44 | isRequired = true;
|
| 45 |
|
| 46 | while (parser.next() != XmlPullParser.END_TAG && parser.getName() != "subscribe-options");
|
| 47 | }
|
| 48 | while (parser.getEventType() != XmlPullParser.END_TAG) parser.next();
|
| 49 | return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired);
|
| 50 | }
|
| 51 |
|
| 52 | }
|