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