1 20 21 package org.jivesoftware.smackx.provider; 22 23 import org.jivesoftware.smack.packet.PacketExtension; 24 import org.jivesoftware.smack.provider.PacketExtensionProvider; 25 import org.jivesoftware.smackx.packet.DelayInformation; 26 import org.xmlpull.v1.XmlPullParser; 27 28 import java.text.ParseException ; 29 import java.text.SimpleDateFormat ; 30 import java.util.Date ; 31 import java.util.TimeZone ; 32 33 38 public class DelayInformationProvider implements PacketExtensionProvider { 39 40 45 public DelayInformationProvider() { 46 } 47 48 public PacketExtension parseExtension(XmlPullParser parser) throws Exception { 49 Date stamp = null; 50 try { 51 stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); 52 } catch (ParseException e) { 53 try { 56 stamp = DelayInformation.NEW_UTC_FORMAT 57 .parse(parser.getAttributeValue("", "stamp")); 58 } catch (ParseException e1) { 59 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'"); 61 formatter.setTimeZone(TimeZone.getTimeZone("UTC")); 62 stamp = formatter.parse(parser.getAttributeValue("", "stamp")); 63 } 64 } 65 DelayInformation delayInformation = new DelayInformation(stamp); 66 delayInformation.setFrom(parser.getAttributeValue("", "from")); 67 delayInformation.setReason(parser.nextText()); 68 return delayInformation; 69 } 70 71 } 72 | Popular Tags |