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.SimpleIQ;
  20. import org.jivesoftware.smack.provider.IQProvider;
  21. import org.jivesoftware.smack.util.stringencoder.Base64;
  22. import org.xmlpull.v1.XmlPullParser;
  23. import org.xmlpull.v1.XmlPullParserException;

  24. public class SoundSettings extends SimpleIQ {
  25.     private String outgoingSound;
  26.     private String incomingSound;


  27.     public void setOutgoingSound(String outgoingSound) {
  28.         this.outgoingSound = outgoingSound;
  29.     }

  30.     public void setIncomingSound(String incomingSound) {
  31.         this.incomingSound = incomingSound;
  32.     }

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

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


  39.     /**
  40.      * Element name of the packet extension.
  41.      */
  42.     public static final String ELEMENT_NAME = "sound-settings";

  43.     /**
  44.      * Namespace of the packet extension.
  45.      */
  46.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  47.     public SoundSettings() {
  48.         super(ELEMENT_NAME, NAMESPACE);
  49.     }

  50.     /**
  51.      * Packet extension provider for SoundSetting Packets.
  52.      */
  53.     public static class InternalProvider extends IQProvider<SoundSettings> {

  54.         @Override
  55.         public SoundSettings parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  56.             SoundSettings soundSettings = new SoundSettings();

  57.             boolean done = false;


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

  70.             return soundSettings;
  71.         }
  72.     }
  73. }