001/** 002 * 003 * Copyright the original author or authors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.delay.packet; 018 019import java.util.Date; 020 021import org.jivesoftware.smack.util.XmppDateTime; 022 023/** 024 * A decorator for the {@link DelayInformation} class to transparently support 025 * both the new <b>Delay Delivery</b> specification <a href="http://xmpp.org/extensions/xep-0203.html">XEP-0203</a> and 026 * the old one <a href="http://xmpp.org/extensions/xep-0091.html">XEP-0091</a>. 027 * 028 * Existing code can be backward compatible. 029 * 030 * @author Robin Collier 031 */ 032public class DelayInfo extends DelayInformation 033{ 034 035 DelayInformation wrappedInfo; 036 037 /** 038 * Creates a new instance with given delay information. 039 * @param delay the delay information 040 */ 041 public DelayInfo(DelayInformation delay) 042 { 043 super(delay.getStamp()); 044 wrappedInfo = delay; 045 } 046 047 @Override 048 public String getFrom() 049 { 050 return wrappedInfo.getFrom(); 051 } 052 053 @Override 054 public String getReason() 055 { 056 return wrappedInfo.getReason(); 057 } 058 059 @Override 060 public Date getStamp() 061 { 062 return wrappedInfo.getStamp(); 063 } 064 065 @Override 066 public void setFrom(String from) 067 { 068 wrappedInfo.setFrom(from); 069 } 070 071 @Override 072 public void setReason(String reason) 073 { 074 wrappedInfo.setReason(reason); 075 } 076 077 @Override 078 public String getElementName() 079 { 080 return "delay"; 081 } 082 083 @Override 084 public String getNamespace() 085 { 086 return "urn:xmpp:delay"; 087 } 088 089 @Override 090 public String toXML() { 091 StringBuilder buf = new StringBuilder(); 092 buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( 093 "\""); 094 buf.append(" stamp=\""); 095 buf.append(XmppDateTime.formatXEP0082Date(getStamp())); 096 buf.append("\""); 097 if (getFrom() != null && getFrom().length() > 0) { 098 buf.append(" from=\"").append(getFrom()).append("\""); 099 } 100 buf.append(">"); 101 if (getReason() != null && getReason().length() > 0) { 102 buf.append(getReason()); 103 } 104 buf.append("</").append(getElementName()).append(">"); 105 return buf.toString(); 106 } 107 108}