SoundSettings.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.settings;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.packet.IqData;
  20. import org.jivesoftware.smack.packet.SimpleIQ;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.provider.IqProvider;
  23. import org.jivesoftware.smack.util.stringencoder.Base64;
  24. import org.jivesoftware.smack.xml.XmlPullParser;
  25. import org.jivesoftware.smack.xml.XmlPullParserException;

  26. public class SoundSettings extends SimpleIQ {
  27.     private String outgoingSound;
  28.     private String incomingSound;


  29.     public void setOutgoingSound(String outgoingSound) {
  30.         this.outgoingSound = outgoingSound;
  31.     }

  32.     public void setIncomingSound(String incomingSound) {
  33.         this.incomingSound = incomingSound;
  34.     }

  35.     public byte[] getIncomingSoundBytes() {
  36.         return Base64.decode(incomingSound);
  37.     }

  38.     public byte[] getOutgoingSoundBytes() {
  39.         return Base64.decode(outgoingSound);
  40.     }


  41.     /**
  42.      * Element name of the stanza extension.
  43.      */
  44.     public static final String ELEMENT_NAME = "sound-settings";

  45.     /**
  46.      * Namespace of the stanza extension.
  47.      */
  48.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  49.     public SoundSettings() {
  50.         super(ELEMENT_NAME, NAMESPACE);
  51.     }

  52.     /**
  53.      * Stanza extension provider for SoundSetting Packets.
  54.      */
  55.     public static class InternalProvider extends IqProvider<SoundSettings> {

  56.         @Override
  57.         public SoundSettings parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
  58.             SoundSettings soundSettings = new SoundSettings();

  59.             boolean done = false;


  60.             while (!done) {
  61.                 XmlPullParser.Event eventType = parser.next();
  62.                 if (eventType == XmlPullParser.Event.START_ELEMENT && "outgoingSound".equals(parser.getName())) {
  63.                     soundSettings.setOutgoingSound(parser.nextText());
  64.                 }
  65.                 else if ((eventType == XmlPullParser.Event.START_ELEMENT) && "incomingSound".equals(parser.getName())) {
  66.                     soundSettings.setIncomingSound(parser.nextText());
  67.                 }
  68.                 else if (eventType == XmlPullParser.Event.END_ELEMENT && "sound-settings".equals(parser.getName())) {
  69.                     done = true;
  70.                 }
  71.             }

  72.             return soundSettings;
  73.         }
  74.     }
  75. }