• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  *     http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 package org.jivesoftware.smackx.packet;
15 
16 import java.util.Date;
17 
18 import org.jivesoftware.smack.util.StringUtils;
19 
20 /**
21  * A decorator for the {@link DelayInformation} class to transparently support
22  * both the new <b>Delay Delivery</b> specification <a href="http://xmpp.org/extensions/xep-0203.html">XEP-0203</a> and
23  * the old one <a href="http://xmpp.org/extensions/xep-0091.html">XEP-0091</a>.
24  *
25  * Existing code can be backward compatible.
26  *
27  * @author Robin Collier
28  */
29 public class DelayInfo extends DelayInformation
30 {
31 
32 	DelayInformation wrappedInfo;
33 
34         /**
35          * Creates a new instance with given delay information.
36          * @param delay the delay information
37          */
DelayInfo(DelayInformation delay)38 	public DelayInfo(DelayInformation delay)
39 	{
40 		super(delay.getStamp());
41 		wrappedInfo = delay;
42 	}
43 
44 	@Override
getFrom()45 	public String getFrom()
46 	{
47 		return wrappedInfo.getFrom();
48 	}
49 
50 	@Override
getReason()51 	public String getReason()
52 	{
53 		return wrappedInfo.getReason();
54 	}
55 
56 	@Override
getStamp()57 	public Date getStamp()
58 	{
59 		return wrappedInfo.getStamp();
60 	}
61 
62 	@Override
setFrom(String from)63 	public void setFrom(String from)
64 	{
65 		wrappedInfo.setFrom(from);
66 	}
67 
68 	@Override
setReason(String reason)69 	public void setReason(String reason)
70 	{
71 		wrappedInfo.setReason(reason);
72 	}
73 
74 	@Override
getElementName()75 	public String getElementName()
76 	{
77 		return "delay";
78 	}
79 
80 	@Override
getNamespace()81 	public String getNamespace()
82 	{
83 		return "urn:xmpp:delay";
84 	}
85 
86 	@Override
toXML()87     public String toXML() {
88         StringBuilder buf = new StringBuilder();
89         buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
90                 "\"");
91         buf.append(" stamp=\"");
92         buf.append(StringUtils.formatXEP0082Date(getStamp()));
93         buf.append("\"");
94         if (getFrom() != null && getFrom().length() > 0) {
95             buf.append(" from=\"").append(getFrom()).append("\"");
96         }
97         buf.append(">");
98         if (getReason() != null && getReason().length() > 0) {
99             buf.append(getReason());
100         }
101         buf.append("</").append(getElementName()).append(">");
102         return buf.toString();
103     }
104 
105 }
106