blob: 8b9d23073efbd2a6786b294a9a29834618910303 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
2 * $Revision$
3 * $Date$
4 *
5 * Copyright 2003-2007 Jive Software.
6 *
7 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.jivesoftware.smackx.workgroup.packet;
21
22import org.jivesoftware.smack.packet.IQ;
23import org.jivesoftware.smack.provider.IQProvider;
24import org.xmlpull.v1.XmlPullParser;
25
26/**
27 * IQ packet for retrieving and changing the Agent personal information.
28 */
29public class AgentInfo extends IQ {
30
31 /**
32 * Element name of the packet extension.
33 */
34 public static final String ELEMENT_NAME = "agent-info";
35
36 /**
37 * Namespace of the packet extension.
38 */
39 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
40
41 private String jid;
42 private String name;
43
44 /**
45 * Returns the Agent's jid.
46 *
47 * @return the Agent's jid.
48 */
49 public String getJid() {
50 return jid;
51 }
52
53 /**
54 * Sets the Agent's jid.
55 *
56 * @param jid the jid of the agent.
57 */
58 public void setJid(String jid) {
59 this.jid = jid;
60 }
61
62 /**
63 * Returns the Agent's name. The name of the agent may be different than the user's name.
64 * This property may be shown in the webchat client.
65 *
66 * @return the Agent's name.
67 */
68 public String getName() {
69 return name;
70 }
71
72 /**
73 * Sets the Agent's name. The name of the agent may be different than the user's name.
74 * This property may be shown in the webchat client.
75 *
76 * @param name the new name of the agent.
77 */
78 public void setName(String name) {
79 this.name = name;
80 }
81
82 public String getChildElementXML() {
83 StringBuilder buf = new StringBuilder();
84
85 buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
86 if (jid != null) {
87 buf.append("<jid>").append(getJid()).append("</jid>");
88 }
89 if (name != null) {
90 buf.append("<name>").append(getName()).append("</name>");
91 }
92 buf.append("</").append(ELEMENT_NAME).append("> ");
93
94 return buf.toString();
95 }
96
97 /**
98 * An IQProvider for AgentInfo packets.
99 *
100 * @author Gaston Dombiak
101 */
102 public static class Provider implements IQProvider {
103
104 public Provider() {
105 super();
106 }
107
108 public IQ parseIQ(XmlPullParser parser) throws Exception {
109 AgentInfo answer = new AgentInfo();
110
111 boolean done = false;
112 while (!done) {
113 int eventType = parser.next();
114 if (eventType == XmlPullParser.START_TAG) {
115 if (parser.getName().equals("jid")) {
116 answer.setJid(parser.nextText());
117 }
118 else if (parser.getName().equals("name")) {
119 answer.setName(parser.nextText());
120 }
121 }
122 else if (eventType == XmlPullParser.END_TAG) {
123 if (parser.getName().equals(ELEMENT_NAME)) {
124 done = true;
125 }
126 }
127 }
128
129 return answer;
130 }
131 }
132}