MonitorPacket.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.packet;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.packet.IQ;
  20. import org.jivesoftware.smack.provider.IQProvider;
  21. import org.xmlpull.v1.XmlPullParser;
  22. import org.xmlpull.v1.XmlPullParserException;

  23. public class MonitorPacket extends IQ {

  24.     private String sessionID;

  25.     private boolean isMonitor;

  26.     public boolean isMonitor() {
  27.         return isMonitor;
  28.     }

  29.     public void setMonitor(boolean monitor) {
  30.         isMonitor = monitor;
  31.     }

  32.     public String getSessionID() {
  33.         return sessionID;
  34.     }

  35.     public void setSessionID(String sessionID) {
  36.         this.sessionID = sessionID;
  37.     }

  38.     /**
  39.      * Element name of the packet extension.
  40.      */
  41.     public static final String ELEMENT_NAME = "monitor";

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

  46.     public MonitorPacket() {
  47.         super(ELEMENT_NAME, NAMESPACE);
  48.     }

  49.     @Override
  50.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  51.         buf.rightAngleBracket();

  52.         if (sessionID != null) {
  53.             buf.append("<makeOwner sessionID=\""+sessionID+"\"></makeOwner>");
  54.         }

  55.         return buf;
  56.     }


  57.     /**
  58.      * Packet extension provider for Monitor Packets.
  59.      */
  60.     public static class InternalProvider extends IQProvider<MonitorPacket> {

  61.         @Override
  62.         public MonitorPacket parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  63.             MonitorPacket packet = new MonitorPacket();

  64.             boolean done = false;


  65.             while (!done) {
  66.                 int eventType = parser.next();
  67.                 if ((eventType == XmlPullParser.START_TAG) && ("isMonitor".equals(parser.getName()))) {
  68.                     String value = parser.nextText();
  69.                     if ("false".equalsIgnoreCase(value)) {
  70.                         packet.setMonitor(false);
  71.                     }
  72.                     else {
  73.                         packet.setMonitor(true);
  74.                     }
  75.                 }
  76.                 else if (eventType == XmlPullParser.END_TAG && "monitor".equals(parser.getName())) {
  77.                     done = true;
  78.                 }
  79.             }

  80.             return packet;
  81.         }
  82.     }
  83. }