001/** 002 * 003 * Copyright 2003-2005 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.jingle.packet; 018 019import org.jivesoftware.smack.packet.PacketExtension; 020import org.jivesoftware.smackx.jingle.media.ContentInfo; 021 022/** 023 * Jingle content info 024 * 025 * @author Alvaro Saurin <alvaro.saurin@gmail.com> 026 */ 027public class JingleContentInfo implements PacketExtension { 028 029 protected ContentInfo mediaInfoElement; 030 031 private String namespace; 032 033 /** 034 * Empty constructor, with no jmf info. 035 */ 036 public JingleContentInfo() { 037 this(null); 038 } 039 040 /** 041 * Constructor with a jmf info 042 * 043 * @param mediaInfoElement MediaInfo element 044 */ 045 public JingleContentInfo(final ContentInfo mediaInfoElement) { 046 super(); 047 this.mediaInfoElement = mediaInfoElement; 048 } 049 050 /** 051 * Get the jmf info element. 052 * 053 * @return the mediaInfoElement 054 */ 055 public ContentInfo getMediaInfo() { 056 return mediaInfoElement; 057 } 058 059 /** 060 * Get the element name 061 */ 062 public String getElementName() { 063 // Media info is supposed to be just a single-word command... 064 return getMediaInfo().toString(); 065 } 066 067 /** 068 * Set the name space. 069 * 070 * @param ns the namespace 071 */ 072 protected void setNamespace(final String ns) { 073 namespace = ns; 074 } 075 076 /** 077 * Get the publilc namespace 078 */ 079 public String getNamespace() { 080 return namespace; 081 } 082 083 public String toXML() { 084 StringBuilder buf = new StringBuilder(); 085 buf.append("<").append(getElementName()).append(" xmlns=\""); 086 buf.append(getNamespace()).append("\" "); 087 buf.append("/>"); 088 return buf.toString(); 089 } 090 091 /** 092 * Transport part of a Jingle packet. 093 */ 094 public static class Audio extends JingleContentInfo { 095 096 public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp"; 097 098 public Audio(final ContentInfo mi) { 099 super(mi); 100 setNamespace(NAMESPACE); 101 } 102 103 public String getNamespace() { 104 return NAMESPACE; 105 } 106 107 // Subclasses: specialize the Audio jmf info... 108 109 /** 110 * Busy jmf info. 111 */ 112 public static class Busy extends Audio { 113 public Busy() { 114 super(ContentInfo.Audio.BUSY); 115 } 116 } 117 118 /** 119 * Hold jmf info. 120 */ 121 public static class Hold extends Audio { 122 public Hold() { 123 super(ContentInfo.Audio.HOLD); 124 } 125 } 126 127 /** 128 * Mute jmf info. 129 */ 130 public static class Mute extends Audio { 131 public Mute() { 132 super(ContentInfo.Audio.MUTE); 133 } 134 } 135 136 /** 137 * Queued jmf info. 138 */ 139 public static class Queued extends Audio { 140 public Queued() { 141 super(ContentInfo.Audio.QUEUED); 142 } 143 } 144 145 /** 146 * Ringing jmf info. 147 */ 148 public static class Ringing extends Audio { 149 public Ringing() { 150 super(ContentInfo.Audio.RINGING); 151 } 152 } 153 } 154}