Skip to content

Instantly share code, notes, and snippets.

@santiago26
Created March 31, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santiago26/9899556 to your computer and use it in GitHub Desktop.
Save santiago26/9899556 to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2014, Leonid Postovski <leonid@postovski.info>
*/
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>
* &lt;to='juliet@capulet.lit' from='romeo@montague.lit/orchard' type='chat' id='a01'&gt;
* &lt;rtt xmlns='urn:xmpp:rtt:0' seq='0' event='new'&gt;
* &lt;t&gt;Hello, .&lt;/t&gt;
* &lt;/rtt&gt;
* &lt;/message&gt;
* </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