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 org.jivesoftware.smack.packet.IQ; 021import org.jivesoftware.smack.provider.IQProvider; 022import org.jivesoftware.smack.util.StringUtils; 023import org.xmlpull.v1.XmlPullParser; 024 025public class SoundSettings extends IQ { 026 private String outgoingSound; 027 private String incomingSound; 028 029 030 public void setOutgoingSound(String outgoingSound) { 031 this.outgoingSound = outgoingSound; 032 } 033 034 public void setIncomingSound(String incomingSound) { 035 this.incomingSound = incomingSound; 036 } 037 038 public byte[] getIncomingSoundBytes() { 039 return StringUtils.decodeBase64(incomingSound); 040 } 041 042 public byte[] getOutgoingSoundBytes() { 043 return StringUtils.decodeBase64(outgoingSound); 044 } 045 046 047 /** 048 * Element name of the packet extension. 049 */ 050 public static final String ELEMENT_NAME = "sound-settings"; 051 052 /** 053 * Namespace of the packet extension. 054 */ 055 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 056 057 public String getChildElementXML() { 058 StringBuilder buf = new StringBuilder(); 059 060 buf.append("<").append(ELEMENT_NAME).append(" xmlns="); 061 buf.append('"'); 062 buf.append(NAMESPACE); 063 buf.append('"'); 064 buf.append("></").append(ELEMENT_NAME).append("> "); 065 return buf.toString(); 066 } 067 068 069 /** 070 * Packet extension provider for SoundSetting Packets. 071 */ 072 public static class InternalProvider implements IQProvider { 073 074 public IQ parseIQ(XmlPullParser parser) throws Exception { 075 if (parser.getEventType() != XmlPullParser.START_TAG) { 076 throw new IllegalStateException("Parser not in proper position, or bad XML."); 077 } 078 079 SoundSettings soundSettings = new SoundSettings(); 080 081 boolean done = false; 082 083 084 while (!done) { 085 int eventType = parser.next(); 086 if ((eventType == XmlPullParser.START_TAG) && ("outgoingSound".equals(parser.getName()))) { 087 soundSettings.setOutgoingSound(parser.nextText()); 088 } 089 else if ((eventType == XmlPullParser.START_TAG) && ("incomingSound".equals(parser.getName()))) { 090 soundSettings.setIncomingSound(parser.nextText()); 091 } 092 else if (eventType == XmlPullParser.END_TAG && "sound-settings".equals(parser.getName())) { 093 done = true; 094 } 095 } 096 097 return soundSettings; 098 } 099 } 100} 101