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        @SuppressWarnings("this-escape")
103        public Audio(final ContentInfo mi) {
104            super(mi);
105            setNamespace(NAMESPACE);
106        }
107
108        @Override
109        public String getNamespace() {
110            return NAMESPACE;
111        }
112
113        // Subclasses: specialize the Audio jmf info...
114
115        /**
116         * Busy jmf info.
117         */
118        public static class Busy extends Audio {
119            public Busy() {
120                super(ContentInfo.Audio.BUSY);
121            }
122        }
123
124        /**
125         * Hold jmf info.
126         */
127        public static class Hold extends Audio {
128            public Hold() {
129                super(ContentInfo.Audio.HOLD);
130            }
131        }
132
133        /**
134         * Mute jmf info.
135         */
136        public static class Mute extends Audio {
137            public Mute() {
138                super(ContentInfo.Audio.MUTE);
139            }
140        }
141
142        /**
143         * Queued jmf info.
144         */
145        public static class Queued extends Audio {
146            public Queued() {
147                super(ContentInfo.Audio.QUEUED);
148            }
149        }
150
151        /**
152         * Ringing jmf info.
153         */
154        public static class Ringing extends Audio {
155            public Ringing() {
156                super(ContentInfo.Audio.RINGING);
157            }
158        }
159    }
160}