1 import org.jivesoftware.smack.provider.IQProvider; 2 import org.jivesoftware.smack.packet.DefaultPacketExtension; 3 import org.jivesoftware.smack.packet.IQ; 4 import org.jivesoftware.smack.provider.ProviderManager; 5 6 7 public final class SearchIQProvider implements IQProvider{ 8 9 10 public SearchIQProvider(){ 11 } 13 14 15 public static void install(){ 16 ProviderManager.addIQProvider("query","jabber:iq:search",new SearchIQProvider()); 17 } 18 19 23 public IQ parseIQ(org.xmlpull.v1.XmlPullParser parser) throws Exception { 24 SearchIQ result=new SearchIQ(); 25 26 DefaultPacketExtension item=null; 27 String currentTag=null; 28 String currentValue=null; 29 String key=null; 30 int event=parser.getEventType(); 31 while (!(event==parser.END_TAG && parser.getName().equals("query"))){ 32 if(event==parser.START_TAG){ 33 if(item==null && parser.getName().equals("item") && (!parser.isEmptyElementTag())){ 34 item=new DefaultPacketExtension("item",""); 35 key=parser.getAttributeValue(0); 36 currentTag=null; 37 } 38 else{ 39 currentTag=parser.getName(); 40 if(item==null && parser.isEmptyElementTag()){ 41 if(!currentTag.equals("instructions")){ 42 result.addField(currentTag); 43 currentTag=null; 44 } 45 } 46 } 47 } 48 if(event==parser.TEXT && currentTag!=null){ 49 if(item!=null){ 50 item.setValue(currentTag,parser.getText()); 51 } 52 else{ 53 if(!currentTag.equals("instructions")){ 54 result.setField(currentTag,parser.getText()); 55 } 56 else{ 57 result.setInstructions(parser.getText()); 58 } 59 } 60 currentTag=null; 61 } 62 if(event==parser.END_TAG && parser.getName().equals("item") && item!=null){ 63 result.addItem(key,item); 64 item=null; 65 } 66 event=parser.next(); 67 } 68 return result; 69 } 70 } | Popular Tags |