Created
March 31, 2014 18:56
-
-
Save santiago26/9899556 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2014, Leonid Postovski <[email protected]> | |
*/ | |
package org.jivesoftware.smackx.packet; | |
import org.jivesoftware.smack.packet.PacketExtension; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Iterator; | |
import java.util.List; | |
/** | |
* Initial implementation of XEP-0301: RealTime Text | |
* | |
* @author Leonid Postovski | |
*/ | |
public class RTTExtension implements PacketExtension { | |
private List bodies = new ArrayList(); | |
private String seq = new String(); | |
private String event = new String(); | |
/** | |
* Returns the XML element name of the extension sub-packet root element. | |
* Always returns "rtt" | |
* | |
* @return the XML element name of the packet extension. | |
*/ | |
public String getElementName() { | |
return "rtt"; | |
} | |
/** | |
* Returns the XML namespace of the extension sub-packet root element. | |
* According the specification the namespace is always "urn:xmpp:rtt:0" | |
* | |
* @return the XML namespace of the packet extension. | |
*/ | |
public String getNamespace() { | |
return "urn:xmpp:rtt:0"; | |
public String getAttributes(String seq, String event ) { //stub | |
return "seq='".append(seq).append("' event='").append(event).append("'>"); | |
} | |
public void setAttributes(String seq, String event) { //stub | |
this.seq=seq; | |
this.event=event; | |
} | |
/** | |
* Returns the XML representation of a RTT extension according the specification. | |
* | |
* Usually the XML representation will be inside of a Message XML representation like | |
* in the following example: | |
* <pre> | |
* <to='[email protected]' from='[email protected]/orchard' type='chat' id='a01'> | |
* <rtt xmlns='urn:xmpp:rtt:0' seq='0' event='new'> | |
* <t>Hello, .</t> | |
* </rtt> | |
* </message> | |
* </pre> | |
* | |
* | |
*/ | |
public String toXML() { | |
StringBuilder buf = new StringBuilder(); | |
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(getAttributes).append( | |
"\">"); | |
// Loop through all the bodies and append them to the string buffer | |
for (Iterator i = getBodies(); i.hasNext();) { | |
buf.append((String) i.next()); | |
} | |
buf.append("</").append(getElementName()).append(">"); | |
return buf.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment