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