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.jingleold.packet;
018
019import org.jivesoftware.smack.packet.ExtensionElement;
020
021import org.jivesoftware.smackx.jingleold.media.ContentInfo;
022
023/**
024 * Jingle content info.
025 *
026 * @author Alvaro Saurin
027 */
028public class JingleContentInfo implements ExtensionElement {
029
030    protected ContentInfo mediaInfoElement;
031
032    private String namespace;
033
034    /**
035     * Empty constructor, with no jmf info.
036     */
037    public JingleContentInfo() {
038        this(null);
039    }
040
041    /**
042     * Constructor with a jmf info.
043     *
044     * @param mediaInfoElement MediaInfo element
045     */
046    public JingleContentInfo(final ContentInfo mediaInfoElement) {
047        super();
048        this.mediaInfoElement = mediaInfoElement;
049    }
050
051    /**
052     * Get the jmf info element.
053     *
054     * @return the mediaInfoElement
055     */
056    public ContentInfo getMediaInfo() {
057        return mediaInfoElement;
058    }
059
060    /**
061     * Get the element name.
062     */
063    @Override
064    public String getElementName() {
065        // Media info is supposed to be just a single-word command...
066        return getMediaInfo().toString();
067    }
068
069    /**
070     * Set the name space.
071     *
072     * @param ns the namespace
073     */
074    protected void setNamespace(final String ns) {
075        namespace = ns;
076    }
077
078    /**
079     * Get the public namespace.
080     */
081    @Override
082    public String getNamespace() {
083        return namespace;
084    }
085
086    @Override
087    public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
088        StringBuilder buf = new StringBuilder();
089        buf.append('<').append(getElementName()).append(" xmlns=\"");
090        buf.append(getNamespace()).append("\" ");
091        buf.append("/>");
092        return buf.toString();
093    }
094
095    /**
096     * Transport part of a Jingle packet.
097     */
098    public static class Audio extends JingleContentInfo {
099
100        public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp";
101
102        public Audio(final ContentInfo mi) {
103            super(mi);
104            setNamespace(NAMESPACE);
105        }
106
107        @Override
108        public String getNamespace() {
109            return NAMESPACE;
110        }
111
112        // Subclasses: specialize the Audio jmf info...
113
114        /**
115         * Busy jmf info.
116         */
117        public static class Busy extends Audio {
118            public Busy() {
119                super(ContentInfo.Audio.BUSY);
120            }
121        }
122
123        /**
124         * Hold jmf info.
125         */
126        public static class Hold extends Audio {
127            public Hold() {
128                super(ContentInfo.Audio.HOLD);
129            }
130        }
131
132        /**
133         * Mute jmf info.
134         */
135        public static class Mute extends Audio {
136            public Mute() {
137                super(ContentInfo.Audio.MUTE);
138            }
139        }
140
141        /**
142         * Queued jmf info.
143         */
144        public static class Queued extends Audio {
145            public Queued() {
146                super(ContentInfo.Audio.QUEUED);
147            }
148        }
149
150        /**
151         * Ringing jmf info.
152         */
153        public static class Ringing extends Audio {
154            public Ringing() {
155                super(ContentInfo.Audio.RINGING);
156            }
157        }
158    }
159}