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