blob: 66bec35b4dbc47b908615a5affdaa7a66fe80680 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
2 * $Revision$
3 * $Date$
4 *
5 * Copyright 2003-2007 Jive Software.
6 *
7 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.jivesoftware.smackx.workgroup.settings;
21
22import org.jivesoftware.smack.packet.IQ;
23import org.jivesoftware.smack.provider.IQProvider;
24import org.jivesoftware.smack.util.StringUtils;
25import org.xmlpull.v1.XmlPullParser;
26
27public class SoundSettings extends IQ {
28 private String outgoingSound;
29 private String incomingSound;
30
31
32 public void setOutgoingSound(String outgoingSound) {
33 this.outgoingSound = outgoingSound;
34 }
35
36 public void setIncomingSound(String incomingSound) {
37 this.incomingSound = incomingSound;
38 }
39
40 public byte[] getIncomingSoundBytes() {
41 return StringUtils.decodeBase64(incomingSound);
42 }
43
44 public byte[] getOutgoingSoundBytes() {
45 return StringUtils.decodeBase64(outgoingSound);
46 }
47
48
49 /**
50 * Element name of the packet extension.
51 */
52 public static final String ELEMENT_NAME = "sound-settings";
53
54 /**
55 * Namespace of the packet extension.
56 */
57 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
58
59 public String getChildElementXML() {
60 StringBuilder buf = new StringBuilder();
61
62 buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
63 buf.append('"');
64 buf.append(NAMESPACE);
65 buf.append('"');
66 buf.append("></").append(ELEMENT_NAME).append("> ");
67 return buf.toString();
68 }
69
70
71 /**
72 * Packet extension provider for SoundSetting Packets.
73 */
74 public static class InternalProvider implements IQProvider {
75
76 public IQ parseIQ(XmlPullParser parser) throws Exception {
77 if (parser.getEventType() != XmlPullParser.START_TAG) {
78 throw new IllegalStateException("Parser not in proper position, or bad XML.");
79 }
80
81 SoundSettings soundSettings = new SoundSettings();
82
83 boolean done = false;
84
85
86 while (!done) {
87 int eventType = parser.next();
88 if ((eventType == XmlPullParser.START_TAG) && ("outgoingSound".equals(parser.getName()))) {
89 soundSettings.setOutgoingSound(parser.nextText());
90 }
91 else if ((eventType == XmlPullParser.START_TAG) && ("incomingSound".equals(parser.getName()))) {
92 soundSettings.setIncomingSound(parser.nextText());
93 }
94 else if (eventType == XmlPullParser.END_TAG && "sound-settings".equals(parser.getName())) {
95 done = true;
96 }
97 }
98
99 return soundSettings;
100 }
101 }
102}
103