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