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 org.jivesoftware.smackx.packet.Time; 020 import org.xmlpull.v1.XmlPullParser; 021 022 /** 023 * Parses jabber:iq:time IQ packets 024 * 025 * @author synic 026 * @created October 30, 2004 027 */ 028 public class TimeProvider implements IQProvider 029 { 030 /** 031 * Parses the IQ XML 032 * 033 * @param parser the xml parser 034 * @return the IQ packet 035 * @exception Exception if an error occurs while parsing the XML 036 */ 037 public IQ parseIQ( XmlPullParser parser ) 038 throws Exception 039 { 040 Time t = new Time(); 041 boolean done = false; 042 043 while( !done ) 044 { 045 int eventType = parser.next(); 046 if( eventType == XmlPullParser.START_TAG ) 047 { 048 if( parser.getName().equals( "utc" ) ) 049 { 050 t.setUtc( parser.nextText() ); 051 } 052 else if( parser.getName().equals( "tz" ) ) 053 { 054 t.setTz( parser.nextText() ); 055 } 056 else if( parser.getName().equals( "display" ) ) 057 { 058 t.setDisplay( parser.nextText() ); 059 } 060 061 } 062 else if( eventType == XmlPullParser.END_TAG ) 063 { 064 if( parser.getName().equals( "query" ) ) 065 { 066 done = true; 067 } 068 } 069 } 070 071 return t; 072 } 073 } 074