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