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; 021import org.jivesoftware.smack.provider.IQProvider; 022import org.xmlpull.v1.XmlPullParser; 023 024/** 025 * IQ packet for retrieving and changing the Agent personal information. 026 */ 027public class AgentInfo extends IQ { 028 029 /** 030 * Element name of the packet extension. 031 */ 032 public static final String ELEMENT_NAME = "agent-info"; 033 034 /** 035 * Namespace of the packet extension. 036 */ 037 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 038 039 private String jid; 040 private String name; 041 042 /** 043 * Returns the Agent's jid. 044 * 045 * @return the Agent's jid. 046 */ 047 public String getJid() { 048 return jid; 049 } 050 051 /** 052 * Sets the Agent's jid. 053 * 054 * @param jid the jid of the agent. 055 */ 056 public void setJid(String jid) { 057 this.jid = jid; 058 } 059 060 /** 061 * Returns the Agent's name. The name of the agent may be different than the user's name. 062 * This property may be shown in the webchat client. 063 * 064 * @return the Agent's name. 065 */ 066 public String getName() { 067 return name; 068 } 069 070 /** 071 * Sets the Agent's name. The name of the agent may be different than the user's name. 072 * This property may be shown in the webchat client. 073 * 074 * @param name the new name of the agent. 075 */ 076 public void setName(String name) { 077 this.name = name; 078 } 079 080 public String getChildElementXML() { 081 StringBuilder buf = new StringBuilder(); 082 083 buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">"); 084 if (jid != null) { 085 buf.append("<jid>").append(getJid()).append("</jid>"); 086 } 087 if (name != null) { 088 buf.append("<name>").append(getName()).append("</name>"); 089 } 090 buf.append("</").append(ELEMENT_NAME).append("> "); 091 092 return buf.toString(); 093 } 094 095 /** 096 * An IQProvider for AgentInfo packets. 097 * 098 * @author Gaston Dombiak 099 */ 100 public static class Provider implements IQProvider { 101 102 public Provider() { 103 super(); 104 } 105 106 public IQ parseIQ(XmlPullParser parser) throws Exception { 107 AgentInfo answer = new AgentInfo(); 108 109 boolean done = false; 110 while (!done) { 111 int eventType = parser.next(); 112 if (eventType == XmlPullParser.START_TAG) { 113 if (parser.getName().equals("jid")) { 114 answer.setJid(parser.nextText()); 115 } 116 else if (parser.getName().equals("name")) { 117 answer.setName(parser.nextText()); 118 } 119 } 120 else if (eventType == XmlPullParser.END_TAG) { 121 if (parser.getName().equals(ELEMENT_NAME)) { 122 done = true; 123 } 124 } 125 } 126 127 return answer; 128 } 129 } 130}