001/**
002 *
003 * Copyright 2003-2007 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 */
017
018package org.jivesoftware.smackx.workgroup.settings;
019
020import java.io.IOException;
021
022import org.jivesoftware.smack.packet.SimpleIQ;
023import org.jivesoftware.smack.packet.XmlEnvironment;
024import org.jivesoftware.smack.provider.IQProvider;
025import org.jivesoftware.smack.util.stringencoder.Base64;
026import org.jivesoftware.smack.xml.XmlPullParser;
027import org.jivesoftware.smack.xml.XmlPullParserException;
028
029public class SoundSettings extends SimpleIQ {
030    private String outgoingSound;
031    private String incomingSound;
032
033
034    public void setOutgoingSound(String outgoingSound) {
035        this.outgoingSound = outgoingSound;
036    }
037
038    public void setIncomingSound(String incomingSound) {
039        this.incomingSound = incomingSound;
040    }
041
042    public byte[] getIncomingSoundBytes() {
043        return Base64.decode(incomingSound);
044    }
045
046    public byte[] getOutgoingSoundBytes() {
047        return Base64.decode(outgoingSound);
048    }
049
050
051    /**
052     * Element name of the stanza extension.
053     */
054    public static final String ELEMENT_NAME = "sound-settings";
055
056    /**
057     * Namespace of the stanza extension.
058     */
059    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
060
061    public SoundSettings() {
062        super(ELEMENT_NAME, NAMESPACE);
063    }
064
065    /**
066     * Stanza extension provider for SoundSetting Packets.
067     */
068    public static class InternalProvider extends IQProvider<SoundSettings> {
069
070        @Override
071        public SoundSettings parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
072            SoundSettings soundSettings = new SoundSettings();
073
074            boolean done = false;
075
076
077            while (!done) {
078                XmlPullParser.Event eventType = parser.next();
079                if (eventType == XmlPullParser.Event.START_ELEMENT && "outgoingSound".equals(parser.getName())) {
080                    soundSettings.setOutgoingSound(parser.nextText());
081                }
082                else if ((eventType == XmlPullParser.Event.START_ELEMENT) && "incomingSound".equals(parser.getName())) {
083                    soundSettings.setIncomingSound(parser.nextText());
084                }
085                else if (eventType == XmlPullParser.Event.END_ELEMENT && "sound-settings".equals(parser.getName())) {
086                    done = true;
087                }
088            }
089
090            return soundSettings;
091        }
092    }
093}
094