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;
020import org.jivesoftware.smackx.jingleold.media.ContentInfo;
021
022/**
023 * Jingle content info.
024 *
025 * @author Alvaro Saurin <alvaro.saurin@gmail.com>
026 */
027public class JingleContentInfo implements ExtensionElement {
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    @Override
063    public String getElementName() {
064        // Media info is supposed to be just a single-word command...
065        return getMediaInfo().toString();
066    }
067
068    /**
069     * Set the name space.
070     *
071     * @param ns the namespace
072     */
073    protected void setNamespace(final String ns) {
074        namespace = ns;
075    }
076
077    /**
078     * Get the publilc namespace.
079     */
080    @Override
081    public String getNamespace() {
082        return namespace;
083    }
084
085    @Override
086    public String toXML() {
087        StringBuilder buf = new StringBuilder();
088        buf.append('<').append(getElementName()).append(" xmlns=\"");
089        buf.append(getNamespace()).append("\" ");
090        buf.append("/>");
091        return buf.toString();
092    }
093
094    /**
095     * Transport part of a Jingle packet.
096     */
097    public static class Audio extends JingleContentInfo {
098
099        public static final String NAMESPACE = "urn:xmpp:tmp:jingle:apps:rtp";
100
101        public Audio(final ContentInfo mi) {
102            super(mi);
103            setNamespace(NAMESPACE);
104        }
105
106        @Override
107        public String getNamespace() {
108            return NAMESPACE;
109        }
110
111        // Subclasses: specialize the Audio jmf info...
112
113        /**
114         * Busy jmf info.
115         */
116        public static class Busy extends Audio {
117            public Busy() {
118                super(ContentInfo.Audio.BUSY);
119            }
120        }
121
122        /**
123         * Hold jmf info.
124         */
125        public static class Hold extends Audio {
126            public Hold() {
127                super(ContentInfo.Audio.HOLD);
128            }
129        }
130
131        /**
132         * Mute jmf info.
133         */
134        public static class Mute extends Audio {
135            public Mute() {
136                super(ContentInfo.Audio.MUTE);
137            }
138        }
139
140        /**
141         * Queued jmf info.
142         */
143        public static class Queued extends Audio {
144            public Queued() {
145                super(ContentInfo.Audio.QUEUED);
146            }
147        }
148
149        /**
150         * Ringing jmf info.
151         */
152        public static class Ringing extends Audio {
153            public Ringing() {
154                super(ContentInfo.Audio.RINGING);
155            }
156        }
157    }
158}