001/** 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.workgroup.packet; 019 020import org.jivesoftware.smack.packet.IQ; 021 022/** 023 * A IQ packet used to depart a workgroup queue. There are two cases for issuing a depart 024 * queue request:<ul> 025 * <li>The user wants to leave the queue. In this case, an instance of this class 026 * should be created without passing in a user address. 027 * <li>An administrator or the server removes wants to remove a user from the queue. 028 * In that case, the address of the user to remove from the queue should be 029 * used to create an instance of this class.</ul> 030 * 031 * @author loki der quaeler 032 */ 033public class DepartQueuePacket extends IQ { 034 035 private String user; 036 037 /** 038 * Creates a depart queue request packet to the specified workgroup. 039 * 040 * @param workgroup the workgroup to depart. 041 */ 042 public DepartQueuePacket(String workgroup) { 043 this(workgroup, null); 044 } 045 046 /** 047 * Creates a depart queue request to the specified workgroup and for the 048 * specified user. 049 * 050 * @param workgroup the workgroup to depart. 051 * @param user the user to make depart from the queue. 052 */ 053 public DepartQueuePacket(String workgroup, String user) { 054 this.user = user; 055 056 setTo(workgroup); 057 setType(IQ.Type.SET); 058 setFrom(user); 059 } 060 061 public String getChildElementXML() { 062 StringBuilder buf = new StringBuilder("<depart-queue xmlns=\"http://jabber.org/protocol/workgroup\""); 063 064 if (this.user != null) { 065 buf.append("><jid>").append(this.user).append("</jid></depart-queue>"); 066 } 067 else { 068 buf.append("/>"); 069 } 070 071 return buf.toString(); 072 } 073}