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