001 /* 002 Copyright (C) 2003 Adam Olsen 003 This program is free software; you can redistribute it and/or modify 004 it under the terms of the GNU General Public License as published by 005 the Free Software Foundation; either version 1, or (at your option) 006 any later version. 007 This program is distributed in the hope that it will be useful, 008 but WITHOUT ANY WARRANTY; without even the implied warranty of 009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 010 GNU General Public License for more details. 011 You should have received a copy of the GNU General Public License 012 along with this program; if not, write to the Free Software 013 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 014 */ 015 package com.valhalla.jbother.jabber.smack.provider; 016 017 import org.jivesoftware.smack.provider.IQProvider; 018 import org.jivesoftware.smack.packet.*; 019 import com.valhalla.jbother.jabber.smack.*; 020 import org.xmlpull.v1.XmlPullParser; 021 022 /** 023 * Parses Version packets 024 * 025 * @author synic 026 * @created October 30, 2004 027 */ 028 public class VersionProvider implements IQProvider 029 { 030 /** 031 * parses the packet 032 * 033 * @param parser the xml parser 034 * @return the parsed IQ object 035 */ 036 public IQ parseIQ( XmlPullParser parser ) 037 { 038 Version v = new Version(); 039 boolean done = false; 040 041 try 042 { 043 while( !done ) 044 { 045 int eventType = parser.next(); 046 if( eventType == XmlPullParser.START_TAG ) 047 { 048 if( parser.getName().equals( "os" ) ) 049 { 050 v.setOs( parser.nextText() ); 051 } 052 else if( parser.getName().equals( "version" ) ) 053 { 054 v.setVersion( parser.nextText() ); 055 } 056 else if( parser.getName().equals( "name" ) ) 057 { 058 v.setName( parser.nextText() ); 059 } 060 } 061 else if( eventType == XmlPullParser.END_TAG ) 062 { 063 if( parser.getName().equals( "query" ) ) 064 { 065 done = true; 066 } 067 } 068 } 069 } 070 catch( Exception e ) 071 { 072 com.valhalla.Logger.debug( "Smack error reading version information." ); 073 } 074 075 return v; 076 } 077 } 078