KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > packet > DelayInformation


1 /**
2  * $RCSfile$
3  * $Revision: 2516 $
4  * $Date: 2005-07-27 21:42:29 -0300 (Wed, 27 Jul 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.packet;
22
23 import java.text.SimpleDateFormat JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.TimeZone JavaDoc;
26
27 import org.jivesoftware.smack.packet.PacketExtension;
28
29 /**
30  * Represents timestamp information about data stored for later delivery. A DelayInformation will
31  * always includes the timestamp when the packet was originally sent and may include more
32  * information such as the JID of the entity that originally sent the packet as well as the reason
33  * for the dealy.<p>
34  *
35  * For more information see <a HREF="http://www.jabber.org/jeps/jep-0091.html">JEP-91</a>.
36  *
37  * @author Gaston Dombiak
38  */

39 public class DelayInformation implements PacketExtension {
40
41     public static SimpleDateFormat JavaDoc UTC_FORMAT = new SimpleDateFormat JavaDoc("yyyyMMdd'T'HH:mm:ss");
42     /**
43      * New date format based on JEP-82 that some clients may use when sending delayed dates.
44      * JEP-91 is using a SHOULD other servers or clients may be using this format instead of the
45      * old UTC format.
46      */

47     public static SimpleDateFormat JavaDoc NEW_UTC_FORMAT =
48             new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
49
50     static {
51         UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
52         NEW_UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
53     }
54
55     private Date JavaDoc stamp;
56     private String JavaDoc from;
57     private String JavaDoc reason;
58
59     /**
60      * Creates a new instance with the specified timestamp.
61      */

62     public DelayInformation(Date JavaDoc stamp) {
63         super();
64         this.stamp = stamp;
65     }
66
67     /**
68      * Returns the JID of the entity that originally sent the packet or that delayed the
69      * delivery of the packet or <tt>null</tt> if this information is not available.
70      *
71      * @return the JID of the entity that originally sent the packet or that delayed the
72      * delivery of the packet.
73      */

74     public String JavaDoc getFrom() {
75         return from;
76     }
77
78     /**
79      * Sets the JID of the entity that originally sent the packet or that delayed the
80      * delivery of the packet or <tt>null</tt> if this information is not available.
81      *
82      * @param from the JID of the entity that originally sent the packet.
83      */

84     public void setFrom(String JavaDoc from) {
85         this.from = from;
86     }
87
88     /**
89      * Returns the timstamp when the packet was originally sent. The returned Date is
90      * be understood as UTC.
91      *
92      * @return the timstamp when the packet was originally sent.
93      */

94     public Date JavaDoc getStamp() {
95         return stamp;
96     }
97
98     /**
99      * Returns a natural-language description of the reason for the delay or <tt>null</tt> if
100      * this information is not available.
101      *
102      * @return a natural-language description of the reason for the delay or <tt>null</tt>.
103      */

104     public String JavaDoc getReason() {
105         return reason;
106     }
107
108     /**
109      * Sets a natural-language description of the reason for the delay or <tt>null</tt> if
110      * this information is not available.
111      *
112      * @param reason a natural-language description of the reason for the delay or <tt>null</tt>.
113      */

114     public void setReason(String JavaDoc reason) {
115         this.reason = reason;
116     }
117
118     public String JavaDoc getElementName() {
119         return "x";
120     }
121
122     public String JavaDoc getNamespace() {
123         return "jabber:x:delay";
124     }
125
126     public String JavaDoc toXML() {
127         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
128         buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
129                 "\"");
130         buf.append(" stamp=\"").append(UTC_FORMAT.format(stamp)).append("\"");
131         if (from != null && from.length() > 0) {
132             buf.append(" from=\"").append(from).append("\"");
133         }
134         buf.append(">");
135         if (reason != null && reason.length() > 0) {
136             buf.append(reason);
137         }
138         buf.append("</").append(getElementName()).append(">");
139         return buf.toString();
140     }
141
142 }
143
Popular Tags