AgentInfo.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.packet;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.packet.IQ;
  20. import org.jivesoftware.smack.provider.IQProvider;
  21. import org.xmlpull.v1.XmlPullParser;
  22. import org.xmlpull.v1.XmlPullParserException;

  23. /**
  24.  * IQ packet for retrieving and changing the Agent personal information.
  25.  */
  26. public class AgentInfo extends IQ {

  27.     /**
  28.     * Element name of the packet extension.
  29.     */
  30.    public static final String ELEMENT_NAME = "agent-info";

  31.    /**
  32.     * Namespace of the packet extension.
  33.     */
  34.    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  35.     private String jid;
  36.     private String name;

  37.     public AgentInfo() {
  38.         super(ELEMENT_NAME, NAMESPACE);
  39.     }

  40.     /**
  41.      * Returns the Agent's jid.
  42.      *
  43.      * @return the Agent's jid.
  44.      */
  45.     public String getJid() {
  46.         return jid;
  47.     }

  48.     /**
  49.      * Sets the Agent's jid.
  50.      *
  51.      * @param jid the jid of the agent.
  52.      */
  53.     public void setJid(String jid) {
  54.         this.jid = jid;
  55.     }

  56.     /**
  57.      * Returns the Agent's name. The name of the agent may be different than the user's name.
  58.      * This property may be shown in the webchat client.
  59.      *
  60.      * @return the Agent's name.
  61.      */
  62.     public String getName() {
  63.         return name;
  64.     }

  65.     /**
  66.      * Sets the Agent's name. The name of the agent may be different than the user's name.
  67.      * This property may be shown in the webchat client.
  68.      *
  69.      * @param name the new name of the agent.
  70.      */
  71.     public void setName(String name) {
  72.         this.name = name;
  73.     }

  74.     @Override
  75.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  76.         buf.rightAngleBracket();

  77.         if (jid != null) {
  78.             buf.append("<jid>").append(getJid()).append("</jid>");
  79.         }
  80.         if (name != null) {
  81.             buf.append("<name>").append(getName()).append("</name>");
  82.         }

  83.         return buf;
  84.     }

  85.     /**
  86.      * An IQProvider for AgentInfo packets.
  87.      *
  88.      * @author Gaston Dombiak
  89.      */
  90.     public static class Provider extends IQProvider<AgentInfo> {

  91.         @Override
  92.         public AgentInfo parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  93.             AgentInfo answer = new AgentInfo();

  94.             boolean done = false;
  95.             while (!done) {
  96.                 int eventType = parser.next();
  97.                 if (eventType == XmlPullParser.START_TAG) {
  98.                     if (parser.getName().equals("jid")) {
  99.                         answer.setJid(parser.nextText());
  100.                     }
  101.                     else if (parser.getName().equals("name")) {
  102.                         answer.setName(parser.nextText());
  103.                     }
  104.                 }
  105.                 else if (eventType == XmlPullParser.END_TAG) {
  106.                     if (parser.getName().equals(ELEMENT_NAME)) {
  107.                         done = true;
  108.                     }
  109.                 }
  110.             }

  111.             return answer;
  112.         }
  113.     }
  114. }