1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-08 06:01:07 +01:00

Updated Jingle implementation. SMACK-240. Thanks to Jeff Williams.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10419 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2008-05-21 04:35:42 +00:00 committed by gato
parent 1cbfdcc7db
commit 646271abac
12 changed files with 1199 additions and 0 deletions

View file

@ -0,0 +1,186 @@
/**
* $RCSfile: JingleContent.java,v $
* $Revision: 1.2 $
* $Date: 2007/07/02 22:45:36 $
*
* Copyright 2003-2005 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.packet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.PacketExtension;
/**
* Jingle content.
*
* @author Jeff Williams
*/
public class JingleContent implements PacketExtension {
public static final String NODENAME = "content";
public static final String CREATOR = "creator";
public static final String NAME = "name";
private String creator;
private String name;
private JingleDescription description;
private final List<JingleTransport> transports = new ArrayList<JingleTransport>();
/**
* Creates a content description..
*/
public JingleContent(String creator, String name) {
super();
this.creator = creator;
this.name = name;
}
public String getCreator() {
return creator;
}
public String getName() {
return name;
}
/**
* Returns the XML element name of the element.
*
* @return the XML element name of the element.
*/
public String getElementName() {
return NODENAME;
}
/**
* Return the namespace.
*
* @return The namespace
*/
public String getNamespace() {
// There is no namespace for <content>
return "";
}
/**
* Sets the description for this Jingle content.
*
* @param description
* The description
*/
public void setDescription(JingleDescription description) {
this.description = description;
}
/**
* Gets the description for this Jingle content.
*
* @return The description.
*/
public JingleDescription getDescription() {
return description;
}
/**
* Adds a JingleTransport type to the packet.
*
* @param transport
* the JignleTransport to add.
*/
public void addJingleTransport(final JingleTransport transport) {
synchronized (transports) {
transports.add(transport);
}
}
/**
* Adds a list of transports to add to the packet.
*
* @param transports
* the transports to add.
*/
public void addTransports(final List<JingleTransport> transports) {
synchronized (transports) {
for (JingleTransport transport : transports) {
addJingleTransport(transport);
}
}
}
/**
* Returns an Iterator for the JingleTransports in the packet.
*
* @return an Iterator for the JingleTransports in the packet.
*/
public Iterator<JingleTransport> getJingleTransports() {
return Collections.unmodifiableList(getJingleTransportsList()).iterator();
}
/**
* Returns a list for the JingleTransports in the packet.
*
* @return a list for the JingleTransports in the packet.
*/
public List<JingleTransport> getJingleTransportsList() {
synchronized (transports) {
return new ArrayList<JingleTransport>(transports);
}
}
/**
* Returns a count of the JingleTransports in the Jingle packet.
*
* @return the number of the JingleTransports in the Jingle packet.
*/
public int getJingleTransportsCount() {
synchronized (transports) {
return transports.size();
}
}
/**
* Convert a Jingle description to XML.
*
* @return a string with the XML representation
*/
public String toXML() {
StringBuilder buf = new StringBuilder();
synchronized (transports) {
buf.append("<").append(getElementName());
buf.append(" creator='" + creator + "' name='" + name + "'>");
// Add the description.
if (description != null) {
buf.append(description.toXML());
}
// Add all of the transports.
for (JingleTransport transport : transports) {
buf.append(transport.toXML());
}
buf.append("</").append(getElementName()).append(">");
}
return buf.toString();
}
}

View file

@ -0,0 +1,197 @@
/**
* $RCSfile: JingleDescription.java,v $
* $Revision: 1.1 $
* $Date: 2007/07/02 17:41:08 $
*
* Copyright 2003-2005 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Jingle content description.
*
* @author Alvaro Saurin <alvaro.saurin@gmail.com>
*/
public abstract class JingleDescription implements PacketExtension {
// static
public static final String NODENAME = "description";
// non-static
private final List<PayloadType> payloads = new ArrayList<PayloadType>();
/**
* Creates a content description..
*/
public JingleDescription() {
super();
}
/**
* Returns the XML element name of the element.
*
* @return the XML element name of the element.
*/
public String getElementName() {
return NODENAME;
}
/**
* Return the namespace.
*
* @return The namespace
*/
public abstract String getNamespace();
/**
* Adds a audio payload type to the packet.
*
* @param pt the audio payload type to add.
*/
public void addPayloadType(final PayloadType pt) {
synchronized (payloads) {
if (pt == null) {
System.err.println("Null payload type");
} else {
payloads.add(pt);
}
}
}
/**
* Adds a list of payloads to the packet.
*
* @param pts the payloads to add.
*/
public void addAudioPayloadTypes(final List<PayloadType> pts) {
synchronized (payloads) {
Iterator ptIter = pts.iterator();
while (ptIter.hasNext()) {
PayloadType.Audio pt = (PayloadType.Audio) ptIter.next();
addPayloadType(new PayloadType.Audio(pt));
}
}
}
/**
* Returns an Iterator for the audio payloads in the packet.
*
* @return an Iterator for the audio payloads in the packet.
*/
public Iterator<PayloadType> getPayloadTypes() {
return Collections.unmodifiableList(getPayloadTypesList()).iterator();
}
/**
* Returns a list for the audio payloads in the packet.
*
* @return a list for the audio payloads in the packet.
*/
public List<PayloadType> getPayloadTypesList() {
synchronized (payloads) {
return new ArrayList<PayloadType>(payloads);
}
}
/**
* Return the list of Payload types contained in the description.
*
* @return a list of PayloadType.Audio
*/
public List<PayloadType> getAudioPayloadTypesList() {
ArrayList<PayloadType> result = new ArrayList<PayloadType>();
Iterator<PayloadType> jinglePtsIter = getPayloadTypes();
while (jinglePtsIter.hasNext()) {
PayloadType jpt = (PayloadType) jinglePtsIter.next();
if (jpt instanceof PayloadType.Audio) {
PayloadType.Audio jpta = (PayloadType.Audio) jpt;
result.add(jpta);
}
}
return result;
}
/**
* Returns a count of the audio payloads in the Jingle packet.
*
* @return the number of audio payloads in the Jingle packet.
*/
public int getPayloadTypesCount() {
synchronized (payloads) {
return payloads.size();
}
}
/**
* Convert a Jingle description to XML.
*
* @return a string with the XML representation
*/
public String toXML() {
StringBuilder buf = new StringBuilder();
synchronized (payloads) {
if (payloads.size() > 0) {
buf.append("<").append(getElementName());
buf.append(" xmlns=\"").append(getNamespace()).append("\" >");
for (PayloadType payloadType : payloads) {
if (payloadType != null) {
buf.append(payloadType.toXML());
}
}
buf.append("</").append(getElementName()).append(">");
}
}
return buf.toString();
}
/**
* Jingle audio description
*/
public static class Audio extends JingleDescription {
public static final String NAMESPACE = "http://www.xmpp.org/extensions/xep-0167.html#ns";
public Audio() {
super();
}
/**
* Utility constructor, with a PayloadType
*/
public Audio(final PayloadType pt) {
super();
addPayloadType(pt);
}
public String getNamespace() {
return NAMESPACE;
}
}
}