KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > provider > DelayInformationProvider


1 /**
2  * $RCSfile$
3  * $Revision: 2523 $
4  * $Date: 2005-08-10 18:55:09 -0300 (Wed, 10 Aug 2005) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

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 JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.TimeZone JavaDoc;
32
33 /**
34  * The DelayInformationProvider parses DelayInformation packets.
35  *
36  * @author Gaston Dombiak
37  */

38 public class DelayInformationProvider implements PacketExtensionProvider {
39
40     /**
41      * Creates a new DeliveryInformationProvider.
42      * ProviderManager requires that every PacketExtensionProvider has a public, no-argument
43      * constructor
44      */

45     public DelayInformationProvider() {
46     }
47
48     public PacketExtension parseExtension(XmlPullParser parser) throws Exception JavaDoc {
49         Date JavaDoc stamp = null;
50         try {
51             stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp"));
52         } catch (ParseException JavaDoc e) {
53             // Try again but assuming that the date follows JEP-82 format
54
// (Jabber Date and Time Profiles)
55
try {
56                 stamp = DelayInformation.NEW_UTC_FORMAT
57                         .parse(parser.getAttributeValue("", "stamp"));
58             } catch (ParseException JavaDoc e1) {
59                 // Last attempt. Try parsing the date assuming that it does not include milliseconds
60
SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("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