001/** 002 * 003 * Copyright 2016 Fernando Ramirez 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.blocking.provider; 018 019import java.io.IOException; 020import java.util.ArrayList; 021import java.util.List; 022 023import org.jivesoftware.smack.packet.IqData; 024import org.jivesoftware.smack.packet.XmlEnvironment; 025import org.jivesoftware.smack.provider.IqProvider; 026import org.jivesoftware.smack.xml.XmlPullParser; 027import org.jivesoftware.smack.xml.XmlPullParserException; 028 029import org.jivesoftware.smackx.blocking.element.UnblockContactsIQ; 030 031import org.jxmpp.jid.Jid; 032import org.jxmpp.jid.impl.JidCreate; 033 034/** 035 * Unblock contact IQ provider class. 036 * 037 * @author Fernando Ramirez 038 * @see <a href="http://xmpp.org/extensions/xep-0191.html">XEP-0191: Blocking 039 * Command</a> 040 */ 041public class UnblockContactsIQProvider extends IqProvider<UnblockContactsIQ> { 042 043 @Override 044 public UnblockContactsIQ parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { 045 List<Jid> jids = null; 046 047 outerloop: while (true) { 048 XmlPullParser.Event eventType = parser.next(); 049 switch (eventType) { 050 case START_ELEMENT: 051 if (parser.getName().equals("item")) { 052 if (jids == null) { 053 jids = new ArrayList<>(); 054 } 055 jids.add(JidCreate.from(parser.getAttributeValue("", "jid"))); 056 } 057 break; 058 059 case END_ELEMENT: 060 if (parser.getDepth() == initialDepth) { 061 break outerloop; 062 } 063 break; 064 065 default: 066 // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. 067 break; 068 } 069 } 070 071 return new UnblockContactsIQ(jids); 072 } 073 074}