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