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 Last Activity packets
024     *
025     *@author     Andrey Zakirov
026     *@created    April 10, 2005
027     */
028    public class LastActivityProvider implements IQProvider {
029        /**
030         *  parses the packet
031         *
032         *@param  parser  the xml parser
033         *@return         the parsed IQ object
034         */
035        public IQ parseIQ(XmlPullParser parser) {
036            LastActivity a = new LastActivity();
037            a.setSeconds(parser.getAttributeValue("", "seconds"));
038    
039            try {
040                boolean done =false;
041                while (!done) {
042                    int eventType = parser.next();
043                    if (eventType == XmlPullParser.START_TAG) {
044                        if (parser.getName().equals("reason")) {
045                            a.setReason(parser.nextText());
046                        }
047                    }
048    
049                    else if (eventType == XmlPullParser.END_TAG) {
050                        if (parser.getName().equals("query")) {
051                            done = true;
052                        }
053                    }
054                }
055            }
056            catch( Exception ex )
057            {
058                com.valhalla.Logger.logException(ex);
059            }
060    
061            return a;
062        }
063    }
064