diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/AbstractPacketExtension.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/AbstractPacketExtension.java new file mode 100644 index 000000000..89b890343 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/AbstractPacketExtension.java @@ -0,0 +1,135 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.jabber.extensions; + +import java.util.*; + +import org.jivesoftware.smack.packet.*; + +/** + * A generic implementation of PacketExtension. The purpose of this + * class is quite similar to that of smack's {@link DefaultPacketExtension} + * with the main difference being that this one is meant primarily for + * extension rather than using as a fallback for unknown elements. We let for + * example our descendants handle child elements and we automate attribute + * handling instead. + * + * @author Emil Ivov + */ +public abstract class AbstractPacketExtension + implements PacketExtension +{ + /** + * The name space of this packet extension. Should remain null if + * there's no namespace associated with this element. + */ + private final String namespace; + + /** + * The name space of this packet extension. Should remain null if + * there's no namespace associated with this element. + */ + private final String elementName; + + /** + * A map of all attributes that this extension is currently using. + */ + private final Map attributes + = new LinkedHashMap(); + + /** + * Creates an {@link AbstractPacketExtension} instance for the specified + * namespace and elementName. + * + * @param namespace the XML namespace for this element. + * @param elementName the name of the element + */ + protected AbstractPacketExtension(String namespace, String elementName) + { + this.namespace = namespace; + this.elementName = elementName; + } + + /** + * Returns the name of the encryption element. + * + * @return the name of the encryption element. + */ + public String getElementName() + { + return elementName; + } + + /** + * Returns the XML namespace for this element or null if the + * element does not live in a namespace of its own. + * + * @return the XML namespace for this element or null if the + * element does not live in a namespace of its own. + */ + public String getNamespace() + { + return namespace; + } + + /** + * Returns an XML representation of this extension. + * + * @return an XML representation of this extension. + */ + public String toXML() + { + StringBuilder bldr = new StringBuilder("<" + getElementName() + " "); + + if(getNamespace() != null) + bldr.append("xmlns='" + getNamespace() + "'"); + + //add the rest of the attributes if any + for() + + //add child elements if any + List childElements = getChildElements(); + + if(childElements == null || childElements.size() == 0) + bldr.append("/>"); + else + { + for(PacketExtension packExt : childElements) + { + bldr.append(packExt.toXML()); + } + + bldr.append(""); + } + + return bldr.toString(); + } + + /** + * Returns all sub-elements for this AbstractPacketExtension or + * null if there aren't any. + * + * @return the {@link List} of elements that this packet extension contains. + */ + public abstract List getChildElements(); + + /** + * Sets the value of the attribute named name to value. + * + * @param name the name of the attribute that we are setting. + * @param value an {@link Object} whose toString() method returns + * the XML value of the attribute we are setting. + */ + protected void setAttribtue(String name, Object value) + { + synchronized(attributes) + { + this.attributes.put(name, value); + } + } + +} diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/CryptoPacketExtension.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/CryptoPacketExtension.java new file mode 100644 index 000000000..78df21b15 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/CryptoPacketExtension.java @@ -0,0 +1,66 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.jabber.extensions.jingle; + +import org.jivesoftware.smack.packet.*; + +/** + * The element containing details about an encryption algorithm that could be + * used during a jingle session. + * + * @author Emil Ivov + */ +public class CryptoPacketExtension + implements PacketExtension +{ + /** + * There's no namespace for the crypto element itself. + */ + public static final String NAMESPACE = null; + + /** + * The name of the "crypto" element. + */ + public static final String ELEMENT_NAME = "crypto"; + + /** + * Returns the name of the encryption element. + * + * @return the name of the encryption element. + */ + public String getElementName() + { + return ELEMENT_NAME; + } + + /** + * Returns null since there's no encryption specific ns. + * + * @return null since there's no encryption specific ns. + */ + public String getNamespace() + { + return NAMESPACE; + } + + /** + * Returns the XML representation of this description packet + * extension including all child elements. + * + * @return this packet extension as an XML String. + */ + public String toXML() + { + StringBuilder bldr = new StringBuilder( + "<" + ELEMENT_NAME+ " "); + + + bldr.append(""); + return bldr.toString(); + } + +} diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/EncryptionPacketExtension.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/EncryptionPacketExtension.java index 31e6ce2b5..3bbe2495c 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/EncryptionPacketExtension.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle/EncryptionPacketExtension.java @@ -22,7 +22,7 @@ public class EncryptionPacketExtension /** * There's no namespace for the encryption element itself. */ - public static final String NAMESPACE = ""; + public static final String NAMESPACE = null; /** * The name of the "encryption" element.