1 20 21 package org.jivesoftware.smackx.packet; 22 23 import java.text.SimpleDateFormat ; 24 import java.util.Date ; 25 import java.util.TimeZone ; 26 27 import org.jivesoftware.smack.packet.PacketExtension; 28 29 41 public class MUCInitialPresence implements PacketExtension { 42 43 private String password; 44 private History history; 45 46 public String getElementName() { 47 return "x"; 48 } 49 50 public String getNamespace() { 51 return "http://jabber.org/protocol/muc"; 52 } 53 54 public String toXML() { 55 StringBuffer buf = new StringBuffer (); 56 buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( 57 "\">"); 58 if (getPassword() != null) { 59 buf.append("<password>").append(getPassword()).append("</password>"); 60 } 61 if (getHistory() != null) { 62 buf.append(getHistory().toXML()); 63 } 64 buf.append("</").append(getElementName()).append(">"); 65 return buf.toString(); 66 } 67 68 75 public History getHistory() { 76 return history; 77 } 78 79 84 public String getPassword() { 85 return password; 86 } 87 88 95 public void setHistory(History history) { 96 this.history = history; 97 } 98 99 104 public void setPassword(String password) { 105 this.password = password; 106 } 107 108 114 public static class History { 115 116 private int maxChars = -1; 117 private int maxStanzas = -1; 118 private int seconds = -1; 119 private Date since; 120 121 126 public int getMaxChars() { 127 return maxChars; 128 } 129 130 135 public int getMaxStanzas() { 136 return maxStanzas; 137 } 138 139 146 public int getSeconds() { 147 return seconds; 148 } 149 150 157 public Date getSince() { 158 return since; 159 } 160 161 166 public void setMaxChars(int maxChars) { 167 this.maxChars = maxChars; 168 } 169 170 175 public void setMaxStanzas(int maxStanzas) { 176 this.maxStanzas = maxStanzas; 177 } 178 179 187 public void setSeconds(int seconds) { 188 this.seconds = seconds; 189 } 190 191 198 public void setSince(Date since) { 199 this.since = since; 200 } 201 202 public String toXML() { 203 StringBuffer buf = new StringBuffer (); 204 buf.append("<history"); 205 if (getMaxChars() != -1) { 206 buf.append(" maxchars=\"").append(getMaxChars()).append("\""); 207 } 208 if (getMaxStanzas() != -1) { 209 buf.append(" maxstanzas=\"").append(getMaxStanzas()).append("\""); 210 } 211 if (getSeconds() != -1) { 212 buf.append(" seconds=\"").append(getSeconds()).append("\""); 213 } 214 if (getSince() != null) { 215 SimpleDateFormat utcFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 216 utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); 217 buf.append(" since=\"").append(utcFormat.format(getSince())).append("\""); 218 } 219 buf.append("/>"); 220 return buf.toString(); 221 } 222 } 223 } 224 | Popular Tags |